任何人都可以提供使用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样式定义,作为空格分隔的命名空间声明属性列表.您可以使用此属性设置默认值命名空间.“