.NET and XML: How can I read nested namespaces (<abc:xyz:name attr="value"/>)?
Posted
by Entrase
on Stack Overflow
See other posts from Stack Overflow
or by Entrase
Published on 2010-05-29T15:29:24Z
Indexed on
2010/05/29
15:32 UTC
Read the original article
Hit count: 281
Suppose there is an element in XML data: <abc:xyz:name attr="value"/>
I'm trying to read it with XmlReader. The problem is that I get XmlException that says
The ‘:’ character, hexadecimal value 0x3A, cannot be included in a name
I have already declared "abc" namespace. I have also tried adding "abc:xyz" and "xyz" namespaces. But this doesn't help at all. I could replace some text before parsing but there may be some more elegant solution. So what should I do?
Here is my code:
XmlReaderSettings settings = new XmlReaderSettings()
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("abc", "");
nsmgr.AddNamespace("xyz", "");
XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
// So this reader can't read <abc:xyz:name attr="value"/>
XmlReader reader = XmlReader.Create(path, settings, context);“
© Stack Overflow or respective owner