Results 1 to 11 of 11

Thread: [2005] VB5/6 to VB.NET help?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    [2005] VB5/6 to VB.NET help?

    Hey,

    I was hoping someone could help out with converting this code:
    Code:
    Public Function LoadXMLNode()
    
       Dim xmlDoc As DOMDocument30
       Dim intCounter As Integer
       
       Set xmlDoc = New MSXML2.DOMDocument30
    
       Me.TxtXMLOut.Text = ""
       
       xmlDoc.loadXML Me.TxtXML.Text
       
       Call RecurseChildNodes(xmlDoc, xmlDoc.childNodes)
       
       Set xmlDoc = Nothing
          
    End Function
    
    Public Function RecurseChildNodes(xmlDoc As MSXML2.DOMDocument30, childNode As IXMLDOMNodeList)
       
       
       Dim CurrChildNode  As IXMLDOMNodeList
       Dim intNodeCounter As Integer
       
       Set CurrChildNode = childNode
       
       For intNodeCounter = 0 To CurrChildNode.length - 1
          
          If CurrChildNode.length > 0 Then
             Set childNode = CurrChildNode.Item(intNodeCounter).childNodes
             If childNode.length > 0 Then
                RecurseChildNodes xmlDoc, childNode
                Me.TxtXMLOut.Text = Me.TxtXMLOut.Text & CurrChildNode.Item(intNodeCounter).nodeName & "= " & CurrChildNode.Item(intNodeCounter).nodeTypedValue & vbCrLf
             End If
          End If
          
            
       Next intNodeCounter
       
    End Function
    The code is in VB5/6 but i need to get it to vb.net 2005, could anyone help me out? im sure theres a simple new rule to it or something.

    I get errors saying:
    MSXML2.DOMDocument30 is not defined
    DOMDocument30 is not defined
    IXMLDOMNodeList is not defined

    Thanks for any help
    lee
    If a post has been usefull then Rate it!

  2. #2
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] VB5/6 to VB.NET help?

    Try this. I just stuck it in the IDE and it has no errors.

    vb.net Code:
    1. Public Function LoadXMLNode()
    2.  
    3.       Dim xmlDoc As Xml.XmlDocument
    4.  
    5.       xmlDoc = New Xml.XmlDocument()
    6.  
    7.       Me.TxtXMLOut.Text = ""
    8.  
    9.       xmlDoc.loadXML(Me.TxtXML.Text)
    10.  
    11.       Call RecurseChildNodes(xmlDoc, xmlDoc.childNodes)
    12.  
    13.       xmlDoc = Nothing
    14.  
    15.       Return Nothing
    16.  
    17.    End Function
    18.  
    19.    Public Function RecurseChildNodes(ByVal xmlDoc As Xml.XmlDocument, ByVal childNode As Xml.XmlNodeList)
    20.  
    21.  
    22.       Dim CurrChildNode As Xml.XmlNodeList
    23.       Dim intNodeCounter As Integer
    24.  
    25.       CurrChildNode = childNode
    26.  
    27.       For intNodeCounter = 0 To CurrChildNode.Count - 1
    28.  
    29.          If CurrChildNode.Count > 0 Then
    30.             childNode = CurrChildNode.Item(intNodeCounter).ChildNodes
    31.             If childNode.Count > 0 Then
    32.                RecurseChildNodes(xmlDoc, childNode)
    33.                Me.TxtXMLOut.Text = Me.TxtXMLOut.Text & CurrChildNode.Item(intNodeCounter).Name & "= " & CurrChildNode.Item(intNodeCounter).NodeType & vbCrLf
    34.             End If
    35.          End If
    36.  
    37.       Next intNodeCounter
    38.  
    39.       Return Nothing
    40.  
    41.    End Function

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    Re: [2005] VB5/6 to VB.NET help?

    Using that code didnt work right, i put in the xml:
    <Clients>
    <Client>
    <NameInfo>
    <NameFirst>Mickey</NameFirst>
    <NameLast>Mouse</NameLast>
    <NamePrefix>Mr.</NamePrefix>
    </NameInfo>
    <NameInfo>
    <NameFirst>Donald</NameFirst>
    <NameLast>Duck</NameLast>
    <NamePrefix>Mr.</NamePrefix>
    </NameInfo>
    </Client>
    </Clients>
    The result i get is incorrect:
    NameFirst= 1
    NameLast= 1
    NamePrefix= 1
    NameInfo= 1
    NameFirst= 1
    NameLast= 1
    NamePrefix= 1
    NameInfo= 1
    Client= 1
    Clients= 1
    im unsure if im doing anything wrong or not :s
    If a post has been usefull then Rate it!

  4. #4
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] VB5/6 to VB.NET help?

    try this..
    vb.net Code:
    1. CurrChildNode.Item(intNodeCounter).Value
    2. 'instead of CurrChildNode.Item(intNodeCounter).Name

    I never used xml before. but this should give you the right response that you are looking for.. the .name looks for a Name="" field, and i believe the .value will give you what you want.

  5. #5
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] VB5/6 to VB.NET help?

    Vblee,

    that's not VB5/6 code. It's already in VB 2005.

    I think the problems are simply caused because you are missing a reference to the microsoft MSXML2 namespace (if not more). Add the appropriate reference(s) and the problems will be taken care of.
    Last edited by stimbo; Jun 21st, 2007 at 11:22 AM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    Re: [2005] VB5/6 to VB.NET help?

    That gets me:
    = 1
    = 1
    = 1
    = 1
    = 1
    = 1
    = 1
    = 1
    = 1
    = 1
    If a post has been usefull then Rate it!

  7. #7
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] VB5/6 to VB.NET help?

    oh, my bad.. I was looking at that the wrong way..

    change .Value back to .Name

    try this where .NodeType is


    kind of confusing but may work.
    vb.net Code:
    1. CurrChildNode.Item(intNodeCounter).GetAttribute(CurrChildNode.Item(intNodeCounter).Name().ToString)

    if getAttribute does not work try GetElementsByTagName()

    sorry nothing is working.. not really an xml guru.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    Re: [2005] VB5/6 to VB.NET help?

    Quote Originally Posted by stimbo
    Vblee,

    that's not VB5/6 code. It's already in VB 2005.

    I think the problems are simply caused because you are missing a reference to the microsoft MSXML2 namespace (if not more). Add the appropriate reference(s) and the problems will be taken care of.
    I have tried that and it doesnt work.

    NPassero i get an error with that line, "GetAttribute" is not a member of "system.xml.xmlnode"
    If a post has been usefull then Rate it!

  9. #9
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] VB5/6 to VB.NET help?

    Did you try the GetElementByTagName()
    if not, i am fresh out of ideas, and someone who is really familiar with XML needs to step in.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    Re: [2005] VB5/6 to VB.NET help?

    Nope nothing, thanks for your help, hope someone with more knowledge of xml can help.
    If a post has been usefull then Rate it!

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] VB5/6 to VB.NET help?

    I notice that what NPassero suggested in post #2 got you almost the right answer, except that it returned the type, which was not what you wanted.

    What was it that your code returned? Did you get an error, or did you get incorrect information, and if so, what?

    I'm leaning towards either Stimbo is on the right track, or this line is wrong:

    CurrChildNode.Item(intNodeCounter).nodeTypedValue

    but it depends on what you were getting originally.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width