8 Replies Latest reply on May 12, 2006 12:59 PM by TimSymons

    Parsing HTML within Strings Sourced from and XML Entry

    ropeGun
      I am loading in a bunch of text (and other data) from an XML file into Dynamic Text Fields on my stage via an XML.load call. Below is one example of one entry of my XML file:

      <stillDescriptions>
      <text>Mack Trucks of North America came to us to help them create marketing materials for their MP7 Diesel Engine.
      </text>
      </stillDescriptions>

      I would like to be able to create HTML links within these strings between the <text> tags that I have in my XML file so that a user could click on the link that is inserted into the dynamic text field.

      I can't get this to work. If I place typical HTML tags within my XML-tagged strings, it does not get parsed as HTML. Like this, this doesn't work -- text string gets truncated after hitting the first HTML tag. Makes sense since it may be expecting XML tags instead of HTML tags?

      <stillDescriptions>
      <text>Mack Trucks of North America came to us to help them create marketing <b><a href = www.blah.blah>materials</a></b> for their MP7 Diesel Engine.
      </text>
      </stillDescriptions>

      Is there a trick to doing this, or is it not possible?

      Any info would be most appreciated.

      Thanks and good day,

      -john
        • 1. Re: Parsing HTML within Strings Sourced from and XML Entry
          Peter Lorent Level 2
          If you want to use html-tags you need to place the text in a CDATA section.
          • 2. Re: Parsing HTML within Strings Sourced from and XML Entry
            ropeGun Level 1
            I had already tried the following line in one of my child nodes, but it does not work.

            <text>Go to the <![CDATA[ <a href="/index.html">;top page</a> ]]>.</text>

            the result is the same as if I place html tags within the child node string, that the string gets truncated after it reaches the "<" sign at the beginning of the CDATA tag, or this shows up in my dynamic text field:

            ________
            Go to the
            ________
            I have ensured that my dynamic text field has the "Render Text as HTML" enabled (small button with "<>" on it), but to no avail.

            Any other thoughts?

            -john
            • 3. Re: Parsing HTML within Strings Sourced from and XML Entry
              Peter Lorent Level 2
              Are you using the htmlText property of the text field?
              • 4. Re: Parsing HTML within Strings Sourced from and XML Entry
                ropeGun Level 1
                Yes, if you mean if I have pressed that little button with the "<>" on it in the properties of the text field, yes. also, when I load the text string with actonscript (from an array), I use:

                this.stillImageContainer.stillImageDescription.stillImageDescriptionText. htmlText = stillsDesc i;

                The same problem persists -- everything that falls within the CDATA tags does not get read into my stillsDesc i variable.

                the (breviated) entry of my XML file that contains the link looks like this (<text> is the XML tag):

                <text>Go to the <![CDATA[ <a href="/index.html">;top page</a>]]>.</text>

                the string variable I am trying to load into my array in Flash is "Go to the top page." where "top page" is the hyperlink.

                On my way into work, I thought that maybe there needs to be some definition witin the header of my XML file that enables CDATA to work. The header I use now is:

                <?xml version="1.0" encoding="utf-8" standalone="yes"?>

                Which, I believe, is the standard. Do I need a later version?

                Going insane in the membrane, here.

                Thanks for the help thus far -- it is appreciated.

                -john
                • 5. Re: Parsing HTML within Strings Sourced from and XML Entry
                  yachts99-2vTvY1 Level 2
                  How about putting all of the html inside the CDATA, not just part of it?

                  • 6. Re: Parsing HTML within Strings Sourced from and XML Entry
                    ropeGun Level 1
                    SCHwwwinnnng!

                    That was it - sort of... It renders out correctly in my Dynamic Text Field, in any case, but with two strange things:

                    (1) the hotspot for the link is not only within the area taken by the underlined linked words, it appears to be the entire length of the hyperlinked words plus the area underneath it all the way to the bottom boundary of the dynamic text field.

                    (2) -- I will post this in a new thread -- the link works fine and dandy when tested within Flash. but, as soon as it is embedded in HTML and read in through a browswer, the link does nothing. I can click forever but, alas, my link does not open.

                    -john
                    • 7. Re: Parsing HTML within Strings Sourced from and XML Entry
                      dandan1138
                      you can also replace the < and > with &lt; and &gt;
                      flash will read this as the < or > signs and it will not affect your xml and you don't need the CDATA tags.
                      • 8. Re: Parsing HTML within Strings Sourced from and XML Entry
                        TimSymons Level 1
                        OK. I feel weird contradicting the other posters on here but you do not necessarily need to place your HMTL code inside the CDATA section to get them to work properly. I used to do that and then I found that if I defined a StyleSheet with starting XML tag then it was much simpler. For example:

                        CSS File:
                        text {
                        color: #000000;
                        display: inline;
                        font-family: Verdana;
                        font-size: 12px;
                        font-style: normal;
                        font-weight: normal;
                        kerning: true;
                        letter-spacing: 0;
                        margin-left: 0;
                        margin-right: 0;
                        text-align: left;
                        text-decoration: none;
                        text-indent: 0;
                        }

                        Then my XML file might look like this:
                        <?xml version="1.0" encoding="UTF-8"?>
                        <stillDescriptions>
                        <text>Mack Trucks of North America came to us to help them create marketing <b><a href ="www.blah.blah">materials</a></b> for their MP7 Diesel Engine.
                        </text>
                        </stillDescriptions>


                        Then in Flash I would read in both the XML and CSS files into appropriate variables and then assign them to my TextField. Assume my dynamic TextField is named: tf, that I read in the CSS file into a variable named "css" and the XML file into a variable named "myxml". Then I would use the following code:

                        tf.autoSize="left";
                        tf.wordWrap = true;
                        tf.multiline = true;
                        tf.embedFonts = true;
                        tf.html = true;
                        tf.styleSheet = css; // see help docs on reading in CSS from an external file.
                        tf.htmlText = myxml.firstChild.firstChild; // This will bring to the <text> tag in the above XML

                        This would then render as:

                        Mack Trucks of North America came to us to help them create marketing materials for their MP7 Diesel Engine.




                        Just thought I would throw this out to everyone.
                        Tim