cottyengland
asked on
Convert XML to Query Object
How do I convert the XML below to a Clodfusion query object?
<loopN1>
<Name>
<entityIdentifierCode>BY</ entityIden tifierCode >
<name>DEFENSE SUPPLY CENTER COLUMBUS</name>
<identificationCodeQualifi er>10</ide ntificatio nCodeQuali fier>
<identificationCode>SPM7M1 </identifi cationCode >
</Name>
<AdditionalNameInformation >
<name>MARITIME SUPPLY CHAIN</name>
</AdditionalNameInformatio n>
<AddressInformation>
<addressInformation>PO BOX 3990</addressInformation>
</AddressInformation>
<GeographicLocation>
<cityName>COLUMBUS</cityNa me>
<stateOrProvinceCode>OH</s tateOrProv inceCode>
<postalCode>432183990</pos talCode>
</GeographicLocation>
<AdministrativeCommunicati onsContact >
<contactFunctionCode>BD</c ontactFunc tionCode>
<name>Searfoss</name>
<communicationNumberQualif ier>TE</co mmunicatio nNumberQua lifier>
<communicationNumber>61469 22049</com munication Number>
</AdministrativeCommunicat ionsContac t>
</loopN1>
<loopN1>
<Name>
<entityIdentifierCode>BY</
<name>DEFENSE SUPPLY CENTER COLUMBUS</name>
<identificationCodeQualifi
<identificationCode>SPM7M1
</Name>
<AdditionalNameInformation
<name>MARITIME SUPPLY CHAIN</name>
</AdditionalNameInformatio
<AddressInformation>
<addressInformation>PO BOX 3990</addressInformation>
</AddressInformation>
<GeographicLocation>
<cityName>COLUMBUS</cityNa
<stateOrProvinceCode>OH</s
<postalCode>432183990</pos
</GeographicLocation>
<AdministrativeCommunicati
<contactFunctionCode>BD</c
<name>Searfoss</name>
<communicationNumberQualif
<communicationNumber>61469
</AdministrativeCommunicat
</loopN1>
ASKER
Yes I do...
I need sample code related to this structure... I have many other structures to convert so this will be my template.
Thank you for you help.
I need sample code related to this structure... I have many other structures to convert so this will be my template.
Thank you for you help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much... this is perfect. I have one additional question that I did not realize until I saw your code work
If I have multiple instances of this node on in the xml how would I loop throuth them? For example build the query with mode than 1 column?
I will be awarding the points now.
If I have multiple instances of this node on in the xml how would I loop throuth them? For example build the query with mode than 1 column?
I will be awarding the points now.
You can use XmlChildren like in the livedocs example.
http://livedocs.adobe.com/coldfusion/7/htmldocs/00001518.htm
All they're doing is parsing the xml string and using ArrayLen() to count the number of nodes.
<cfset xmlDoc = XMLParse(theXMLString, false)>
<cfset numberOfNodes = arrayLen(xmlDoc.yourElemen tName.XmlC hildren)>
Then using cfloop to add one row to the queryfor each node, and using the array index to extract the values for each node.
http://livedocs.adobe.com/coldfusion/7/htmldocs/00001518.htm
All they're doing is parsing the xml string and using ArrayLen() to count the number of nodes.
<cfset xmlDoc = XMLParse(theXMLString, false)>
<cfset numberOfNodes = arrayLen(xmlDoc.yourElemen
Then using cfloop to add one row to the queryfor each node, and using the array index to extract the values for each node.
ASKER
I am going to open up a new question...
Okay. But you'll find its pretty easy :)
ASKER
nothing ever seems to be easy for me ;)
> nothing ever seems to be easy for me ;)
Yeah well, its always easier when it someone else's code. ie something you haven't been staring/cursing at for 2 hours ;-)
Yeah well, its always easier when it someone else's code. ie something you haven't been staring/cursing at for 2 hours ;-)
http://livedocs.adobe.com/coldfusion/7/htmldocs/00001518.htm
But do you really need to convert it to a query? You can extract the values by just parsing xml string. For example
<cfset xmlDoc = XMLParse(yourXMLString)>
<cfoutput>
#xmlDoc.loopN1.Name.Name.X
#xmlDoc.loopN1.Name.identi
</cfoutput>