We help IT Professionals succeed at work.

Coldfusion XML parsing question

roger v
roger v asked
on
I have an xml document being returned from a function call. I need to retrieve values from this xml object and populate a struct. Never done this before and having issues. I've attached a screenshot of the xml document.

From that xml doc I need to retrieve values like addrCity, addrLine1, addrStateAbrv etc and then create a struct called myStruct and set that like so:

myStruct.addrCity = addrCity
myStruct.addrLine1 = addrLine1

and so on...

How do I accomplish this?
thanks in advance,

roger
xmlCleanse.doc
Comment
Watch Question

Systems architect
Top Expert 2006
Commented:
Please do not post a phote of your XML but the text of your XML as file.

Author

Commented:
@Zvonko:

Attached the output file.
CleansedValues.txt

Author

Commented:
@Zvonko,

Here's another file that has just the xml output, thanks
CleansedValues2.txt
XML in coldfusion is referenced as a struct. You can use the function XMLparse() to turn the xml file into a xml document object and then save it to a variable. Then just use struct notation to reference.

You may not even need to create another additional struct to manually set the values, if the key names are the same, since it will already be in the format you want.

Here is the documentation for XMLparse:
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_t-z_23.html#139864
ZvonkoSystems architect
Top Expert 2006

Commented:
Here an example:


<cfset myStruct=StructNew() >

<cfset myStruct.addrCity = myXML.CustomerMatchResults.BeforeMatch.Customer.BaseCustomer.XmlAttributes.addrCity >
<cfset myStruct.addrLine1 = myXML.CustomerMatchResults.BeforeMatch.Customer.BaseCustomer.XmlAttributes.addrLine1 >
<cfset myStruct.addrStateAbrv = myXML.CustomerMatchResults.BeforeMatch.Customer.BaseCustomer.XmlAttributes.addrStateAbrv >


<cfdump var="#myStruct#" >

Author

Commented:
Thanks for the help!

roger
ZvonkoSystems architect
Top Expert 2006

Commented:
You are welcome.