简体   繁体   中英

VB.net read XML element

I am trying to write an application in VB.net but I stuck and I spend some time searching how to do this but can't get it. What i need is read specific xml element and write it in to the specific label. If someone can give me an example.

I need output like this:

--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>

What i need is something like this: Image

Now is showing only first book. I need to loop all books.

Thank you

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM