Solved

Reading XML Values...

Posted on 2007-03-30
5
216 Views
Last Modified: 2010-04-24
I have a question reading XML-Files. I am writing it in this format:

 <?xml version="1.0" ?>
- <!-- Template for Media Remote 2007
  -->
- <MediaRemote2007>
- <Settings>
  <Name>Test</Name>
  <Author>Sven Rutten</Author>
  <BackgroundImage />
- <Button1>
  <Text>Button1</Text>
  <BackColor>-1316371</BackColor>
  <ForeColor>-16777216</ForeColor>
  <Left>78</Left>
  <Top>119</Top>
  <Width>75</Width>
  <Height>23</Height>
  <Command>Nothing</Command>
  </Button1>
- <Button2>
  <Text>Button2</Text>
  <BackColor>-65281</BackColor>
  <ForeColor>-16711936</ForeColor>
  <Left>11</Left>
  <Top>170</Top>
  <Width>93</Width>
  <Height>26</Height>
  <Command>Nothing</Command>
  </Button2>
- <pb1>
  <Left>16</Left>
  <Top>25</Top>
  <Width>64</Width>
  <Height>48</Height>
  <Command>Nothing</Command>
  <Picture />
  </pb1>
- <pb2>
  <Left>80</Left>
  <Top>0</Top>
  <Width>56</Width>
  <Height>40</Height>
  <Command />
  <Picture />
  </pb2>
  </Settings>
  </MediaRemote2007>

I have several Buttons and Picturebox. How can I now loop through all these buttons and picturebox and read the values of them?

Thanks

Sven
0
Comment
Question by:Ruttensoft
  • 4
5 Comments
 
LVL 18

Accepted Solution

by:
DarrenD earned 500 total points
ID: 18823289
I'm not sure you XML is correct.

If you want to loop through all of the button elements and picture box elements then you should probably have then under the same name so that you can retrieve all buttons and all picutre boxes and then go through them one by one.

So you have

<Button>
...
</Button>
<Button>
...
</Button>
<Button>
...
</Button>

and

<pb>
...
</pb>
<pb>
...
</pb>
<pb>
...
</pb>

etc...

I think this is a good start. Then to loop through them

        Dim NewXmlDoc2 As New XmlDocument
        Dim oNodeList As XmlNodeList
        Dim oRootNode As XmlNode
        Dim oNode As XmlNode

        Try
            NewXmlDoc2.Load("C:\test\test.xml")

            oRootNode = NewXmlDoc2.DocumentElement()
            oNodeList = oRootNode.SelectNodes("/MediaRemote2007/Button")

            For Each oNode In oNodeList
                ' You can loop through each button or picture box node and pull out the values
            Next

            NewXmlDoc2.Save("C:\test\test.xml")

        Catch ex As SystemException
            MessageBox.Show(ex.Message)
        End Try
0
 
LVL 18

Expert Comment

by:DarrenD
ID: 18823295
you don't need the save

take out the line

NewXmlDoc2.Save("C:\test\test.xml")
0
 
LVL 18

Expert Comment

by:DarrenD
ID: 18823311
This line should also be...

oNodeList = oRootNode.SelectNodes("/MediaRemote2007/Settings/Button")
0
 
LVL 18

Expert Comment

by:DarrenD
ID: 18823382
Here is how you get the Text contents:

For Each oNode In oNodeList
 MessageBox.Show(oNode.Item("Text").InnerText.ToString)
 ' You can loop through each button or picture box node and pull out the values
Next

Hope all of this helps,

Darren
0
 

Author Comment

by:Ruttensoft
ID: 18823383
Thanks
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question