CPB07
CPB07

Reputation: 699

CFHTTP Response - Set XML values in variables

I'm making a CFHTTP request which is returning the following XML in the fileContent:

<login>
    <success>1</success>
    <player>
        <id>123456</id>
        <nucleusId>28736389714</nucleusId>
        <email>[email protected]</email>
        <preferredPersona>
            <id>19842082</id>
            <gamertag>MyGamerTag1</gamertag>
            <platform>360</platform>
        </preferredPersona>
    </player>
</login> 

What I'm looking to do is declare ColdFusion variables for:

I've had a read around all morning but am still none the wiser on how I'd achieve this?

Upvotes: 0

Views: 1001

Answers (2)

Adam Cameron
Adam Cameron

Reputation: 29870

Over and above Duncan's answer, it seems you could probably step back, and get yourself up to speed understanding/using XML in ColdFusion before you look at any implementation stuff.

It's always best to read and understand the docs before trying to use some part of CFML's functionality.

Upvotes: 0

duncan
duncan

Reputation: 31912

So all you need to do is convert some XML to a coldfusion structure?

I'd probably just do it like

<cfsavecontent variable="myXML">
<login>
    <success>1</success>
    <player>
        <id>123456</id>
        <nucleusId>28736389714</nucleusId>
        <email>[email protected]</email>
        <preferredPersona>
            <id>19842082</id>
            <gamertag>MyGamerTag1</gamertag>
            <platform>360</platform>
        </preferredPersona>
    </player>
</login> 
</cfsavecontent>

<cfset myXML = XMLParse(myXML)>
<cfset stuPlayer = {}>
<cfset stuPlayer.ID = myXML.login.player.ID.XmlText>
<cfset stuPlayer.nucleusID = myXML.login.player.nucleusID.XmlText>
... etc
<cfdump var="#stuPlayer#">

Upvotes: 1

Related Questions