Solved

Reading XML Values...

Posted on 2007-03-30
5
213 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
Comment Utility
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
Comment Utility
you don't need the save

take out the line

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

Expert Comment

by:DarrenD
Comment Utility
This line should also be...

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

Expert Comment

by:DarrenD
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now