Home >Backend Development >XML/RSS Tutorial >XML illegal characters (escape characters)

XML illegal characters (escape characters)

高洛峰
高洛峰Original
2016-12-24 11:41:122608browse

As usual,
The client sent me an xml file,
used to update the digital classroom schedule - it is a js that reads the xml file to achieve the effect of displaying the daily course schedule by moving the mouse over the calendar, similar to Ajax data reading (It’s just that the data is completely statically updated)
Since there are two parties to complete the entire schedule update (the customer separates the page creation and website update),
there is always a problem with the xml file given to me,
because it is done often, I know The producer is still relatively junior in HTML coding,
so the files they provide must be corrected before each update.
Sure enough, there are still problems,
As usual, I checked whether each tag of the file content is complete,
check There was an error, and it felt like it should be OK,
But the page still showed that reading the xml data failed,
I checked the tags one by one from beginning to end (the file is quite long, I am so pathetic, woo~~~),
It actually happened No errors were found, oh, dazzled, depressed~~~,
In desperation, I had to copy the codes out,
copy them in one by one, and refresh the page preview while copying,
went back and forth several times, and finally found that there were several places in the code There are all problems,
There seems to be no grammatical errors~~~, and the tags are complete~~,
Suddenly I found "&" in the content, damn it,
I kept staring at the tags for a long time to check, forgetting that it might be a character conflict in the content ,
Replace it, it works,
In order to understand in detail, I checked on w3school:
Escape characters
Illegal XML characters must be replaced with entity references.
There are 5 predefined entity references in XML:
< < Less than
> > Greater than
& & Ampersand
' ' Ellipses
" " Quotes
Note: Strictly speaking, there are only The characters "<" and "&" are illegal. Ellipses, quotation marks, and greater-than signs are legal, but it's good practice to replace them with entity references.

For more XML illegal characters (escape characters) related articles, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn