1

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

1 Answer 1

2
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
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. It's working in console. You know maybe how to make that in the windows form application?
You need to create the labels on runtime or create a custom control that can hold and show that info or ... a lot of possibilities :)
Thanks. Will try now. I think I am on a good way to make it. Thanks again. Can I contact you if I stuck? :)
Best is asking here, there are lot more capable people around than me :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.