4

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?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
senthil kumar
  • 119
  • 2
  • 4

1 Answers1

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