473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

xmltext reader and namespace

MAF
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?


Feb 1 '07 #1
2 2308
* 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/
Feb 2 '07 #2
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/
Feb 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michel | last post by:
Hi there, I have an enum field that I serialize: public ParameterDirection Direction = ParameterDirection.Out; The enum looks like this: public enum ParameterDirection { In, Out, Both };
2
by: Anirudh | last post by:
Hi, i wanted to know if there is any way to convert an object to XMlText to XMLElement. Thanks in advance.
0
by: Andrew Burgher | last post by:
Feeding the following .xsd into the XsdObjectGen (v1.4.2.0) tool produces an invalid attribute: with DataType="System.String". Has anybody seen this behaviour before? Is this a bug in...
5
by: Drew Yallop | last post by:
I read an XML file with a stream reader in VB.Net. When I look at the stream reader output in debug mode (by passing cursor over the stream reader object)the format is a perfect replica of the...
17
by: Filip Strugar | last post by:
Considering that the BinaryWriter/BinaryReader object closes the underlaying stream upon being gc collected, is the following code correct, and if it is what is the reason preventing BinaryWriter...
1
by: thejeffross | last post by:
I have a memory problem that keeps causing server resets, so I'm using WinDbg to figure out what the problem is. When I look at the heap, WinDbg tells me that there are over one million XmlText...
2
by: junk | last post by:
This seems something that should be easy and not uncommon... but hours of searching have yielded nothing! I am using XmlSerializer to map some XML (not defined by me) into some class objects...
1
by: Chukkalove | last post by:
I originally created several "copy" resource reader classes which worked great individually, but after I converted them into an parent class with children they no longer find the resources. Each...
3
by: buterfly0707 | last post by:
The type or namespace name 'Text Reader' could not be found (are you missing a using directive or an assembly reference?)" what dose this error mean??"
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.