Skip to main content
February 12, 2008
Answered

Parsing a simple XML file

  • February 12, 2008
  • 2 replies
  • 945 views
Hello,

In the XML shown below, I want to get the value of the ID element that is nested under the BOX element.

The ColdFusion code I have in my sample outputs the xmltext of the RICHTEXT element.

What change would I make to output the value of the ID (such as Text 1) followed by the output of the RICHTEXT element?

I would like it to be something like
Text 1 : Sweet Wines
Text 2 : Simpy Joe's Vineyard

I really don't need to worry about any of the other elements or attributes. Those are the only ones I need. Any suggestions?

Best regards,
Kevin
    This topic has been closed for replies.
    Correct answer JohnEric
    Good morning,

    Thank you very much for your example. I think that will work nicely.

    Best regards,
    Kevin


    The following seems to do what you want.

    2 replies

    BKBK
    Community Expert
    Community Expert
    February 12, 2008
    Just use associated array notation to pluck out the XML data.

    February 13, 2008
    Hello,

    Thanks for your replies. They are very much appreciated.

    I have already been looking at XMLSearch and Xpath. I use XMLSearch in the code shown above.

    I tried the code provided by BKBK and got the same error I had gotten in one of my earlier attempts.

    (see below for the error)

    It is complaining that the element TEXT is part of the XMLNodelist. I was figuring that I must have been way off base so I tried outputting the code in other ways.

    Even if the example had worked as intended, it wouldn't actually have been what I was looking for. I can output the value of the RICHTEXT attribute using the code at the top of the page.

    The problem is outputting the value of the NAME attribute of ID under the BOX element. It isn't always in order, so I can just put the word 'Text' followed by the index value. The path to ID is
    PROJECT.LAYOUT.SPREAD.BOX.ID
    ID then has a NAME value which in most cases will be something like
    Text 1
    Text 3
    Text 2

    In some cases it will be something else entirely. As such, I need to output the value of the NAME attribute (or is it called a named node value? I am still learning the XML terminlogy) of the ID.

    I tried #arBOX .xmlvalue# But that doesn't seem to be the right syntax either.

    The previous line had part of the text stripped out on post. I am adding some spaced between the characters to see if I can get it to post the string. #arBOX [ i ] .xmlvalue#
    Thanks for any help you can provide.

    Best regards,
    Kevin
    Inspiring
    February 12, 2008