Solved

Help with getting XML node

Posted on 2006-10-20
7
500 Views
Last Modified: 2011-09-20
Hi,

I have attempted to write code which will run a different query depending on the node "type"

Here is my code;

    Private Sub OpenXML(ByVal SourceFileName As String)

        Dim XmlDoc As New XmlDocument
        XmlDoc.Load(SourceFileName)
        Dim currentNodes As XmlNodeList = XmlDoc.SelectNodes("//Type/Type")
        Dim currentArray As ArrayList = NodesToArrayList(currentNodes)

        For Each currentNodes In currentArray
            If currentNode = "Hardware" Then
                QueryHardware(SourceFileName)

            ElseIf XmlDoc.Value = "Software" Then
                QuerySoftware(SourceFileName)

            ElseIf XmlDoc.Value = "SoftwareUnchecked" Then
                QueryUnchecked(SourceFileName)
            End If
        Next

    End Sub

Please help.
0
Comment
Question by:nickmarshall
[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
  • 3
7 Comments
 
LVL 9

Accepted Solution

by:
DjDezmond earned 125 total points
ID: 17772305
I havn't tested this, but I saw where you had gone wrong. Consider this line:
   "For each CurrentNode in CurrentArray"
That line declares the variable 'CurrentNode' as whatever objects are in the 'CurrentArray' list. So there is no need to declare it before then. (declare the variable obviously, but you don't need to reference it to anything).

Private Sub OpenXML(ByVal SourceFileName As String)
        Dim XmlDoc As New XmlDocument
        XmlDoc.Load(SourceFileName)
        Dim currentNode As XmlNode
        Dim currentArray As ArrayList = NodesToArrayList(currentNodes)

        For Each currentNode In currentArray
            Select case CurrentNode
              Case "Hardware"
                QueryHardware(SourceFileName)
              Case "Software"
                QuerySoftware(SourceFileName)
              Case "SoftwareUnchecked"
                QueryUnchecked(SourceFileName)
             End Select
        Next
    End Sub

Hope this works..

Dez
0
 
LVL 9

Expert Comment

by:DjDezmond
ID: 17772318
Sorry, you need to add back:

        Dim currentNodes As XmlNodeList = XmlDoc.SelectNodes("//Type/Type")

... in the declaration area... so it will be:

        Dim XmlDoc As New XmlDocument
        XmlDoc.Load(SourceFileName)
        Dim currentNode As XmlNode
        Dim currentNodes As XmlNodeList = XmlDoc.SelectNodes("//Type/Type")  <<-- Add back (I deleted by mistake before!)
        Dim currentArray As ArrayList = NodesToArrayList(currentNodes)

Let me know how you get on...
Dez
0
 
LVL 9

Expert Comment

by:DjDezmond
ID: 17772339
And this line "For Each currentNode In currentArray" should change to:

  For Each currentNode In currentNodes

Sorry for all the posts (im not having a very good day lol).
I've not done much work with XML documents, but as long as this line was already correct (from your original code):

  Dim currentNodes As XmlNodeList = XmlDoc.SelectNodes("//Type/Type")

There should be no problems.

Dez
0
Technology Partners: 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!

 
LVL 1

Author Comment

by:nickmarshall
ID: 17772405
Hi Dez,

I am getting overload resolution failed on the Case lines...

with "hardware", "software", "Softwareunchecked" underlined?
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17772425
It says,

value of type system.xml.xmlnode cannot be converted to a string
0
 
LVL 1

Author Comment

by:nickmarshall
ID: 17772435
I have modified it with;

Select Case currentNode.ToString

which seems to have worked now.

0
 
LVL 9

Expert Comment

by:DjDezmond
ID: 17772461
Yea, sorry, like i said I had not tested it, if i had i'd of picked that up.

Glad its working now anyway.

Cheers,
Dez
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 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