Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help with getting XML node

Posted on 2006-10-20
7
Medium Priority
?
503 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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