AEJ45
2011-03-17 12:29:26 UTC
I have the following in an XML file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE paymentService PUBLIC "-//?????//??????//EN"
"Location">
<paymentService version="1.4" merchantCode="MCODE">
<reply>
<batchStatus merchantBatchCode="2" status="PROCESSED"
transactions="4">
<orderStatus orderCode="123456789">
<payment>
<paymentMethod>VISA_DEBIT-SSL</paymentMethod>
<amount value="100" currencyCode="GBP" exponent="2"
debitCreditIndicator="credit"/>
<lastEvent>AUTHORISED</lastEvent>
<CVCResultCode description="B"/>
<AVSResultCode description="C"/>
<cardHolderName>
<![CDATA[CARD HOLDER]]>
</cardHolderName>
<issuerCountryCode>GB</issuerCountryCode>
<balance accountType="IN_PROCESS_AUTHORISED">
<amount value="100" currencyCode="GBP" exponent="2"
debitCreditIndicator="credit"/>
</balance>
<cardNumber>1234********5678</cardNumber>
<riskScore value="0"/>
</payment>
</orderStatus>
</batchStatus>
</reply>
</paymentService>
I have the following code to read through teh xml:
Option Explicit
Dim oDom As msxml.DOMDocument
Dim strErrText As String
Dim xPE As msxml.IXMLDOMParseError
Dim xNode As msxml.IXMLDOMNode
Dim lCounter As Long
Dim fpath As String
Sub LoadXML()
fpath = "L:\XMLResponse\Batches\Query Response for BatchID2.xml"
Set oDom = New msxml.DOMDocument
oDom.async = False
oDom.Load (fpath)
If oDom.parseError.ErrorCode <> 0 Then
Set xPE = oDom.parseError
strErrText = xPE.ErrorCode & vbCrLf & xPE.reason & vbCrLf &
xPE.Line & vbCrLf & xPE.linepos & vbCrLf & xPE.srcText
MsgBox "Laod failed" & vbCrLf & strErrText
Exit Sub
End If
'''''' For lCounter = 0 To oDom.ChildNodes.Length - 1
'''''' Debug.Print oDom.ChildNodes.item(lCounter).Text
'''''' Next lCounter
DisplayNode oDom.ChildNodes, 0
End Sub
Sub DisplayNode(ByRef nodes As msxml.IXMLDOMNodeList, ByVal Indent As
Integer)
Indent = Indent + 2
For Each xNode In nodes
If xNode.NodeType = NODE_ELEMENT Then
Debug.Print "Node Element: " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
ElseIf xNode.NodeType = NODE_ATTRIBUTE Then
Debug.Print "Node Attribute: " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
ElseIf xNode.NodeType = NODE_CDATA_SECTION Then
Debug.Print "Node CDATA: " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
ElseIf xNode.NodeType = NODE_ENTITY Then
Debug.Print "Node Entity: " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
ElseIf xNode.NodeType = NODE_TEXT Then
Debug.Print "Node Text: " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
Else
Debug.Print xNode.NodeType & ": " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
End If
If xNode.HasChildNodes Then
DisplayNode xNode.ChildNodes, Indent
End If
Next xNode
End Sub
Whenever I run through it it never returns the orderCode or the amount
value. Can anybody point me in teh right direction to get this
working? I need to be able to iterate through multiple records in teh
same xml document. For each record I need the orderCode value, the
amount value and the lastEvent value but cannot see how it is done.
TIA
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE paymentService PUBLIC "-//?????//??????//EN"
"Location">
<paymentService version="1.4" merchantCode="MCODE">
<reply>
<batchStatus merchantBatchCode="2" status="PROCESSED"
transactions="4">
<orderStatus orderCode="123456789">
<payment>
<paymentMethod>VISA_DEBIT-SSL</paymentMethod>
<amount value="100" currencyCode="GBP" exponent="2"
debitCreditIndicator="credit"/>
<lastEvent>AUTHORISED</lastEvent>
<CVCResultCode description="B"/>
<AVSResultCode description="C"/>
<cardHolderName>
<![CDATA[CARD HOLDER]]>
</cardHolderName>
<issuerCountryCode>GB</issuerCountryCode>
<balance accountType="IN_PROCESS_AUTHORISED">
<amount value="100" currencyCode="GBP" exponent="2"
debitCreditIndicator="credit"/>
</balance>
<cardNumber>1234********5678</cardNumber>
<riskScore value="0"/>
</payment>
</orderStatus>
</batchStatus>
</reply>
</paymentService>
I have the following code to read through teh xml:
Option Explicit
Dim oDom As msxml.DOMDocument
Dim strErrText As String
Dim xPE As msxml.IXMLDOMParseError
Dim xNode As msxml.IXMLDOMNode
Dim lCounter As Long
Dim fpath As String
Sub LoadXML()
fpath = "L:\XMLResponse\Batches\Query Response for BatchID2.xml"
Set oDom = New msxml.DOMDocument
oDom.async = False
oDom.Load (fpath)
If oDom.parseError.ErrorCode <> 0 Then
Set xPE = oDom.parseError
strErrText = xPE.ErrorCode & vbCrLf & xPE.reason & vbCrLf &
xPE.Line & vbCrLf & xPE.linepos & vbCrLf & xPE.srcText
MsgBox "Laod failed" & vbCrLf & strErrText
Exit Sub
End If
'''''' For lCounter = 0 To oDom.ChildNodes.Length - 1
'''''' Debug.Print oDom.ChildNodes.item(lCounter).Text
'''''' Next lCounter
DisplayNode oDom.ChildNodes, 0
End Sub
Sub DisplayNode(ByRef nodes As msxml.IXMLDOMNodeList, ByVal Indent As
Integer)
Indent = Indent + 2
For Each xNode In nodes
If xNode.NodeType = NODE_ELEMENT Then
Debug.Print "Node Element: " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
ElseIf xNode.NodeType = NODE_ATTRIBUTE Then
Debug.Print "Node Attribute: " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
ElseIf xNode.NodeType = NODE_CDATA_SECTION Then
Debug.Print "Node CDATA: " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
ElseIf xNode.NodeType = NODE_ENTITY Then
Debug.Print "Node Entity: " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
ElseIf xNode.NodeType = NODE_TEXT Then
Debug.Print "Node Text: " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
Else
Debug.Print xNode.NodeType & ": " & Space(Indent) &
xNode.ParentNode.nodeName & ":" & xNode.NodeValue & ":" & xNode.Text
End If
If xNode.HasChildNodes Then
DisplayNode xNode.ChildNodes, Indent
End If
Next xNode
End Sub
Whenever I run through it it never returns the orderCode or the amount
value. Can anybody point me in teh right direction to get this
working? I need to be able to iterate through multiple records in teh
same xml document. For each record I need the orderCode value, the
amount value and the lastEvent value but cannot see how it is done.
TIA