2 Replies Latest reply on Mar 12, 2008 5:42 AM by randomstew

    Flattening XML text

    randomstew
      Given the following XML snippet:
      <adjustments>
      <adjustment>Add <bonus>10</bonus> points if completion time less than <completionTime>60</completionTime> seconds.</adjustment>
      <adjustment>Add <bonus>15</bonus> points if opponent rank is higher than level <opponentRank>5</opponentRank>.</adjustment>
      <adjustment>Add <bonus>5</bonus> points if the temperature is above <temperature>75</temperature> degrees Fahrenheit.
      </adjustments>

      How would I output each adjustment as text like the following? In other words, how can I "flatten" the XML text?
      Add 10 points if completion time less than 60 seconds.
      Add 15 points if opponent rank is higher than level 5.
      Add 5 points if the temperature is above 75 degrees Fahrenheit.

      Thanks in advance for your help.
        • 1. Re: Flattening XML text
          ntsiii Level 3
          Try:
          adjustments.text();
          Tracy
          • 2. Re: Flattening XML text
            randomstew Level 1
            adjustments.text() returns an empty string, of course. And something like adjustments.adjustment[0].text() returns just:
            Add points if completion time less than seconds.
            It doesn't have the text of of the child nodes.

            What I need is the text of a parent node and all of the child nodes in one string. Even if I iterate over the parent and all the descendants, I don't see any way of properly placing the text from the children into the text from the parent.

            Any other ideas?