Parse XML using coldfuison

I am trying to parse XML returned using Coldfusion but can not access an element that I need .

<cfset mydoc = XmlParse(result.returnedXML)>

This gives a structure that looks like attached:

I am trying to access the filed called cardTypeFile
LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gdemariaCommented:
Just go bit by bit down the tree ...

Try <cfdump var="#mydoc#">

It looks like the first container woudl be  
  mydoc['getTransactionDetailsResponse']

Then you can try to dump that to see what is next...

  <cfdump var="# mydoc['getTransactionDetailsResponse']#">

The next element looks like  

  mydoc['getTransactionDetailsResponse']['transaction']

Then you can cfdump that...

The end result looks like it is located at....

  mydoc['getTransactionDetailsResponse']['transaction']['payment']['creditCard']['cardNumber']
erikTsomikSystem Architect, CF programmer Author Commented:
I tried  <cfdump var="#mydoc['getTransactionDetailsResponse']['transaction']#"> but getting an error message

Element transaction is undefined in a Java object of type class coldfusion.xml.XmlNodeList.
erikTsomikSystem Architect, CF programmer Author Commented:
if dump <cfdump var="#mydoc.XMLRoot#">

I get the following. THe file is attachedFile
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

erikTsomikSystem Architect, CF programmer Author Commented:
if I do <cfdump var="#mydoc.XMLRoot.xmlChildren#"> I get the following and then I am can not do anymore keep getting error FIle message
gdemariaCommented:
The next element is a number, see the green first column is an array 1, 2,...

So now dump...
#mydoc.XMLRoot.xmlChildren[1]#

and see what you have to grab next..

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
erikTsomikSystem Architect, CF programmer Author Commented:
when I access first element I am getting the response, but my desired result in the second array position and if I ran
#mydoc.XMLRoot.xmlChildren[2]# getting an error message.

"'' The specific sequence of files included or processed
gdemariaCommented:
What do you mean by "ran" ?   If you do a cfdump on this you should see the next level, no?
<cfdump var="#mydoc.XMLRoot.xmlChildren[2]#">
erikTsomikSystem Architect, CF programmer Author Commented:
Got this far <cfdump var="#mydoc.XMLRoot.xmlChildren[2].xmlChildren[15].xmlChildren#">

And the array looks like this . Almost there Now got stock again
File
gdemariaCommented:
Its another array, see the green column, the next element is a [1]
erikTsomikSystem Architect, CF programmer Author Commented:
i have noticed some inconsistency in the return .

Can I do the search . If i do <cfdump var="#mydoc.XMLRoot.xmlChildren[2].xmlChildren#">

it goves me an array of n number of elelments. can i do the search to find array element with the name **payment**?
Pravin AsarPrincipal Systems EngineerCommented:
You can search for the particular element by XmlSearch function.

e.g.

<cfset myElement=XmlSearch(xmlObject,"//cardType")>

Here is simple example, which parses XML data.

<cfset xmlFile =
'<?xml version="1.0" encoding="utf-8" ?>
<ResponseArray xmlns="urn:mdWebServiceAddress" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Version>2.0.34</Version>
  <TransmissionReference />
  <Results />
  <TotalRecords>1</TotalRecords>
<Record>
  <RecordID>1</RecordID>
  <Results>AS01,AS12,AS15</Results>
<Address>
  <Company>California Hospital Assocation</Company>
<Urbanization>
  <Name />
  </Urbanization>
  <Address1>1215 K St</Address1>
  <Address2 />
  <Suite>Ste 900</Suite>
  <PrivateMailBox />
<City>
  <Name>Sacramento</Name>
  <Abbreviation>Sacramento</Abbreviation>
  </City>
<State>
  <Name>California</Name>
  <Abbreviation>CA</Abbreviation>
  </State>
  <Zip>95814</Zip>
  <Plus4>3947</Plus4>
  <CarrierRoute>C001</CarrierRoute>
  <DeliveryPointCode>25</DeliveryPointCode>
  <DeliveryPointCheckDigit>3</DeliveryPointCheckDigit>
<Type>
<Address>
  <Code>H</Code>
  <Description>Highrise</Description>
  </Address>
<Zip>
  <Code />
  <Description>Standard ZIP Code</Description>
  </Zip>
  </Type>
<Country>
  <Abbreviation>US</Abbreviation>
  <Name>United States of America</Name>
  </Country>
  <AddressKey>95814394725</AddressKey>
<Parsed>
  <StreetName>K</StreetName>
  <AddressRange>1215</AddressRange>
  <Suffix>St</Suffix>
<Direction>
  <Post />
  <Pre />
  </Direction>
<Suite>
  <Range>900</Range>
  <Name>Ste</Name>
  </Suite>
<PrivateMailbox>
  <Name />
  <Range />
  </PrivateMailbox>
  <Garbage />
  </Parsed>
  </Address>
  </Record>
  </ResponseArray>'>
 

<cfset rssXml = xmlParse(xmlFile)>

<cffunction name="ReadXml" returntype="Any">
            <cfargument name="curNode" type="xml" />
            <cfsavecontent variable="readData">
                  <cfoutput>
                        <p>Type: #curNode.XmlType#</p>
                        <p>Name: #curNode.XmlName#</p>
                        <p>Value: #curNode.XmlText#</p>
                        <cfif ArrayLen(curNode.XmlChildren) gt 0>
                                    <p>No of Childern: #ArrayLen(curNode.XmlChildren)#</p>
                                    <cfloop index="ix" from="1" to="#ArrayLen(curNode.XmlChildren)#">
                                    <p>#ReadXml(curNode.XmlChildren[ix])#</p>
                                    </cfloop>
                        <cfelse>
                              <p>No ChildNodes</p>
                        </cfif>
                  </cfoutput>
            </cfsavecontent>
            <cfreturn #readData#/>
</cffunction>


<!--- Root Element --->
<cfset rootElm = rssXMl.xmlRoot/>
<!--- Element Data --->
<cfoutput>#ReadXml(rootElm)#</cfoutput>
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.