ptslv
asked on
Urgent - need help identifying XML nodes and Elements using ColdFusion 4.5
Urgent: I am using ColdFusion 4.5 and javascript to identify the nodes and elements in XML files since they are all different, and I need to process them and put the data into an Access database. When I loop thru and traverse the file, all I get is 2 nodes and the Elements are all running together even though they have their own tags.
Can anyone show me how to get all the Elements? Each file is one record. Here is my code and file:
Code to see what I have:
<script type="text/vbscript">
set xmlDoc=CreateObject("Micro soft.XMLDO M")
xmlDoc.async="false"
xmlDoc.load("ATT169185.xml ")
set elem=xmlDoc.getElementsByT agName("Re marks")
for i = 1 to elem.length
document.write("Remarks Elements are: " & elem.item(i-1).text & "<br>" & "<br>" )
next
for each x in xmlDoc.documentElement.att ributes
document.write("Attribute is: " & x.name )
//for each y in xmlDoc.documentElement.att ributes
document.write(", which contains: " & x.value & "<br>" & "<br>")
//next
next
document.write("Traversing the node tree now:" & "<br>" & "<br>")
for each y in xmlDoc.documentElement.chi ldNodes
document.write("<b>" & y.nodename & "</b>")
document.write(": ")
document.write(y.text)
document.write("<br>")
next
</script>
***********
My XML File:
***********
<?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <soapenv:Header>
<ns1:timeStamp soapenv:mustUnderstand="0" xsi:type="xsd:dateTime" xmlns:ns1="http://www.ngc.com/DTS/GEXTransaction">2004-09-02T17 :14:28.320 </ns1:time Stamp>
</soapenv:Header>
- <soapenv:Body>
- <DebxAckTransaction xmlns="http://www.ngc.com/DTS/DEBXTransaction">
- <HeaderInfo>
<DocumentName>DEBX Ack Transaction</DocumentName>
<DocumentType>VCH</Documen tType>
<TransactionType>824V</Tra nsactionTy pe>
<TANUM>0NTHZK</TANUM>
<TransactionID>0NTHZK002</ Transactio nID>
<TravelerSSN />
<InvoiceNumber>0NTHZK002</ InvoiceNum ber>
<DOVNumber />
<ResponseStatus>REJECT</Re sponseStat us>
<ResponseStatusDate>2004-0 9-01</Resp onseStatus Date>
<AdminEmailAddress>DCD0038 01</AdminE mailAddres s>
<TransactionDate>2004-09-0 2</Transac tionDate>
<TransactionTime>17:14:28< /Transacti onTime>
</HeaderInfo>
- <Remarks>
<DadsTransactionID>0NTHZK0 02</DadsTr ansactionI D>
<ReferenceNumber>042460010 1</Referen ceNumber>
<CodeErrorTitle>Disbursing (DCD-GAFS) Error Code</CodeErrorTitle>
<CodeErrorDetails>102</Cod eErrorDeta ils>
<ErrorDescription>Duplicat e Record</ErrorDescription>
<LineIDError>00</LineIDErr or>
<TRNError>0NTHZK</TRNError >
<FillerErrorTitle />
<FillerErrorDetails />
</Remarks>
</DebxAckTransaction>
</soapenv:Body>
</soapenv:Envelope>
Thanks for any help!
ptslv
Can anyone show me how to get all the Elements? Each file is one record. Here is my code and file:
Code to see what I have:
<script type="text/vbscript">
set xmlDoc=CreateObject("Micro
xmlDoc.async="false"
xmlDoc.load("ATT169185.xml
set elem=xmlDoc.getElementsByT
for i = 1 to elem.length
document.write("Remarks Elements are: " & elem.item(i-1).text & "<br>" & "<br>" )
next
for each x in xmlDoc.documentElement.att
document.write("Attribute is: " & x.name )
//for each y in xmlDoc.documentElement.att
document.write(", which contains: " & x.value & "<br>" & "<br>")
//next
next
document.write("Traversing
for each y in xmlDoc.documentElement.chi
document.write("<b>" & y.nodename & "</b>")
document.write(": ")
document.write(y.text)
document.write("<br>")
next
</script>
***********
My XML File:
***********
<?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <soapenv:Header>
<ns1:timeStamp soapenv:mustUnderstand="0"
</soapenv:Header>
- <soapenv:Body>
- <DebxAckTransaction xmlns="http://www.ngc.com/DTS/DEBXTransaction">
- <HeaderInfo>
<DocumentName>DEBX Ack Transaction</DocumentName>
<DocumentType>VCH</Documen
<TransactionType>824V</Tra
<TANUM>0NTHZK</TANUM>
<TransactionID>0NTHZK002</
<TravelerSSN />
<InvoiceNumber>0NTHZK002</
<DOVNumber />
<ResponseStatus>REJECT</Re
<ResponseStatusDate>2004-0
<AdminEmailAddress>DCD0038
<TransactionDate>2004-09-0
<TransactionTime>17:14:28<
</HeaderInfo>
- <Remarks>
<DadsTransactionID>0NTHZK0
<ReferenceNumber>042460010
<CodeErrorTitle>Disbursing
<CodeErrorDetails>102</Cod
<ErrorDescription>Duplicat
<LineIDError>00</LineIDErr
<TRNError>0NTHZK</TRNError
<FillerErrorTitle />
<FillerErrorDetails />
</Remarks>
</DebxAckTransaction>
</soapenv:Body>
</soapenv:Envelope>
Thanks for any help!
ptslv
ASKER
David -
That is what I've been trying to do all morning! Why are all the elements being seen now when they weren't before?
Can you show me how to :
1. Check to see if an element exixts
2. If the element exists, place into a field
Such as:
<cfif xmlDoc.documentElement.chi ldNodes(0) .nodeName eq "TransactionType">
TransactionType.innerText= xmlDoc.get ElementsBy TagName("T ransaction Type").ite m(0).text;
</cfif>
#2 gives me a error:
Just in time compilation error
Invalid parser construct found on line 18 at position 43. ColdFusion was looking at the following text:
.
Invalid expression format. The usual cause is an error in the expression structure.
The last successfully parsed CFML construct was a CFIF tag occupying document position (18:1) to (18:5).
ptslv
That is what I've been trying to do all morning! Why are all the elements being seen now when they weren't before?
Can you show me how to :
1. Check to see if an element exixts
2. If the element exists, place into a field
Such as:
<cfif xmlDoc.documentElement.chi
TransactionType.innerText=
</cfif>
#2 gives me a error:
Just in time compilation error
Invalid parser construct found on line 18 at position 43. ColdFusion was looking at the following text:
.
Invalid expression format. The usual cause is an error in the expression structure.
The last successfully parsed CFML construct was a CFIF tag occupying document position (18:1) to (18:5).
ptslv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help, David.
As for the levels of childNodes, how can you tell, just by looking at the xml, how many node levels you have? I am just learning XML on the fly for this project I have. I need and appreciate all the help I can get! Thanks again!
ptslv
As for the levels of childNodes, how can you tell, just by looking at the xml, how many node levels you have? I am just learning XML on the fly for this project I have. I need and appreciate all the help I can get! Thanks again!
ptslv
Open your XML in Internet Explorer, and you will see the indentation of the levels :
Level1 : soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Level 2 : <soapenv:Header>
Other Level 2 : <soapenv:Body>
Level 3 : <DebxAckTransaction xmlns="http://www.ngc.com/DTS/DEBXTransaction">
Level 4 : <HeaderInfo>
Other Level 4 : <Remarks>
If you include the last level items like <DocumentName>DEBX Ack Transaction</DocumentName> ), that gives us 5 levels of nesting.
Level1 : soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Level 2 : <soapenv:Header>
Other Level 2 : <soapenv:Body>
Level 3 : <DebxAckTransaction xmlns="http://www.ngc.com/DTS/DEBXTransaction">
Level 4 : <HeaderInfo>
Other Level 4 : <Remarks>
If you include the last level items like <DocumentName>DEBX Ack Transaction</DocumentName>
ASKER
OK. Thanks, David. Appreciate the help!
ptslv
ptslv
<script type="text/vbscript">
'ADDED THIS HERE :
sub processnode(nodes)
for each y in nodes
document.write("<b>" & y.nodename & "</b>")
document.write(": ")
document.write(y.text)
document.write("<br>")
if y.ChildNodes.length>0 then processnode y.ChildNodes
next
end sub
'TO HERE !
set xmlDoc=CreateObject("Micro
xmlDoc.async="false"
xmlDoc.load("c:\temp\xml.x
set elem=xmlDoc.getElementsByT
for i = 1 to elem.length
document.write("Remarks Elements are: " & elem.item(i-1).text & "<br>" & "<br>" )
next
for each x in xmlDoc.documentElement.att
document.write("Attribute is: " & x.name )
//for each y in xmlDoc.documentElement.att
document.write(", which contains: " & x.value & "<br>" & "<br>")
//next
next
document.write("Traversing
'ADDED THIS LINE HERE :
processnode xmlDoc.documentElement.Chi
' REMOVED THESE LINES HERE
'for each y in xmlDoc.documentElement.chi
' document.write("<b>" & y.nodename & "</b>")
' document.write(": ")
' document.write(y.text)
' document.write("<br>")
'next
</script>
Hope it makes it !
David