0

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>myemail@email.com</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:

  • player -> id
  • player -> nucleusID
  • player -> email
  • player -> preferredPersona -> id
  • player -> preferredPersona -> gamertag
  • player -> preferredPersona -> platform

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

fareed
  • 3,034
  • 6
  • 37
  • 65
CPB07
  • 679
  • 3
  • 13
  • 23

2 Answers2

1

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>myemail@email.com</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#">
Community
  • 1
  • 1
duncan
  • 31,401
  • 13
  • 78
  • 99
0

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.

duncan
  • 31,401
  • 13
  • 78
  • 99
Adam Cameron
  • 29,677
  • 4
  • 37
  • 78