I have a seemingly easy task that got extremely hairy.
As an input I have xml files that may or may not define a default namespace. the files look like below:
< xml version="1.0" encoding="UTF-8" >
<collection xmlns="http://www.loc.gov/MARC21/slim">
<record>
<controlfield tag="001">1020311</controlfield>
<datafield tag="980" ind1=" " ind2=" ">
<subfield code="a">PHOTOLAB</subfield>
</datafield>
<datafield tag="960" ind1=" " ind2=" ">
<subfield code="a">81</subfield>
</datafield>
...
</record>
</collection>
I looked at the information on xml namespaces given here:
http://sinan.ussakli.net/code/xml-namespaces-on-xpath-queries-and-xslt
and tried their hack:
resultPage.Load(@"C:\SoftwareProjects\eBulletinSubmission\MultimediaGallery\test.xml");
XPathNavigator navigator = resultPage.CreateNavigator();
XPathNavigator context = navigator.Clone();
context.MoveToFirstChild();
XPathNodeIterator iterator = navigator.Select("//record", context);
the only difference in my example is that I do not use a prefix, since I don't have one. The result is that it will never find anything. I tried to run the DocumentNsResolver class from the same link above and got the obvious result that my prefix is "". How can I query for this I tried a whole lot of things, without much success for this simple case. I guess the next thing I am doing is just cut out the namespace from the file, extremely ugly, but it seems to be the only thing that really works...
If you have any ideas on this, please let me know.
Thanks!