加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – SelectSingleNodeNS中namespaces参数的预期格式

发布时间:2020-12-16 23:17:19 所属栏目:百科 来源:网络整理
导读:任何人都可以提供使用WinFT XmlDocument.SelectSingleNodeNS功能的示例吗?我不清楚第二个参数是什么期待的,我找不到一个例子. public IXmlNode SelectSingleNodeNS( string xpath,object namespaces) Contains a string that specifies the namespaces to u
任何人都可以提供使用WinFT XmlDocument.SelectSingleNodeNS功能的示例吗?我不清楚第二个参数是什么期待的,我找不到一个例子.

public IXmlNode SelectSingleNodeNS(
  string xpath,object namespaces
)

Contains a string that specifies the namespaces to use in XPath
expressions when it is necessary to define new namespaces externally.
Namespaces are defined in the XML style,as a space-separated list of
namespace declaration attributes. You can use this property to set the
default namespace as well.

解决方法

namespaces参数显然只是一个字符串(尽管声明为对象),它必须包含“xmlns:aliasname =’namespace’”(XML样式)形式的XML名称空间声明.例如

xmlDocument.DocumentElement.SelectNodesNS("cb:person","xmlns:cb='http://www.addison-wesley.de/codebook'");

使用这样的XML文档:

<?xml version="1.0" encoding="utf-8" ?>
<persons xmlns="http://www.addison-wesley.de/codebook">
  <person id="1000">
    <firstname>Zaphod</firstname>
    <lastname>Beeblebrox</lastname>
    <type>Alien</type>
  </person>
...
</persons>

请注意,别名(cb :)用于XPath.

如果命名空间不是XML样式,则会出现臭名昭着的COM错误E_Fail.

SelectNodesNS的(差)文档说:
“当需要在外部定义新的命名空间时,包含指定用于XPath表达式的命名空间的字符串.命名空间以XML样式定义,作为空格分隔的命名空间声明属性列表.您可以使用此属性设置默认值命名空间.“

根据命名空间必须是一个字符串,可能包含多个XML命名空间(尚未尝试).问题仍然是公开为什么它是一个对象.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读