Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: XML line break

  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Thanked 0 Times in 0 Posts

    XML line break


    I have a new problem with my XML parsed to AS3 textfield. Seems like there is a double spacing line break when displayed on the Flash AS3 screen from the XML file. below is my code in the XML, i did try <br /> but to now avail since the <br /> tag will display itself on the textfield.

    XML code:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <page pTitle="What Causes Back Pain?">
    Poor posture
    Strenuous activities at home or at work
    Lifting, carrying, pushing or pulling incorrectly
    Standing or bending down for long periods
    Twisting or bending awkwardly
    Sitting in a hunched position for long periods without taking a break
    Muscle tension and or over-stretching

    And this my AS3 Code:
    var myXML:XML = new XML();
    var XMLURL:String = "xxxx.xml";
    var myXMLURL:URLRequest = new URLRequest(XMLURL);
    var myLoader:URLLoader = new URLLoader(myXMLURL);
    myLoader.addEventListener("complete", xmlLoaded);

    function xmlLoaded(event:Event):void
    myXML = XML(event.target.data);

    Any help would be much appreciated.



  2. #2
    New Coder
    Join Date
    Aug 2012
    Thanked 3 Times in 3 Posts
    Hi bryanbelle

    I believe I may have joined the site the same day as yourself and therefore I should probably leave this part to the moderators, however I just thought I'd let you know that you will probably recieve considerably more assistance if you follow the forum rules as found here:


    I am making this comment in relation to code sequences being inserted into code tags for easy viewing by the members of the forum.

    As for your problem, I have to say that I have not done any work with XML working with Flash, however the XML "code" that you have posted seems incomplete to me - ie: what XML tags are you using for your child elements?

    <line>Poor posture</line>
    <line>Strenuous activities at home or at work</line>
    <line>Lifting, carrying, pushing or pulling incorrectly</line>
    <line>Standing or bending down for long periods</line>
    <line>Twisting or bending awkwardly</line>
    <line>Sitting in a hunched position for long periods without taking a break</line>
    <line>Muscle tension and or over-stretching</line>
    I don't profess to be an expert on this matter as I have only recently learned XML myself, but it seems to me that as per your "code" you have posted, if this is how it actually appears then it is my opinion that your document is not well formed in the sense that your child elements each need an opening and closing line attribute.

    "Each XML element MUST have an opening and closing tag and each element MUST be opened and closed in the correct order for the document to be well formed"

    Maybe this is your problem?

    I had the same problem as you at one stage whilst writing a document meaning that line breaks are NOT the answer as you are already aware.

    Hope I have used the correct terminlogy here and provided some reasonable advice which may assist in solving your problem.

    Other respondees: I have no problem with being corrected in regard to any of my statements which prove to be false and/ or the terminology used. I want to learn also.

  3. #3
    Senior Coder
    Join Date
    Apr 2011
    London, England
    Thanked 354 Times in 353 Posts
    I'm no expert myself, but understand that XML line-breaks are preserved and could be viewed in the resultant HTML using View Source.

    In JS you could use the function nl2br to re-establish the breaks and, hopefully, there is an equivalent function in AS:

    function nl2br(s) { return s.split(/\r?\n/).join("<br>"); }
    I apologise if this doesn't prove helpful
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  4. #4
    New Coder
    Join Date
    Aug 2012
    Thanked 3 Times in 3 Posts
    Well that's way more helpful than my reply I believe! Very handy function in PHP and JS - Actionscript equivalent - mmm- seems like a question I'd come up with - you know the ones I mean - answer the first question only to find another question needs answering and then loop - lol - back to Google

  5. #5
    New to the CF scene
    Join Date
    Aug 2012
    Thanked 0 Times in 0 Posts
    If you need more line breaks between elements, I don't believe it's possible to add them through CSS (and using before or after pseudo elements isn't the answer, since it would make it neither a) valid xml (without modifying the XML document), and b) compatible with IE). So if you do need more space, you will have to use margins and padding instead.
    read more here


Posting Permissions

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