-
<![cdata[ ?????????
<BODY><![CDATA[xxxxxxxxxxx]]></BODY>
what is the reason for using this -> <![CDATA[
-
Senior Member
Lets say you have tag in your xml file,
<message>This is some text</message>
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)
<message><![CDATA[<b>This is some text</b>]]></message>
http://www.w3schools.com/xml/xml_cdata.asp
-
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.
-
Senior Member
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><br>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.
-
can u explain this line of code
_root.textbox = this.firstChild.firstChild.firstChild.nodeValue;
i dont get this line at all
-
Senior Member
- The right of the People to create Flash movies shall not be infringed. -
-
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=1, nodeName="mydata", children=1, nodeValue="null"
[node], type=1, nodeName="someelement", children=1, nodeValue="null"
[node], type=3, nodeName="null", children=0, nodeValue="<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=1, nodeName="mydata", children=3, nodeValue="null"
[node], type=3, nodeName="null", children=0, nodeValue="
"
[node], type=1, nodeName="someelement", children=3, nodeValue="null"
[node], type=3, nodeName="null", children=0, nodeValue="
"
[node], type=3, nodeName="null", children=0, nodeValue="<b>This is the bold first line</b><br>This is the second line"
[node], type=3, nodeName="null", children=0, nodeValue="
"
[node], type=3, nodeName="null", children=0, nodeValue="
"
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=1, nodeName="mydata", children=3, nodeValue="null"
[node], type=3, nodeName="null", children=0, nodeValue="
"
[node], type=1, nodeName="someelement", children=4, nodeValue="null"
[node], type=3, nodeName="null", children=0, nodeValue="
"
[node], type=1, nodeName="b", children=1, nodeValue="null"
[node], type=3, nodeName="null", children=0, nodeValue="This is the bold first line"
[node], type=1, nodeName="br", children=0, nodeValue="null"
[node], type=3, nodeName="null", children=0, nodeValue="This is the second line
"
[node], type=3, nodeName="null", children=0, nodeValue="
"
And if we have "ignoreWhite" back on?:
PHP Code:
[node], type=1, nodeName="mydata", children=1, nodeValue="null"
[node], type=1, nodeName="someelement", children=3, nodeValue="null"
[node], type=1, nodeName="b", children=1, nodeValue="null"
[node], type=3, nodeName="null", children=0, nodeValue="This is the bold first line"
[node], type=1, nodeName="br", children=0, nodeValue="null"
[node], type=3, nodeName="null", children=0, nodeValue="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!"
-
thanks
<b>catbert303</b> and <b>cancerinform</b>
I finally got both versions to work.
greets
andreas
-
Senior Member
wow, great stuff XMLEvangelist
-
How do I treat special characters within the CDATA tag?
PHP Code:
This is not php, the 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|