Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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
XML,读取对象的属性,VB.net_Xml_Vb.net - Fatal编程技术网

XML,读取对象的属性,VB.net

XML,读取对象的属性,VB.net,xml,vb.net,Xml,Vb.net,我试图获得这个xml文档的价格(90.0),但要让它正常工作,我尝试使用xmlTextReader和ReadElementString函数,但我想我需要获得属性。然后,我研究了如何使用GetAttribute函数 <s:inventories> - <s:inventory channel="online" availability="inStock"> <s:price currency="USD">90.0</s:price> <

我试图获得这个xml文档的价格(90.0),但要让它正常工作,我尝试使用xmlTextReader和ReadElementString函数,但我想我需要获得属性。然后,我研究了如何使用GetAttribute函数

<s:inventories>
- <s:inventory channel="online" availability="inStock">
  <s:price currency="USD">90.0</s:price> 
  </s:inventory>
  </s:inventories>

- 
90
我相信这很容易,但在网上找不到如何做到这一点,有什么想法吗

提前谢谢

Dim xmlString as String = ...

Dim s As XNamespace = "s"
Dim e As XElement = XElement.Parse(xmlString)
Dim price = e.Element(s + "inventory").Element(s + "price").Value

请确保您为
“s”

声明了名称空间,谢谢您这么做,但当我刚刚尝试此操作时,最后一行出现了空引用错误?“对象引用未设置为对象的实例”?您可以发布如何包含声明的命名空间吗?如果没有名称空间,此代码段将打印90.0这是可行的,干杯。对于完整的Xml字符串,尽管它有问题:我似乎无法将完整的Xml字符串添加到页面上的这个网站中,您能给我发电子邮件给paul吗。standage@gmail.com我可以把它寄过来吗?