读节点,与放,没有命名空间的标签 [英] Reading nodes with&without namespace tag
本文介绍了读节点,与放,没有命名空间的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要阅读这样的XML文档:
I need to read xml documents like this :
<wcs:CoverageOffering>
<wcs:description>Generated from GeoTIFF</wcs:description>
<wcs:name>ndh:ndh-cyclone-mortality-risks-distribution</wcs:name>
....
但在某些服务器的XML文档没有命名空间的标签实现的:
But in some servers the xml document is implemented without namespace tag :
<CoverageOffering>
<description>Generated from GeoTIFF</description>
<name>ndh:ndh-cyclone-mortality-risks-distribution</name>
....
我如何以有效的方式读取这两种? (我写的if else语句为每个节点来控制这种情况,但它似乎不是一个好办法做到这一点)
How can I read both in an efficient way? (I wrote if else statements for each node to control this condition but it seems not a good way to do it)
推荐答案
使用的XmlDocument
并添加 WCS
命名空间的XmlNamespaceManager
:
var document = new XmlDocument();
document.Load(...);
var nsmgr = new XmlNamespaceManager(document.NameTable);
nsmgr.AddNamespace("wcs", "http://...your ns");
var nl = document.SelectNodes("your xpath", nsmgr);
这篇关于读节点,与放,没有命名空间的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文