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