[英]VB.net read XML element
我試圖在VB.net中編寫一個應用程序,但我堅持了下來,花了一些時間搜索如何執行此操作,但無法獲取。 我需要的是讀取特定的xml元素並將其寫入特定的標簽。 如果有人可以給我一個例子。
我需要這樣的輸出:
--Book 1---
Title: Everyday Italian
Author: Giada De Laurentiis
--Book 2--
Title: Harry Potter
Author: J K. Rowling
--etc--
XML:
<bookstore>
<book>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<title>XQuery Kick Start</title>
<author>James McGovern</author>
<year>2003</year>
<price>49.99</price>
</book>
<book>
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
我需要的是這樣的: 圖片
現在只顯示第一本書。 我需要循環所有書。
謝謝
Dim xmlRoot As XElement = XDocument.Load("x:\books.xml").Root
For Each book As XElement In xmlRoot.<book>
Debug.WriteLine(book.<title>.Value)
Debug.WriteLine(book.<author>.Value)
Debug.WriteLine(book.<year>.Value)
Debug.WriteLine(book.<price>.Value)
Next
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.