I've had better luck by giving the namespace an alias - when the namespace
is the default or only one listed.. something like this:
nsmgr.AddNamespace("default", "urn:sp-schema");
foreach (XmlNode appNode in
appListDoc.DocumentElement.SelectNodes("default:Application", nsmgr))
[quoted text, click to view] "Trace C" <tracey.roy@dewr.gov.au> wrote in message
news:9f0a7a28.0403292355.511fe942@posting.google.com...
> I have XML that has XML embedded in it, which has a namespace on the
> root element I am trying to get, so I end up with XML of:
>
> <ApplicationsList xmlns="urn:sp-schema">
> <Application>
> <Name></Name>
> <ApplicationAddress></ApplicationAddress>
> <FormAddress></FormAddress>
> <Description></Description>
> </Application>
> <Application>
> <Name></Name>
> <ApplicationAddress></ApplicationAddress>
> <FormAddress></FormAddress>
> <Description>EA3000</Description>
> <ImageIndex>0</ImageIndex>
> .....
>
> So I load this XML into a DOM, using LoadXml
>
> appListDoc.LoadXml(xmlNode.OuterXml);
>
> //Create the XmlNamespaceManager.
> XmlNamespaceManager nsmgr = new
> XmlNamespaceManager(appListDoc.NameTable);
> nsmgr.AddNamespace("", "urn:sp-schema");
>
> foreach (XmlNode appNode in
> appListDoc.DocumentElement.SelectNodes("Application", nsmgr))
> {
> // do stuff
> }
>
> In my foreach loop, it never finds the "Application" element. But if
> I iterate through the childNodes, all is fine - but I don't want to do
> this.
>
> ======= Immediate Window ================
> appListDoc.DocumentElement.ChildNodes
> {System.Xml.XmlChildNodes}
> [System.Xml.XmlChildNodes]: {System.Xml.XmlChildNodes}
> System.Object: {System.Xml.XmlChildNodes}
> Count: 16
> ItemOf: <cannot view indexed property>
> =========================================
>
> Please could someone help!
>
> Thanks,
> Trace