All text in the XML document will be parsed by the parser. Only the text in the CDATA part is ignored by the parser. All text in the XML document will be parsed by the parser. Only the text in the CDATA part is ignored by the parser.
--------------------------------------------------------------------------------
Parse data
The XML parser usually processes all text 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
--------------------------------------------------------------------------------
Escape characters
Invalid XML characters must be replaced with corresponding entities.
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:
All content 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 ended:
《script》function matchwo(a,b){if (a < b && a < 0) then{return 1}else{return 0}}《script》
In the previous 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"" ,将很有可能出错哦。</p><p>同样要注意在字符串"There is no space or line break between them.
The above is the detailed content shared by the xml Parsing method code. For more information, see other related articles in the first PHP community!