Analysis of the use of escape characters in HTML and XML in Flash AS3

Source: Internet
Author: User
Tags cdata html tags xml parser

In the use of special characters in AS3, there will be errors, or the characters are not displayed, or show the wrong, this article to do a simple analysis, if there is better analysis, please keep abreast.

Sample.xml and Sample_cdata.xml are the XML files that need to be used in this example, please click to see their content, this example takes special characters < and > as an example; the text string variable is txt and the text is displayed with the name Shwo_txt.

Since < and > in HTML and XML have special meanings that cannot be used directly, the two characters should be used with their escape sequences, that is, < and, so the < and > in the XML file will be replaced by &lt; and &gt;. See Sample.xml for your usage.

CDATA used for text data that you do not want to be parsed by the XML parser, using the format, the string part is considered a pure string, even if it contains special characters and is considered a normal string, see Sample_cdata.xml.

After the XML file is ready, the next step is to use the program to load the XML file and display it in the text box (Show_txt) based on the contents of the XML, where the load is loaded with Urlloader, the string txt is loaded after the load is completed, and then the button that you clicked is displayed accordingly. Here is the demo file, where "normal" means no CDATA XML file, text box does not support HTML tags, htmltext description of HTML tags support (note: Flash only supports some HTML tags).

As you can see,,&lt; and &gt; when the XML is normal (no CDATA used) Will first be parsed by XML, escaping to < and, when the string txt is passed to the Show_txt Text property, because the HTML tag feature is not used, there will be no error, the display result is correct, and when TXT is passed to Show_txt's HTMLText property, Because the HTML tag feature is used, special characters < and > are considered illegal characters and are not displayed.

In the same vein, when XML uses CDATA, XML parses the text, ignoring the characters that &lt; and &gt; think are simple, and when the string txt is passed to the Show_txt Text property, the natural,&lt; and &gt; is displayed, and when TXT is passed to Show_txt's HTMLText property, the results are displayed correctly because the HTML tag feature,&lt; and &gt; is escaped to < and.

Therefore, be aware that both HTML and XML will escape special characters to avoid the occurrence of errors.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.