Skip to main content
Inspiring
Dec 28, 2015 2:11 AM UTC
Answered

XML parsing display question

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 is closed to new replies. Start a new post to keep the conversation going.
    BKBK
    BKBKCorrect answer
    Community Expert
    Dec 31, 2015 5:31 AM UTC

    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.

    3 replies

    BKBK
    Community Expert
    Community Expert
    Dec 30, 2015 8:20 AM UTC

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

    should have value

    'Miami Heat'

    Translate
    BACFLAuthor
    Inspiring
    Dec 31, 2015 2:47 AM UTC

    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.

    Translate
    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    Dec 31, 2015 5:31 AM UTC

    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.

    Translate