Groups | Blog | Home
all groups > dotnet xml > february 2007 >

dotnet xml : xmltext reader and namespace


MAF
2/1/2007 2:18:47 PM
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?



Bjoern Hoehrmann
2/2/2007 1:03:20 AM
* MAF wrote in microsoft.public.dotnet.xml:
[quoted text, click to view]

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:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
Helena Kotas [MSFT]
2/5/2007 6:17:00 PM
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
[quoted text, click to view]
AddThis Social Bookmark Button