A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: create CDATA tag dinamically. is it possible?

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Location
    IT
    Posts
    213

    create CDATA tag dinamically. is it possible?

    Hi guys, just a small question!
    Is it possible to create dinamically the CDATA tag in flash?

    Like, suppose that you want to create this XMLNode:

    <mynode><![CDATA[test]]></mynode>

    How would you do it? There's no problems in creating the first part of it ( <mynode />), but what about the CDATA tag?

    anyhelp?

    Thanks in advance

  2. #2

  3. #3
    Senior Member
    Join Date
    Jan 2001
    Location
    IT
    Posts
    213
    Hi whispers,

    in fact it's what I do, I add it as a string and pass the whole thing to a .php file which 'writes' my xml page. The problem is that it doesn't work!
    I mean, I cannot create the '<' '>' correctly as a xml tag, they're coded as a string...so it doesn't work.

    My code looks like this one:


    var doc:XML = new XML();

    var element1:XMLNode = doc.createElement("element1");
    var element2:XMLNode = doc.createElement("element2");

    doc.appendChild(element1);
    element1.appendChild(element2);

    var _myvalue:String = "this is just a test"
    var textNode1:XMLNode = doc.createTextNode("<![CDATA["+_myvalue+"]]>");

    element2.appendChild(textNode1);

    trace(doc);
    //<element1><element2>&lt;![CDATA[this is just a test]]&gt;</element2></element1>

    As you can see the "<" is coded as "&lt;" and the ">" as "&gt;"

    Any help?

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    try urlencoding the characters -
    PHP Code:
    var doc:XML = new XML();

    var 
    element1:XMLNode doc.createElement("element1");
    var 
    element2:XMLNode doc.createElement("element2");

    doc.appendChild(element1);
    element1.appendChild(element2);

    var 
    _myvalue:String "this is just a test"
    var textNode1:XMLNode doc.createTextNode("%3c![CDATA["+_myvalue+"]]%3e");

    element2.appendChild(textNode1);

    str unescape(doc.toString());
    trace(str);
    //<element1><element2><![CDATA[this is just a test]]></element2></element1> 
    hth

  5. #5
    Senior Member
    Join Date
    Jan 2001
    Location
    IT
    Posts
    213
    Hi there man,
    thanks for your help and sorry for 'being late' but I've been away for a while. Your hint was right, unfortunately it doesn't work. I don't know what is wrong with itI've attached my file so if you're willing to give it a look...

    Basically what I wanted to do is create a small file that could modify a simple xml structure. The data are sent to .php page (that I've found here on flashkit) which 'creates' the xml'.
    When I load the .xml file, I select the line to modify throuhg the compobox, then what I do I simply delete the line that I want to modidy and create a new one that I paste in the place of the deleted one. It works fine except that the fact I couldn't create the CDATA tag. The 'unescape' seems to work fine but now the trouble is that I can't create the new xml file, for some reason it doesn't work! Do you think that's because I'm tring to send a string?

    giano
    Attached Files Attached Files

  6. #6
    Senior Member
    Join Date
    Jan 2001
    Location
    IT
    Posts
    213
    Huh it seems that the problem is the .php script that should create the .xml file. I've found this one in the movie section (reference goes to Andrew Ryan) :

    <?
    clearstatcache();
    $filename=$xmlToSave;;
    $fp=@fopen($filename,"w");
    $rec=$xmlContent;
    fwrite($fp,$rec);
    fclose($fp);
    chmod($filename, 0775 );
    if ($fp) {
    echo ("&erro=NONE&statusText=SUCCESS! changes saved to database!");
    } else {
    echo ("&erro=OK&statusText=SERVER ERROR!, there was a problem. Pls try again!");
    exit();
    }

    ?>

    Changed those lines in the flush function:
    function flush() {
    xmlToSave = "testi.xml"
    xmlContent = myXML
    nomod.text = xmlContent;
    loadVariablesNum ("savexml.php", "", "POST");
    _root.statusText = "saving changes, pls wait...";
    }

    And it works just fine!
    Now do you think it's possible to set a sendAndLoad instead of loadVariablesNum?

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