Solved

Help with getting XML node

Posted on 2006-10-20
7
494 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
  • 4
  • 3
7 Comments
 
LVL 9

Accepted Solution

by:
DjDezmond earned 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:nickmarshall
Comment Utility
Hi Dez,

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

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

Author Comment

by:nickmarshall
Comment Utility
It says,

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

Author Comment

by:nickmarshall
Comment Utility
I have modified it with;

Select Case currentNode.ToString

which seems to have worked now.

0
 
LVL 9

Expert Comment

by:DjDezmond
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

17 Experts available now in Live!

Get 1:1 Help Now