A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: HOW TO: line breaks in XML strings

  1. #1

    Angry

    when sending a string in XML, how do you get a line break?

    <text content="garble garble garble garblegarble garble garble garble garble garble garble garble garble garble garble garble garble garble garble garble"

    i can't make the tag itself the text... needs to be a string. i tried \r\n but that just comes out explicitly

    maybe this has something to do with it? :

    <?xml version="1.0" encoding="iso-8859-1" ?> (at the top)

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    What about having the line space explicitly in the XML file (eg press enter in Notepad to put the linespace in the file.

    You might also want to check if you have xml.ignoreWhite set.

    Thanks

    Luke

  3. #3
    i tried putting hitting enter within my string but that causes the XML not to load completely empty in the flash movie... that seems strange

    this xml.ignoreWhite command.. where do i place it? i assume i set xml.ignoreWhite in the Flash movie rather than the external xml file itself? since i'm using an external file perhaps i need a different notation?

  4. #4
    think i found what you're talkin about. i'm usin someone else's menu code here and i think that's what's creating problems.

    i load an external actionscript (.as) file and at the top it has this:

    XML.prototype.ignoreWhite = true;
    serverData = new XML();
    serverData.load(serverfile);
    n=100;

    if i change that ignoreWhite to false, the XML loads blank in my movie... does that mean somewhere in this code the author depends on the parser ignoring white space? can't seem to find any spots where that should create such a problem... grr

  5. #5
    New Title:
    Join Date
    Jul 2002
    Posts
    87
    When you want to include "raw text" in XML, it should almost always be CDATA (character data) which you can access with nodeValue. Character data is also where people like to put their nicely tabbed formatting, which is why ignoring whitespace becomes a critical issue.

    This is the bad way to encode character data - and will in fact not work with the Flash XML reader.

    Code:
    &lt;MESSAGE ID="4" SUBJECT="Working with XML" TEXT="I'm having a problem with XML.
    
    Can anybody help me?"/>
    This is the good way:

    Code:
    &lt;MESSAGE ID="4">&lt;SUBJECT>Working with XML&lt;/SUBJECT>
      &lt;BODY>I'm having a problem with XML.
    
    Can anybody help me?"&lt;/BODY>
    &lt;/MESSAGE>
    - but it requires much more complicated actionscript to get everything out:

    Code:
    // node is out MESSAGE tag
    var ID = node.attributes.id;
    var n = node.firstChild;
    while (n) {
      if (n.nodeName == "SUBJECT") {
        SUBJECT = n.firstChild.nodeValue;
      }
      if (n.nodeName == "BODY") {
        BODY = n.firstChild.nodeValue;
      }
      n = n.nextSibling;
    }
    Warning: even this is bad code, but it should suffice.

    Even with ignoreWhite set to true, the line breaks inside the BODY will show up... only leading and trailing whitespace are actually ignored by this directive.

  6. #6
    my situation was too complicated to plug in your code... but i finally found something analogous.... thx for making me consider nodeValue... that's definitely more dependable than the attribute system...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center