Results 1 to 6 of 6

Thread: Asp Xml Iteration Problem **Resolved**

  1. #1

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935

    Asp Xml Iteration Problem **Resolved**

    hello all,

    Has anyone here tried parsing an xml document from an asp page before??

    The code I have written doesnt have any "errors" persay it just doesnt execute correctly

    this is all dummy code for testing so it looks nasty

    The app has the following

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim xmld As MSXML2.DOMDocument30
    3. Dim xmld2 As MSXML2.XMLHTTP30
    4. Dim mynode
    5. Dim myothernode
    6. Dim rmDoc
    7. Set xmld = New MSXML2.DOMDocument30
    8. Set rmDoc = xmld.createElement("bob")
    9. Set xmld.documentElement = rmDoc
    10. Set mynode = xmld.createNode(NODE_ELEMENT, "Hungry", "")
    11. Set myothernode = xmld.createNode(NODE_TEXT, "Food", "")
    12. myothernode.Text = "Hamburgers yummy"
    13. mynode.appendChild (myothernode)
    14. Set xmld2 = New MSXML2.XMLHTTP30
    15. xmld2.open "POST", "http://escs1/richmastery/secure/xml/put_order.asp?IDGRP=AKL&userCode=miketest&pwd=mik001p", False
    16. xmld2.send xmld
    17. Set strResponse = xmld2.responseXML
    18. Text1.Text = ""
    19. Text1.Text = Text1.Text & xmld2.responseText
    20. Open "C:\Workshop\temp\t.htm" For Output As #1
    21. Print #1, Text1.Text
    22. Close #1
    23. WebBrowser1.Navigate "C:\Workshop\temp\t.htm"
    24. End Sub

    then the asp page grabs it validates it and falls apart at this code here

    VB Code:
    1. Private function parse_xml
    2. Dim strField
    3. Dim strValue
    4. Dim isSuccess
    5. Dim xNode
    6. dim oNode
    7. set oNode = XMLdoc.documentElement
    8. Response.Write ("<got here1>")
    9. For Each xNode In oNode.childNodes 'this line is the line that it excutes but doesnt find any nodes so it skips to end of function
    10.    
    11.     'If xNode.nodeType = NODE_TEXT Then
    12.         Response.Write ("<got here2>")
    13.         strField = xNode.parentNode.nodeName
    14.        
    15.         'If Not IsNull(xNode.nodeValue) Then
    16.            'strValue = xNode.nodeValue
    17.         'Else
    18.             strValue = xNode.Text
    19.         'End If
    20.            
    21.         sortValues strField, strValue
    22.                
    23.     'End If
    24.    
    25.     'If xNode.hasChildNodes Then
    26.         'IterateNodes xNode.childNodes
    27.     'End If
    28.  
    29. Next
    30.  
    31. end function
    32.  
    33. private function sortValues(strField, strValue)
    34. Response.ContentType = "text/HTML"
    35. Response.Write ("<" & strfield & ">")
    36. Response.Write (chr(9) & "<" & strvalue & ">")
    37. Response.Write ("</" & strfield & ">")
    38. end function


    any ideas would be greatly appreciated
    Last edited by rudvs2; Aug 8th, 2002 at 12:44 AM.

  2. #2
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    'Doesnt execute correctly' isnt much to go on......what isnt happening that should/is that shouldnt? Is it just that it isnt finding any nodes or is there something more sinister going on?
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  3. #3

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    sorry I should have been clearer.

    It isnt finding any nodes. I have basically concluded that the problem is either I am defining the wrong node type to look for or in the remote app its not creating the xml correctly

    but I cant seem to see what It is that I have done wrong.

  4. #4
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Can u post the XML document u r trying to parse?
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  5. #5

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    The xml document is being dynamically constructed by the app and then sent to the asp page all the code for this is posted above

  6. #6

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    okay all I have finally figured out where i went wrong

    It was the way in which i was creating the XML document. The structure I was using was all messed up

    For those that might be interested here is a sample format of code that works


    In the App
    VB Code:
    1. Dim xmld As MSXML2.DOMDocument30
    2. Dim xmld2 As MSXML2.XMLHTTP30
    3. Dim rootElement
    4. Dim memoAttribute
    5. Dim memoAttributeText
    6. Dim toElement
    7. Dim toElementText
    8.  
    9. 'create the items
    10. Set xmld = New MSXML2.DOMDocument30
    11. Set rootElement = xmld.createElement("Memo")
    12. Set memoAttribute = xmld.createAttribute("Author")
    13. Set memoAttributeText = xmld.createTextNode("Pat Coleman")
    14. Set toElement = xmld.createElement("To")
    15. Set toElementText = xmld.createTextNode("Carol Poland")
    16.  
    17. 'build the document
    18. xmld.appendChild (rootElement)
    19. rootElement.setAttributeNode (memoAttribute)
    20. rootElement.appendChild (toElement)
    21. rootElement.appendChild (toElementText)
    22.  
    23. 'prepare object to send xml to asp page
    24. Set xmld2 = New MSXML2.XMLHTTP30
    25. 'send out the xml
    26. xmld2.open "POST", "http://escs1/richmastery/secure/xml/put_order.asp?IDGRP=AKL&userCode=miketest&pwd=mik001p", False
    27. xmld2.send xmld
    28. 'get and process the response
    29. Set strResponse = xmld2.responseXML
    30. Text1.Text = ""
    31. Text1.Text = Text1.Text & xmld2.responseText
    32. Open "C:\Workshop\temp\t.htm" For Output As #1
    33. Print #1, Text1.Text
    34. Close #1
    35. WebBrowser1.Navigate "C:\Workshop\temp\t.htm"

    and on the asp page

    VB Code:
    1. Private function parse_xml
    2. Dim strField
    3. Dim strValue
    4. Dim isSuccess
    5. Dim xNode
    6. dim oNode
    7. set oNode = XMLdoc.documentElement
    8. Response.Write ("<got here1>")
    9.  
    10.  
    11. For Each xNode In oNode.childNodes
    12.    
    13.     If xNode.nodeType = 3 Then
    14.         Response.Write ("<got here2>")
    15.         strField = xNode.parentNode.nodeName
    16.        
    17.         If Not IsNull(xNode.nodeValue) Then
    18.            strValue = xNode.nodeValue
    19.         Else
    20.             strValue = xNode.Text
    21.         End If
    22.            
    23.         sortValues strField, strValue
    24.                
    25.     End If
    26.    
    27.     If xNode.hasChildNodes Then
    28.         IterateNodes xNode.childNodes
    29.     End If
    30.  
    31. Next
    32.  
    33. end function
    34.  
    35. private function sortValues(strField, strValue)
    36. Response.ContentType = "text/HTML"
    37. Response.Write ("<" & strfield & ">")
    38. Response.Write (chr(9) & "<" & strvalue & ">")
    39. Response.Write ("</" & strfield & ">")
    40. end function

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