一个人怎么可以在文档中找到未知的XML命名空间? [英] How can one find unknown XML namespaces in a document?

查看:137
本文介绍了一个人怎么可以在文档中找到未知的XML命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体(深吸一口气):你会如何去在C#/找到所有的XML命名空间NET 的XmlDocument 对其中有中没有适用的模式实例的的XmlSchemaSet 架构属性)?

Specifically (taking a deep breath): How would you go about finding all the XML name spaces within a C#/.NET XmlDocument for which there are no applicable schemas in the instance's XmlSchemaSet (Schemas property)?

我的XPath神奇的是缺乏成熟到做这样的事情,但是我将继续寻找在此期间...

My XPath magic is lacking the sophistication to do something like this, but I will keep looking in the meantime ...

推荐答案

您需要把所有的不同的命名空间的文档中的列表,然后比较,与不同的命名空间的架构设置。

You need to get a list of all the distinct namespaces in the document, and then compare that with the distinct namespaces in the schema set.

但空间声明的名称通常不中的XPath文档模型曝光。但考虑到一个节点,你可以得到它的命名空间:

But namespace declaration names are typically not exposed in the XPath document model. But given a node you can get its namespace:

// Match every element and attribute in the document
var allNodes = xmlDoc.SelectNodes("//(*|@*)");
var found = new Dictionary<String, bool>(); // Want a Set<string> really
foreach (XmlNode n in allNodes) {
  found[n.NamespaceURI] = true;
}
var allNamespaces = found.Keys.OrderBy(s => s);

这篇关于一个人怎么可以在文档中找到未知的XML命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆