|
-
Aug 6th, 2002, 11:25 PM
#1
Thread Starter
Fanatic Member
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:
Private Sub Command1_Click()
Dim xmld As MSXML2.DOMDocument30
Dim xmld2 As MSXML2.XMLHTTP30
Dim mynode
Dim myothernode
Dim rmDoc
Set xmld = New MSXML2.DOMDocument30
Set rmDoc = xmld.createElement("bob")
Set xmld.documentElement = rmDoc
Set mynode = xmld.createNode(NODE_ELEMENT, "Hungry", "")
Set myothernode = xmld.createNode(NODE_TEXT, "Food", "")
myothernode.Text = "Hamburgers yummy"
mynode.appendChild (myothernode)
Set xmld2 = New MSXML2.XMLHTTP30
xmld2.open "POST", "http://escs1/richmastery/secure/xml/put_order.asp?IDGRP=AKL&userCode=miketest&pwd=mik001p", False
xmld2.send xmld
Set strResponse = xmld2.responseXML
Text1.Text = ""
Text1.Text = Text1.Text & xmld2.responseText
Open "C:\Workshop\temp\t.htm" For Output As #1
Print #1, Text1.Text
Close #1
WebBrowser1.Navigate "C:\Workshop\temp\t.htm"
End Sub
then the asp page grabs it validates it and falls apart at this code here
VB Code:
Private function parse_xml
Dim strField
Dim strValue
Dim isSuccess
Dim xNode
dim oNode
set oNode = XMLdoc.documentElement
Response.Write ("<got here1>")
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
'If xNode.nodeType = NODE_TEXT Then
Response.Write ("<got here2>")
strField = xNode.parentNode.nodeName
'If Not IsNull(xNode.nodeValue) Then
'strValue = xNode.nodeValue
'Else
strValue = xNode.Text
'End If
sortValues strField, strValue
'End If
'If xNode.hasChildNodes Then
'IterateNodes xNode.childNodes
'End If
Next
end function
private function sortValues(strField, strValue)
Response.ContentType = "text/HTML"
Response.Write ("<" & strfield & ">")
Response.Write (chr(9) & "<" & strvalue & ">")
Response.Write ("</" & strfield & ">")
end function
any ideas would be greatly appreciated
Last edited by rudvs2; Aug 8th, 2002 at 12:44 AM.
-
Aug 7th, 2002, 01:18 AM
#2
Frenzied Member
'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
-
Aug 7th, 2002, 02:13 AM
#3
Thread Starter
Fanatic Member
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.
-
Aug 7th, 2002, 04:34 AM
#4
Frenzied Member
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
-
Aug 7th, 2002, 11:03 PM
#5
Thread Starter
Fanatic Member
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
-
Aug 8th, 2002, 12:42 AM
#6
Thread Starter
Fanatic Member
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:
Dim xmld As MSXML2.DOMDocument30
Dim xmld2 As MSXML2.XMLHTTP30
Dim rootElement
Dim memoAttribute
Dim memoAttributeText
Dim toElement
Dim toElementText
'create the items
Set xmld = New MSXML2.DOMDocument30
Set rootElement = xmld.createElement("Memo")
Set memoAttribute = xmld.createAttribute("Author")
Set memoAttributeText = xmld.createTextNode("Pat Coleman")
Set toElement = xmld.createElement("To")
Set toElementText = xmld.createTextNode("Carol Poland")
'build the document
xmld.appendChild (rootElement)
rootElement.setAttributeNode (memoAttribute)
rootElement.appendChild (toElement)
rootElement.appendChild (toElementText)
'prepare object to send xml to asp page
Set xmld2 = New MSXML2.XMLHTTP30
'send out the xml
xmld2.open "POST", "http://escs1/richmastery/secure/xml/put_order.asp?IDGRP=AKL&userCode=miketest&pwd=mik001p", False
xmld2.send xmld
'get and process the response
Set strResponse = xmld2.responseXML
Text1.Text = ""
Text1.Text = Text1.Text & xmld2.responseText
Open "C:\Workshop\temp\t.htm" For Output As #1
Print #1, Text1.Text
Close #1
WebBrowser1.Navigate "C:\Workshop\temp\t.htm"
and on the asp page
VB Code:
Private function parse_xml
Dim strField
Dim strValue
Dim isSuccess
Dim xNode
dim oNode
set oNode = XMLdoc.documentElement
Response.Write ("<got here1>")
For Each xNode In oNode.childNodes
If xNode.nodeType = 3 Then
Response.Write ("<got here2>")
strField = xNode.parentNode.nodeName
If Not IsNull(xNode.nodeValue) Then
strValue = xNode.nodeValue
Else
strValue = xNode.Text
End If
sortValues strField, strValue
End If
If xNode.hasChildNodes Then
IterateNodes xNode.childNodes
End If
Next
end function
private function sortValues(strField, strValue)
Response.ContentType = "text/HTML"
Response.Write ("<" & strfield & ">")
Response.Write (chr(9) & "<" & strvalue & ">")
Response.Write ("</" & strfield & ">")
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|