簡體   English   中英

XML,讀取對象的屬性,VB.net

[英]XML, reading attributes to an object, VB.net

我試圖獲取這個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>

我敢肯定它很容易,但是在網上找不到如何做到這一點的,有任何想法嗎?

提前致謝

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"聲明名稱空間即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM