Browser output XML file error on line 4 at column 56:entityref:expecting '; ' Detailed

Source: Internet
Author: User
Tags cdata xml parser
PHP writes an API that outputs something in XML format.

Now the direct display in the browser to report this error:

Error on line 4 at column 56:entityref:expecting '; '
To view the source code of the page, this line is:
Http://www.xxx.cn/index.php?id=5383&utm_source=57tuan

What's going on? How to solve?

Answer:

& Symbol, change to &, or directly with CDATA area ( )

The Firefox browser, Google Chrome browser, and most browsers display the XML file, not the source of the file, but the result of parsing the XML parser. However, when the "XML parser" encounters the character "&", it will take "&" as the beginning of an entity reference, and look for the end symbol of the entity reference ";", this is the problem that is encountered in this article.
In the XML document, there are 5 predefined entity references such as "&", namely "&", "<", ">", "" "," "".

Workaround One:
The entity reference is encoded and used, i.e.
Encode "&" as "&"
Encode "<" as "<"
Encode ">" as ">"
Encode "'" as "'"
Encode "" "" ""

Workaround Two:
In the markup CDATA, all tags, entity references are ignored and treated as raw character data by the "XML parser", CDATA in the following form:文本内容

Two points to be aware of using CDATA,

A: Because the end symbol of CDATA is "]]>", CDATA cannot contain "]]>",

Two: CDATA cannot be nested because all tags and entity references in CDATA are ignored.

  • 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.