Yeah, that is the basic problem. The xpath queries use no context by
default; you could think of it like the empty namespace. So we have to
provide context for queries. Here is how it would have to work.
XmlNamespaceManager nm = new XmlNamespaceManager(new
NameTable());
nm.AddNamespace("nant","nantNameSpaceURI"); //namespace prefix
XmlNode node = doc.SelectSingleNode("nant:project", nm); //
w/prefix
Not such a big change, but one that will affect all xpath queries.
I think we can detect if a namespace is used on the project element and
use that for our queries. But it will require that in all our xpath
queries we use a pre-defined prefix (like "nant:").
And in the case where no namespace is specified, we can add one to the
document (once it has been loaded) so queries still work.
I expect the types of build files that will be supported will have to be
in one of the three following forms:
1.) No namespace
<project/>
2.) default namespace provided
<project xmlns="nantNameSpaceURI"/>
3.) explicit namespace
<project xmlns:X="nantNameSpaceURI"/>
(X can be pretty much anything you want, but should probably be "nant")
2 & 3 are pretty much the same.
1 is the only one I'm not sure of.
I will do a few more tests, but I think this will be the best solution.
BTW. Most people expect 1 & 2 to work the same. I know I did before I
thought about it, and read about it. :(
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of Ian
MacLean
Sent: Wednesday, April 17, 2002 11:09 AM
To: Scott Hernandez
Cc: [EMAIL PROTECTED]
Subject: Re: [nant-dev] nant.xsd sample
Scott Hernandez wrote:
>So I did this (sent the email), then realized that if actually use the
>existing file (meaning you add an xmlns=" to the project element) it
>will cause problems with xpath queries.
>
>Before you actually build (use the build file) you need to remove the
>default namespace def from the build file. If you leave it, all xpath
>queries will fail.
>
I think I see the problem. In the build file we map the dafault
namespace to the nant namespace but when we come to execute an xpath the
default namspace isn't the nant one so the xpath queries will return
nothing.
Does this mean we will need to specify the namespace in our xpath
queries - using a custom context ? Even if we use prefixes our xpath
queries will still need to be aware of the namespace mapping.
Ian
[snip]
_______________________________________________
Nant-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-developers