开发者

Ignoring namespace in XmlReader

开发者 https://www.devze.com 2023-04-10 00:30 出处:网络
I\'m using an xmlreader to read an xml fil开发者_如何学Goe. 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

I'm using an xmlreader to read an xml fil开发者_如何学Goe. 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?


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))
{
}
0

精彩评论

暂无评论...
验证码 换一张
取 消