Skip to main content
Inspiring
December 28, 2015
Answered

XML parsing display question

  • December 28, 2015
  • 1 reply
  • 596 views

I'm clearly not understanding how to parse my XML file.  I can get the first "child" but I don't know how to get children after that.

To get the league name I use the below code which was pulled from a cffile which retrieved the XML doc and that works fine:

<cfdump var="#mydoc#">

#mydoc.league.xmlattributes.name# = NBA

In the below, what would be the code to get the "home" team "name"?

Cheers!

My XML:

xml document [short version]
league
XmlText 
XmlAttributes
struct
alias NBA
id 4353138d-4c22-4396-95d8-5f587d2df25c
name NBA
xmlns
daily-schedule
XmlText 
XmlAttributes
struct
date 2015-12-25
games
XmlText  
game
XmlText  
XmlAttributes
struct
away_team 583ecc9a-fb46-11e1-82cb-f4ce4684ea4c
coverage full
home_team 583ecea6-fb46-11e1-82cb-f4ce4684ea4c
id b55c5579-950b-4726-8d36-6467f6caa772
scheduled 2015-12-25T17:00:00+00:00
status scheduled
venue
XmlText
XmlAttributes
struct
address 601 Biscayne Blvd.
capacity 19600
city Miami
country USA
id b67d5f09-28b2-5bc6-9097-af312007d2f4
name American Airlines Arena
state FL
zip 33132
home
XmlText
XmlAttributes
struct
alias MIA
id 583ecea6-fb46-11e1-82cb-f4ce4684ea4c
name Miami Heat
    This topic has been closed for replies.
    Correct answer BKBK

    The dash may have something to do with it. As an alternative, use the associative-array style:

    mydoc.league["daily-schedule"].games.game.home.xmlattributes.name

    In any case, keep to the XML best practice when naming your elements.

    1 reply

    BKBK
    Community Expert
    Community Expert
    December 30, 2015

    mydoc.league.daily-schedule.games.game.home.xmlattributes.name

    should have value

    'Miami Heat'

    BACFLAuthor
    Inspiring
    December 31, 2015

    I get the following error:

    Element LEAGUE.DAILY is undefined in MYDOC.  <br>The error occurred on line 33.

    Do you think the dash in daily-schedule is the issue?

    Thanks!

    B.

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    December 31, 2015

    The dash may have something to do with it. As an alternative, use the associative-array style:

    mydoc.league["daily-schedule"].games.game.home.xmlattributes.name

    In any case, keep to the XML best practice when naming your elements.