HighTechTalks DotNet Forums  

XmlNamespaceManager, default namespaces, nested qualified namespace, xpath problem.

Dotnet XML microsoft.public.dotnet.xml


Discuss XmlNamespaceManager, default namespaces, nested qualified namespace, xpath problem. in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Oisin Grehan
 
Posts: n/a

Default XmlNamespaceManager, default namespaces, nested qualified namespace, xpath problem. - 06-30-2003 , 06:35 AM






Hi,


I can't for the life of me get this to work properly. I've searched for
examples, but none of the examples quite match my environment. Here is my
XML (please treat this as immutable -- no solutions involving altering the
XML are good for me):

---- config.xml ----

<Configuration
xmlns="urn:server:schemas:configuration"
xmlns:f="urn:server:schemas:faq">
<version version="0.0.0001">
<f:faq>
<f:section>Default</f:section>
<f:item>
<f:q>What is the meaning of life?</f:q>
<f:a>42.</f:a>
</f:item>
</f:faq>
</version>
</Configuration>

I want to have an XmlNode object referencing the first <faq> tag. Here is
the corresponding c# code:

XmlDocument xd = new XmlDocument();
xd.Load("config.xml");
XmlNamespaceManager xnm = new XmlNamespaceManager(xd.NameTable);
xnm.AddNamespace(String.Empty, "urn:server:schemas:configuration");
xnm.AddNamespace("f", "urn:server:schemas:faq"); // faq container namespace
XmlNode xnFaq = xd.SelectSingleNode(

"/Configuration/version[@version=\"0.0.0001\"]/f:faq[f:section=\"Default\"]"
, xnm);

This fails to select the f:faq node. I've tried using the following also:

xnm.AddNamespace("c", "urn:server:schemas:configuration");
xnm.AddNamespace("f", "urn:server:schemas:faq"); // faq container namespace
XmlNode xnFaq = xd.SelectSingleNode(

"/c:Configuration/c:version[@c:version=\"0.0.0001\"]/f:faq[f:section=\"Defau
lt\"]", xnm);

I'm beginning to lose the mind here people; any ideas? Cheers!

- Oisin






Reply With Quote
  #2  
Old   
Oisin Grehan
 
Posts: n/a

Default Re: XmlNamespaceManager, default namespaces, nested qualified namespace, xpath problem. - 06-30-2003 , 07:01 AM







"Steven Livingstone" <s.livingstone (AT) nospam (DOT) btinternet.com> wrote

Quote:
Have you tried this?

XmlNode xnFaq = xd.SelectSingleNode(

"/Configuration/version[@version='0.0.0001']/f:faq[f:section='Default']"
, xnm);

?
Nope, that's not it. If I strip the default namespace declaration out of the
xml, e.g. the root tag is just <Configuration>, everything works fine. But
like I mentioned, this is not an option for me. Thanks for the try anyway.

- Oisin







Reply With Quote
  #3  
Old   
Oisin Grehan
 
Posts: n/a

Default Re: XmlNamespaceManager, default namespaces, nested qualified namespace, xpath problem. - 06-30-2003 , 07:44 AM



Right -- for the benefit of the rest of the group, the problem was in the
XPath query;

if should have been:

/c:Configuration/c:version[@version=\"0.0.0001\"] ...

instead of

/c:Configuration/c:version[@c:version=\"0.0.0001\"] ...

I was qualifying the attribute with a namespace prefix and I didn't need to.
Guess I'd better read up a little more on schema defaults

- Oisin



"Oisin Grehan" <oising (AT) nospam (DOT) iol.ie.> wrote

Quote:
Hi,
<snip />




Reply With Quote
  #4  
Old   
Steven Livingstone
 
Posts: n/a

Default Re: XmlNamespaceManager, default namespaces, nested qualified namespace, xpath problem. - 06-30-2003 , 07:51 AM



ok, with the c prefix try.. (sorry not to take more time but i'm rushed of
my feet for the next couple of hours!)

"/c:Configuration/c:version[@version='0.0.0001']/f:faq[f:section='Default']"
, xnm);


"Oisin Grehan" <oising (AT) nospam (DOT) iol.ie.> wrote

Quote:
"Steven Livingstone" <s.livingstone (AT) nospam (DOT) btinternet.com> wrote in
message
news:%23MNdAXvPDHA.1748 (AT) TK2MSFTNGP11 (DOT) phx.gbl...
Have you tried this?

XmlNode xnFaq = xd.SelectSingleNode(

"/Configuration/version[@version='0.0.0001']/f:faq[f:section='Default']"
, xnm);

?

Nope, that's not it. If I strip the default namespace declaration out of
the
xml, e.g. the root tag is just <Configuration>, everything works fine. But
like I mentioned, this is not an option for me. Thanks for the try anyway.

- Oisin








Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.