Yes, it is better to fix the content of the document. However, if that is
beyond your control, or if the XML is not supposed to be a full well-formed
XML document but rather just an XML fragment, you can use the fragment
constructor on the XmlTextReader. You can specify the custom namespace
manager on XmlParserContext and pass this to the XmlTextReader:
XmlParserContext pc = new XmlParserContext( null, new
XmlNamespaceManager( new NameTable() ), string.Empty, XmlSpace.Default );
XmlTextReader xtr = new XmlTextReader( myStream,
XmlNodeType.Element, pc );
-Helena
"Bjoern Hoehrmann" wrote:
* MAF wrote in microsoft.public.dotnet.xml:
I am gettin the following error: 'ns1' is an undeclared namespace. Line 13,
position 5.
The way I got around this with using a xmldocument like this.
System.Xml.XmlDocument XMLDoc = new XmlDocument();
nsManager = new XmlNamespaceManager(XMLDoc.NameTable);
nsManager.AddNamespace("ns1", http://ACME.com/MyDataSet.xsd);
How do I do something similar in the text reader?
Why would you do that? If the document you are trying to parse fails to
declare all the namespace prefixes it uses, it is not namespace-well-
formed and instead of working around that you should contact whoever
provides the content you are trying to process to have their content
fixed, no?
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/