Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split XML data in VBScript

Status
Not open for further replies.

axLW

Programmer
Feb 6, 2015
110
0
0
GB
Hello, I'm able to receive and display my XML message using the following (in my .asp file):

Code:
Response.ContentType = "text/xml"
Response.Write(httpRequest.ResponseText)

The message arrives in normal XML format:

Code:
<ChargeList>
<Charge>
<Name>Fare</Name>
<Currency>GBP</Currency>
<Price>259.29</Price>
</Charge>
<Charge>
<Name>Waiting Time</Name>
<Currency>GBP</Currency>
<Price>0.00</Price></Charge>
</ChargeList>

I would like to create an array and assign each item in the XML list to a variable which I can then use throughout my ASP page.

Can somebody please assit me?

Thanks
Antony
 
Ok I can return a valid XML message with the following URL

[link "]Link[/url]

I have used that URL in my code (with loadXML) and created a new asp page called newstatexml.asp

You can see the page here, getting an error straight away:

Link

code below:

Code:
<%

Dim objXML As New MSXML2.DOMDocument
Dim xPE As MSXML2.IXMLDOMParseError

Private Sub Command1_Click()
        Set objXML = New MSXML2.DOMDocument
        objXML.setProperty "ProhibitDTD", True
        objXML.async = False
        result = objXML.LoadXML("[URL unfurl="true"]http://www.londonlutoncars.com/statexml.asp")[/URL]
        If result = False Then
            Set xPE = objXML.parseError
            With xPE
              MsgBox "*****Error #: " & .errorCode & ": " & xPE.reason & _
                "Line #: " & .Line & vbCrLf & _
                "Line Position: " & .linepos & vbCrLf & _
                "Position In File: " & .filepos & vbCrLf & _
                "Source Text: " & .srcText & vbCrLf & _
                "Document URL: " & .url
            End With
        End If
        MsgBox objXML.selectSingleNode("//TargetJobID").Text
End Sub 

%>
 
Actually VB6 :) You would have to change it to VBScipt which wouldn't take much. Let us know if you need assistance.

Swi
 
axLW,

You should just be able to load the XML returned from your request in the first post and parse it with DOM retrieve the variable with XPath. I can't test on my side but this should work.

Code:
Dim objXML
Dim result

Set objXML = CreateObject("MSXML2.DOMDocument")
result = objXML.LoadXML(httpRequest.ResponseText)
If result = False Then
  response.write "Error loading XML"
else
  response.write objXML.selectSingleNode("//TargetJobID").Text
end if

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top