When the data contains the '<', '&' symbols, the encapsulated XML cannot be parsed.

Source: Internet
Author: User
A request2XML method is written. when the data contains the & lt; and & amp; symbols, the encapsulated XML cannot be parsed. The CDATA attribute in XML is found to solve the problem! All text in the XML document will be parsed by the parser. Only the text in the CDATA part is ignored by the parser.

A request2XML method is written. when the data contains the '<', '&' symbol, the encapsulated XML cannot be parsed. The CDATA attribute in XML is found to solve the problem! All text in the XML document will be parsed by the parser. Only the text in the CDATA part is ignored by the parser. --------------------------------------------------- The XML parser for parsing data generally processes all texts in the XML document. When an XML element is parsed, the text inside the XML element is also parsed: This text is also parsed The XML parser does this because the XML element may also contain other elements. in the following example, the name element contains the first and last elements: Bill Gates The parser considers the above code as follows: Bill Gates -----------------------------------------------------

Invalid escape characters must be replaced with corresponding XML characters. If you use a character similar to "<" in the XML document, the parser will encounter an error because the parser considers this as the beginning of a new element. Therefore, the code should not be written as follows: If salary <1000 then To avoid this situation, you must convert the character "<" to an object, as shown below: If salary <1000 then The following are five pre-defined entities in the XML document:

<Yu No.
> Yu No.
&
''Single quotes
"" Double quotation marks

The object must start with the symbol "&" and end with the symbol. Note: only the "<" and "&" characters are strictly forbidden for XML. The rest are legal. it is a good habit to use entities to reduce errors. -----------------------------------------------------

All content of the CDATA component in CDATA is ignored by the parser. If the text contains many "<" characters and "&" characters-like program code, it is best to put them in the CDATA component. A CDATA part uses"" 标记开始,以""Mark end: script function matchwo(a,b) { if (a < b && a < 0) then { return 1 } else { return 0 } } In the preceding example, all texts between CDATA components are ignored by the parser. CDATA considerations: CDATA components cannot be nested ). If the CDATA part contains the character "]>" or"" ,将很有可能出错哦。同样要注意在字符串"There is no space or line break between them.

When the data contains the '<' and '&' symbols, the encapsulated XML cannot be parsed. For more information, see other related articles in the first PHP community!

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.