Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Urgent - need help identifying XML nodes and Elements using ColdFusion 4.5

Posted on 2004-09-30
6
Medium Priority
?
565 Views
Last Modified: 2013-12-16
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("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("ATT169185.xml")

set elem=xmlDoc.getElementsByTagName("Remarks")
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.attributes
  document.write("Attribute is: " & x.name )
  //for each y in xmlDoc.documentElement.attributes
  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.childNodes
  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:timeStamp>
  </soapenv:Header>
- <soapenv:Body>
- <DebxAckTransaction xmlns="http://www.ngc.com/DTS/DEBXTransaction">
- <HeaderInfo>
  <DocumentName>DEBX Ack Transaction</DocumentName>
  <DocumentType>VCH</DocumentType>
  <TransactionType>824V</TransactionType>
  <TANUM>0NTHZK</TANUM>
  <TransactionID>0NTHZK002</TransactionID>
  <TravelerSSN />
  <InvoiceNumber>0NTHZK002</InvoiceNumber>
  <DOVNumber />
  <ResponseStatus>REJECT</ResponseStatus>
  <ResponseStatusDate>2004-09-01</ResponseStatusDate>
  <AdminEmailAddress>DCD003801</AdminEmailAddress>
  <TransactionDate>2004-09-02</TransactionDate>
  <TransactionTime>17:14:28</TransactionTime>
  </HeaderInfo>
- <Remarks>
  <DadsTransactionID>0NTHZK002</DadsTransactionID>
  <ReferenceNumber>0424600101</ReferenceNumber>
  <CodeErrorTitle>Disbursing (DCD-GAFS) Error Code</CodeErrorTitle>
  <CodeErrorDetails>102</CodeErrorDetails>
  <ErrorDescription>Duplicate Record</ErrorDescription>
  <LineIDError>00</LineIDError>
  <TRNError>0NTHZK</TRNError>
  <FillerErrorTitle />
  <FillerErrorDetails />
  </Remarks>
  </DebxAckTransaction>
  </soapenv:Body>
  </soapenv:Envelope>


Thanks for any help!

ptslv
0
Comment
Question by:ptslv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:david_barker
ID: 12191354
How about adding a bit of recursion into your code with the function processnode() ?

<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("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("c:\temp\xml.xml")

set elem=xmlDoc.getElementsByTagName("Remarks")
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.attributes
  document.write("Attribute is: " & x.name )
  //for each y in xmlDoc.documentElement.attributes
  document.write(", which contains: " & x.value & "<br>" & "<br>")
//next
next

document.write("Traversing the node tree now:" & "<br>" & "<br>")

'ADDED THIS LINE HERE :
processnode xmlDoc.documentElement.ChildNodes

' REMOVED THESE LINES HERE
'for each y in xmlDoc.documentElement.childNodes
'  document.write("<b>" & y.nodename & "</b>")
'  document.write(": ")
'  document.write(y.text)
'  document.write("<br>")
'next

</script>

Hope it makes it !

David
0
 

Author Comment

by:ptslv
ID: 12191648
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.childNodes(0).nodeName eq "TransactionType">
      TransactionType.innerText=xmlDoc.getElementsByTagName("TransactionType").item(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
0
 
LVL 6

Accepted Solution

by:
david_barker earned 1200 total points
ID: 12191760
>>Why are all the elements being seen now when they weren't before?
Because you were parsing the first level nodes, and not the children of each node.
To do so, I used recursion, that is I call the processnode() function again from each node which has children (and so on for each level).

For the new questions, I don't know anything about ColdFusion.

Hope you will still consider my answer as valid for the initial question !

David

0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 

Author Comment

by:ptslv
ID: 12192035
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
0
 
LVL 6

Expert Comment

by:david_barker
ID: 12192112
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.


0
 

Author Comment

by:ptslv
ID: 12192307
OK.  Thanks, David.  Appreciate the help!

ptslv
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question