[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Reading XML Values...

Posted on 2007-03-30
5
Medium Priority
?
225 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

649 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