A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: <![cdata[ ?????????

  1. #1
    Senior Member
    Join Date
    Aug 2000
    Posts
    473

    <![cdata[ ?????????

    <BODY><![CDATA[xxxxxxxxxxx]]></BODY>

    what is the reason for using this -> <![CDATA[



  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Lets say you have tag in your xml file,

    &lt;message&gt;This is some text&lt;/message&gt;

    now you decide you want to make this into bold using some html tags, the < and > aren't allowed inside the XML since they would be enterpreted as new XML tags, however you can solve this by putting it inside a CDATA section (this prevents the XML parser trying to parse the text contained inside)

    &lt;message&gt;&lt;![CDATA[&lt;b&gt;This is some text&lt;/b&gt;]]>&lt;/message&gt;

    http://www.w3schools.com/xml/xml_cdata.asp

  3. #3
    Senior Member
    Join Date
    Aug 2001
    Posts
    201

    get html to work - in a node

    Hi all,

    I´ve been searching some posts but couldn´t manage to find the answer. How to put html in a node?

    so i tried using
    PHP Code:
    <element>1st line<![CDATA[<br/>]]>2nd line</element

    and also I tried
    PHP Code:
    <element><![CDATA[1stline<br>second line]]></element
    but both flash didn´t like.

    How do I inform Flash that this whole nodeValue is html-code which should be displayed?

    I does it matter that I run through the xml tree first and assign put all the data in arrays?

    anyhelp is very much appreciated!

    andylatte
    Last edited by andylatte; 05-10-2003 at 09:16 PM.

  4. #4
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Here's a very quick example,

    the xml file, linebreak.xml
    PHP Code:
    <?xml version="1.0"?> 
    <mydata>
    <someelement><![CDATA[<b>This is the bold first line</b>&lt;br&gt;This is the second line]]></someelement>
    </mydata>
    and the actionscript,

    code:

    myXML = new XML();
    myXML.ignoreWhite = true;
    myXML.onLoad = function(success) {
    if (success) {
    _root.textbox = this.firstChild.firstChild.firstChild.nodeValue;
    }
    }
    myXML.load("linebreak.xml");



    where textbox is the variable name of an html enabled textfield on the main timeline. hope this helps

    [edit]
    storing the data in an array should make no difference
    [/edit]
    Last edited by catbert303; 05-10-2003 at 09:40 PM.

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Posts
    473
    can u explain this line of code

    _root.textbox = this.firstChild.firstChild.firstChild.nodeValue;


    i dont get this line at all



  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Check out this:
    html in xml. It's so easy!
    http://can_info_guide.tripod.com/xml...utorial_6.html
    and also this (something about html, [CDATA] in xml/flash)
    http://can_info_guide.tripod.com/tex...htmlinxml.html
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Member
    Join Date
    Jan 2003
    Location
    Australia, Adelaide (SA)
    Posts
    97
    Given the following XML:
    PHP Code:
    <mydata>
      <
    someelement>
        <![
    CDATA[<b>This is the bold first line</b><br>This is the second line]]>
      </
    someelement>
    </
    mydata
    The following is the structure of the XML:
    PHP Code:
    [node], type=1nodeName="mydata"children=1nodeValue="null"
      
    [node], type=1nodeName="someelement"children=1nodeValue="null"
        
    [node], type=3nodeName="null"children=0nodeValue="<b>This is the bold first line</b><br>This is the second line" 
    Given the above, lets answer your question:
    can u explain this line of code

    _root.textbox = this.firstChild.firstChild.firstChild.nodeValue;
    The code is setting a text box on the _root timeline to the value of something in the XML, specifically:
    • In the XML object (this), get the first child (node "mydata")
    • Get the first child (node "someelement")
    • Get the first child (node type 3, the CDATA block)
    • Return the nodeValue (the text of the CDATA block)


    If you want to understand more, keep reading, otherwise stop now!

    The above output is generated by the following script (handy for debugging):
    code:

    var xmlDoc = new XML();
    xmlDoc.ignoreWhite = true;

    var strXML = "<mydata>\n";
    strXML += "\t<someelement>\n";
    strXML += "\t\t<![CDATA[<b>This is the bold first line</b><br>This is the second line]]>\n";
    strXML += "\t</someelement>\n";
    strXML += "</mydata>";

    xmlDoc.parseXML(strXML);

    showNode( xmlDoc.firstChild, 0 );
    function showNode( xmlNode, depth )
    {
    var strIndent = '';
    var strOutput = '';
    for( var i=0; i < depth; i++ )
    {
    strIndent += ' ';
    }
    strOutput = '[node], type=' + xmlNode.nodeType;
    strOutput += ', nodeName="' + xmlNode.nodeName + '"';
    strOutput += ', children=' + xmlNode.childNodes.length;
    strOutput += ', nodeValue="' + xmlNode.nodeValue + '"';
    trace( strIndent + strOutput );
    // show child node info
    for( var i=0; i < xmlNode.childNodes.length; i++ )
    {
    showNode( xmlNode.childNodes[i], depth + 1 );
    }
    }


    Now, lets see what happens if we turn off the "ignoreWhite" setting:
    PHP Code:
    [node], type=1nodeName="mydata"children=3nodeValue="null"
      
    [node], type=3nodeName="null"children=0nodeValue="
        "
      
    [node], type=1nodeName="someelement"children=3nodeValue="null"
        
    [node], type=3nodeName="null"children=0nodeValue="
            "
        
    [node], type=3nodeName="null"children=0nodeValue="<b>This is the bold first line</b><br>This is the second line"
        
    [node], type=3nodeName="null"children=0nodeValue="
        "
      
    [node], type=3nodeName="null"children=0nodeValue="

    Now, lets try removing the CDATA around our text (since it is valid XML if we properly terminate the BR tag):
    PHP Code:
    <mydata>
      <
    someelement>
        <
    b>This is the bold first line</b><br />This is the second line
      
    </someelement>
    </
    mydata
    How does the tree look now?:
    PHP Code:
    [node], type=1nodeName="mydata"children=3nodeValue="null"
      
    [node], type=3nodeName="null"children=0nodeValue="
        "
      
    [node], type=1nodeName="someelement"children=4nodeValue="null"
        
    [node], type=3nodeName="null"children=0nodeValue="
            "
        
    [node], type=1nodeName="b"children=1nodeValue="null"
          
    [node], type=3nodeName="null"children=0nodeValue="This is the bold first line"
        
    [node], type=1nodeName="br"children=0nodeValue="null"
        
    [node], type=3nodeName="null"children=0nodeValue="This is the second line
        "
      
    [node], type=3nodeName="null"children=0nodeValue="

    And if we have "ignoreWhite" back on?:
    PHP Code:
    [node], type=1nodeName="mydata"children=1nodeValue="null"
      
    [node], type=1nodeName="someelement"children=3nodeValue="null"
        
    [node], type=1nodeName="b"children=1nodeValue="null"
          
    [node], type=3nodeName="null"children=0nodeValue="This is the bold first line"
        
    [node], type=1nodeName="br"children=0nodeValue="null"
        
    [node], type=3nodeName="null"children=0nodeValue="This is the second line
        " 
    OK, summary time: XML can be tricky, but once you understand the basic concepts it's pretty easy... one of the key things to remember is every 'piece' of XML is considered a node, even text.

    As you might have noticed above, the "ignoreWhite" property tells Flash if it should ignore the extra white-space between nodes, specifically if a node of type text is between two nodes of type element, and it's contents is whitespace only (space, tab, line-feeds), ignore it.

    When ignoreWhite isn't enabled, the pretty formatting of the XML is included as text nodes. One thing to keep in mind is that regardless of the ignoreWhite setting, extra white-space at the end of the last example was still included (the enter+tab before the end "someelement" tag).

    Hope this helps!
    Tim Walters
    Senior Developer
    XML Evangelist
    "XML isn't a language, it's a way of life!"

  8. #8
    Senior Member
    Join Date
    Aug 2001
    Posts
    201
    thanks

    <b>catbert303</b> and <b>cancerinform</b>

    I finally got both versions to work.

    greets

    andreas

  9. #9
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    wow, great stuff XMLEvangelist

  10. #10
    Junior Member
    Join Date
    Jul 2000
    Posts
    21
    How do I treat special characters within the CDATA tag?

    PHP Code:
    This is not phpthe code tag didn't work.

    <![CDATA[<LI>This text has a special character ’ </LI>]]>

    I end up with %96 in the text field if I set the asp to:

    Response.Write "<![CDATA[<LI>"  & Server.URLEncode(text) "</LI>]]>" 
    Last edited by agallisa; 07-18-2003 at 11:04 AM.
    [swf width="300" height="40" background="#003366"]http://www2.trincoll.edu/~agallisa/footer.swf[/swf]

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