Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用c获取带有XPAth的xml属性#_C#_Xml_Xpath - Fatal编程技术网

C# 使用c获取带有XPAth的xml属性#

C# 使用c获取带有XPAth的xml属性#,c#,xml,xpath,C#,Xml,Xpath,我试图从XML中获取属性,但出现错误: 表达式必须计算为节点测试 我不熟悉XPath XML文件示例: <Message> <Head> <Sender Identifier="id" ref=""/> </Head> </Message> 我也不知道如何显示属性值。这里是一个很好的工具,可以评估给定XML的Xpath 转到此链接,尝试将xml粘贴到文本区域,并将光标移动到需要Xpath的节点。Xpath将在下

我试图从XML中获取属性,但出现错误:

表达式必须计算为节点测试

我不熟悉XPath

XML文件示例:

<Message>
   <Head>
      <Sender Identifier="id" ref=""/>
   </Head>
</Message>

我也不知道如何显示属性值。

这里是一个很好的工具,可以评估给定XML的Xpath

转到此链接,尝试将xml粘贴到文本区域,并将光标移动到需要Xpath的节点。Xpath将在下面生成

XmlIO xml=new XmlIO(xmlPath);
 XmlIO xml = new XmlIO(xmlPath);
                ProductName = xml.SelectNodeValue(@"//PRODUCTINFO/Application/@ProductName");
                IDictionary<string, string> keyValList = xml.SelectNodesList(@"//PRODUCTINFO/Application/Parameters");
ProductName=xml。选择NodeValue(@”//PRODUCTINFO/Application/@ProductName); IDictionary keyValList=xml.selectNodeList(@”//PRODUCTINFO/Application/Parameters);
看一看

应该是

/Message/Head/Sender[@Identifier]
                    ^
                    |->no need of / here since Identifier is an attribute of sender
所以

/Message/Head/Sender[@Identifier]
仅当Sender具有
Identifier
属性时才会选择它


/Message/Head/Sender[@Identifier='id']
仅当Sender具有值为
id

标识符属性时才会选择Sender,但我确实选择了,但它没有显示出来,我想知道为什么会出现StackOverflow:如果您发布代码、XML或数据示例,请在文本编辑器中突出显示这些行,然后单击编辑器工具栏上的“代码示例”按钮(
{}
)可以很好地格式化和语法突出显示它!+1.很好的解释。通常注意-如果
id
包含单个qoute,则需要执行
concat
技巧。
/Message/Head/Sender[@Identifier]
                    ^
                    |->no need of / here since Identifier is an attribute of sender