I'm using an xmlreader to read an xml file. The problem is i have many undefined namespaces in the child elements. Because of it, I'm unable to read the content of the files. Is there any way to read the contents of the files avoiding this issue or is there any solution to handle these kind of scenarios?
Asked
Active
Viewed 3,037 times
4
-
1Can you post a small XML snippet to show your problem? – Paolo Tedesco Oct 03 '11 at 14:37
-
2What do you mean that they're undefined? If there is really no namespace declaration for the given namespace prefixes, then you have garbage, and not XML. – John Saunders Oct 03 '11 at 14:38
-
Undefined in the sense, they arent defined in the root element but have been used in its descendants – senthil kumar Oct 03 '11 at 15:01
-
Vote to close: so far there is no issue explained/shown in the question - provide sample XML, code, errors and expected behavior. – Alexei Levenkov Oct 03 '11 at 16:01
1 Answers
2
You can add the missing namespaces to the XmlReader like this.
var settings = new XmlReaderSettings
{
NameTable = new NameTable(),
};
XmlNamespaceManager xmlns = new XmlNamespaceManager(settings.NameTable);
xmlns.AddNamespace("yourundeclarednamespace", "http://www.dummynamespace.org");
XmlParserContext context = new XmlParserContext(null, xmlns, "", XmlSpace.Default);
using (var reader = XmlReader.Create(filePath, settings, context))
{
}

Eric
- 245
- 1
- 9