RE: [nant-dev] nant.xsd sample
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'll send more info after I write up a brief description of the problem (really just an explanation of the specification) and what to do. In short, we will have to use a prefix name with our xml if you are using the xsd, or change all the xpath in code (probably the better way). If you want to read about the problem (before I post my explanation), here are few posts that get into the issue: http://groups.google.com/groups?hl=enthreadm=Ojp6QPIUAHA.279%40cppssbbs a03rnum=2prev=/groups%3Fq%3Dxmlns%2Bnamespace%2Bxpath%2Bcontext%26hl%3 Den%26selm%3DOjp6QPIUAHA.279%2540cppssbbsa03%26rnum%3D2 http://groups.google.com/groups?hl=enthreadm=wy4rj92fju.fsf%40polya.u-s trasbg.frrnum=1prev=/groups%3Fq%3Dxmlns%2Bnamespace%2Bxpath%2Bcontext% 26hl%3Den%26selm%3Dwy4rj92fju.fsf%2540polya.u-strasbg.fr%26rnum%3D1 Later, Scott -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Ian MacLean Sent: Wednesday, April 17, 2002 10:45 AM To: Scott Hernandez Cc: [EMAIL PROTECTED] Subject: Re: [nant-dev] nant.xsd sample Scott Hernandez wrote: Attached is sample of the output for tasks I am generating. I?ve been fighting with vs.net to get it working in the xml editor. It turns out the more normalized format I started with was giving no help in the vs.net xml editor. So I had to start over. This version is much larger, and deeper, with little to no references to complex types. In short, it probably about 80% repeated text. Great work Scott. I notice Project is expected as uppercase and arg tags aren't handled in the csc task. target should have a depends attribute not a default attr. This is really cool. the intellisense makes to so much quicker - no more looking up the nant task reference every time I code a build file. Ian ___ Nant-developers mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/nant-developers ___ Nant-developers mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/nant-developers
RE: [nant-dev] nant.xsd sample
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
Re: [nant-dev] nant.xsd sample
A lot of the code in NAnt that uses XPath could really be rewritten so that it doesn't without much trouble at all. For example, most of the SelectSingleNode calls are just getting attributes which could just as easily (and possibly even more efficiently) be gotten be casting an XmlNode to XmlElement and using the GetAttribute method. These calls aren't actually affected by this problem since the attributes aren't qualified but it might be worth it to remove those anyways. There are some other SelectSingleNode calls that get a named child element. These could use the indexer on XmlNode. The project element is always the document element so we could use XmlDocument.DocumentElement to get at that. But the question is really do we want to require that NAnt elements be namespace qualified? I can see arguments for both sides but am currently leaning towards no. It's unfortunate that VS.NET requires a targetNamespace in XSDs in order to use IntelliSense especially since XSDs are perfectly capable of describing documents that make no use of namespaces. I ran into this (and probably the other problems you mentioned) just yesterday for a different project. It's frustrating because VS.NET is _sooo_ close to being perfect but not close enough to where you can actually use it. Jason - Original Message - From: Scott Hernandez [EMAIL PROTECTED] To: 'Ian MacLean' [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, April 17, 2002 2:38 PM Subject: RE: [nant-dev] nant.xsd sample 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 ___ Nant-developers mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/nant-developers
RE: [nant-dev] nant.xsd sample
The context issue is actually defined in the XPath W3C Standard[1]; and is supposed to work that way. As for validation, we can do it without the namespace, but if want intellisense and leave the namespace in, all of the xpath queries will fail unless we code it. [1] http://groups.google.com/groups?hl=enselm=Ojp6QPIUAHA.279%40cppssbbsa03 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Jason Diamond Sent: Wednesday, April 17, 2002 2:40 PM To: [EMAIL PROTECTED] Subject: Re: [nant-dev] nant.xsd sample [snip] It's unfortunate that VS.NET requires a targetNamespace in XSDs in order to use IntelliSense especially since XSDs are perfectly capable of describing documents that make no use of namespaces. I ran into this (and probably the other problems you mentioned) just yesterday for a different project. It's frustrating because VS.NET is _sooo_ close to being perfect but not close enough to where you can actually use it. Jason ___ Nant-developers mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/nant-developers
RE: [nant-dev] nant.xsd sample
Yeah, I made those changes while I was testing on my local copy. I can check them in later if you want. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Gerry Shaw Sent: Wednesday, April 17, 2002 5:19 PM Cc: [EMAIL PROTECTED] Subject: RE: [nant-dev] nant.xsd sample It shouldn't add too much overhead. The majority of tasks have no need to use xpath as they are de-serialized by the default mechanism. In fact a quick grep through the code shows maybe two places where we need xpath, the rest of the places where SelectNodes and SelectSingleNode is called should be replaced with the likely faster and clearer Attributes[] and/or ChildElments[] properties. Having to add that prefix and then forgetting will sure make for a confusing bug... ___ Nant-developers mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/nant-developers ___ Nant-developers mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/nant-developers