The XPath expression in SelectSingleNode does not pick up the default
namespace of the xml document.
The following code sample shows how to make use of the namespace manager
that can be passed into SelectSingleNode:
XmlDocument doc = new XmlDocument();
doc.Load("select.xml");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("tns", "
http://www.disclosureusa.org/filingreceipt.xsd");
XmlElement root = doc.DocumentElement;
XmlNode receiptdate = root.SelectSingleNode(".//tns:receiptdate", nsmgr);
//You need to qualify the XPath with the namespace of the node that you are
trying to select.
Console.WriteLine(receiptdate.InnerText);
Also, to get no validation using XmlValidatingReader, you can set the
ValidationType property on the reader to ValdiationType.None
Thanks,
Priya
[quoted text, click to view] "Erik Moore" <erikmoore@austin.rr.nospam.com> wrote in message
news:%23AcS4o2PEHA.3732@TK2MSFTNGP11.phx.gbl...
> I am both producing and parsing an xml document that needs to be validated
against a schema. I wanted some consumers of the document
> to have the option of not performing a validation, so I left the nodes in
the instance unqualified. An example of the document is
> below:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <filingreceipt xmlns="
http://www.disclosureusa.org/filingreceipt.xsd"> > <cpofilingnumber>TX2004043037501</cpofilingnumber>
> <receiptdate>2004-05-01T16:54:21</receiptdate>
> <zipfilebytes>95137</zipfilebytes>
> <recipientcode>mactx</recipientcode>
> </filingreceipt>
>
>
> When the xmlns attribute is included in the document, I am able to use the
XmlValidatingReader to validate the document. However,
> parsing the document fails because the parser is looking for the prefix in
the unqualified nodes, and I don't have a prefix to pass
> to SelectSingleNode. I don't want to qualify the nodes in the document to
keep the document simple, and make validating optional. If
> I remove the xmlns attribute, XmlValidatingReader refuses to validate the
document.
>
> I want to both validate and be able to parse this document, and don't know
how to get both the validator and the parser to
> cooperate.
>
>
>
>
>
>