Solved

Reading XML Values...

Posted on 2007-03-30
5
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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