开发者

Ignoring namespace in XmlReader

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜