Solved

Help with getting XML node

Posted on 2006-10-20
7
496 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
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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio .Net 2012 and Crystal Reports 9 67
Pagebreak issue while printing the aspx page 3 24
Store results in vb.net 3 20
.NET 2008 VB and C# 6 27
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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