A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: XML and HTML tag

  1. #1
    Member
    Join Date
    Jan 2003
    Posts
    85

    XML and HTML tag

    I've done this many times before - now I've worked on this for hours and I just can't figure out what's wrong this time.

    This is my AS:
    Code:
    myText.html = true;
    myText.autoSize = true;
    var mydata = new XML();
    mydata.ignoreWhite = true;
    mydata.load("kontakt.xml");
    mydata.onLoad = process;
    
    function process (success) {
    	if (success) {
    		
    		trace(mydata.firstChild);
    		myText.htmlText = mydata.firstChild;
    	} else {
    		trace("bad");
    	}
    }

    This is my XML:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <data><![CDATA[<img src='krak.jpg'>]]></data>
    The trace comes up with:
    Code:
    <data>&lt;img src=&apos;krak.jpg&apos;&gt;</data>
    ...but the output is just the HTML code:
    <img src='krak.jpg'>
    ..instead of showing the image. What's going on ?

  2. #2
    Member
    Join Date
    Jan 2003
    Posts
    85
    ...and why is the trace so weird ?




    ...and why can't I edit my post ??...this has been a bad day - really bad!

  3. #3
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    LOL...well..they imposed a new 15 minute limit on editing posts. After that you are unable to.

    In your xml, you need to specify a width and height....flash needs that for inline images. I also adjusted your parsing of the XML itself shown below. I also have it running if you need to see the result.

    XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <data><![CDATA[<img src="image15.jpg" width="200" height="200" />]]></data>

    AS:

    myText.html = true;
    myText.autoSize = true;
    var mydata = new XML();
    mydata.ignoreWhite = true;
    mydata.load("krook.xml");
    mydata.onLoad = process;

    function process (success) {
    if (success) {

    trace(this.firstChild.firstChild.nodeValue);
    myText.htmlText = this.firstChild.firstChild.nodeValue;
    } else {
    trace("bad");
    }
    }


    Running Demo:

    http://flex.hobby-site.com/examples/CDATA_image.swf



  4. #4
    Member
    Join Date
    Jan 2003
    Posts
    85
    Ahhh - thank you so much.
    Now I can relax again - I was going insane here.


    So the solution was: firstChild.firstChild.nodeValue
    I did try firstChild.nodeValue
    I'm not sure I understand why there is 2x firstChild.


    Anyways...Thank you again!

  5. #5
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Because your <data> node contains a nested node (a text node ...your CDATA) we "dot down" to it that way.

    firstChild= <data>
    firstChild.firstChild= the text node
    firstChild.firstChild.nodeValue = the text nodes value

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