SelectSingleNode 没有命名空间 [英] SelectSingleNode without namespace

查看:35
本文介绍了SelectSingleNode 没有命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 .Net 2.0,无论命名空间如何,都需要从我的 XmlDocumentSelectSingleNode,这听起来可能是错误的.

I'm using .Net 2.0, and need to SelectSingleNode from my XmlDocument regardless of namespace, as wrong headed as that may sound.

具体的

XmlElement slipType = (XmlElement)document.SelectSingleNode("//Provenance1");

会将 slipType 设置为 null,因为在查询时我不知道命名空间 Provenance1 所在.

will set slipType to null since I don'l know th namespace Provenance1 is in at the time of the query.

推荐答案

您可以查看 local-name 元素并使用以下 XPath 表达式忽略命名空间:

You can check the local-name of the element and ignore namespace with the following XPath expression:

//*[local-name()='Provenance1']

这篇关于SelectSingleNode 没有命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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