coldfusioncoldfusion-9coldfusion-8coldbox

Processing of xml data inside coldfusion


After processing data I can able to set the xml value

<cfoutput>#xmlResults#</cfoutput>

output example :

<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="889923"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="shiporder.xsd">
    <orderperson>John Smith</orderperson>
    <shipto>
        <name>Ola Nordmann</name>
        <address>Langgt 23</address>
        <city>4000 Stavanger</city>
        <country>Norway</country>
    </shipto>
    <item>
        <title>Empire Burlesque</title>
        <note>Special Edition</note>
        <quantity>1</quantity>
        <price>10.90</price>
    </item>
    <item>
        <title>Hide your heart</title>
        <quantity>1</quantity>
        <price>9.90</price>
    </item>
</shiporder>

How I can use the details separately using coldfusion ?(I want to use the title value inside my application.)


Solution

  • <cfsavecontent variable="variable.xmlResults">
    <?xml version="1.0" encoding="UTF-8"?>
    <shiporder orderid="889923"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="shiporder.xsd">
        <orderperson>John Smith</orderperson>
        <shipto>
            <name>Ola Nordmann</name>
            <address>Langgt 23</address>
            <city>4000 Stavanger</city>
            <country>Norway</country>
        </shipto>
        <item>
            <title>Empire Burlesque</title>
            <note>Special Edition</note>
            <quantity>1</quantity>
            <price>10.90</price>
        </item>
        <item>
            <title>Hide your heart</title>
            <quantity>1</quantity>
            <price>9.90</price>
        </item>
    </shiporder>
    </cfsavecontent>
    <cfset variables.myXmlArray = xmlparse(trim(variable.xmlResults))>
    
    <cfset variables.responseNodesItem = XMLSearch(variables.myXmlArray,"//*[ local-name() = 'item' ]") />
    <cfset variables.title = variables.responseNodesItem[1].title["XmlText"]>	
    <cfdump var="#variables.myXmlArray#">
    <cfdump var="#variables.responseNodesItem#">
    <cfdump var="#variables.title#">
    <cfabort>