php output xml produces parse error “’”

前端 未结 7 1490
时光说笑
时光说笑 2021-01-13 08:24

Is there any function that I can use to parse any string to ensure it won\'t cause xml parsing problems? I have a php script outputting a xml file with content obtained from

相关标签:
7条回答
  • 2021-01-13 09:25

    Enclose the value within CDATA tags.

    <message><![CDATA[&rsquo;]]></message>
    

    From the w3schools site:

    Characters like "<" and "&" are illegal in XML elements.

    "<" will generate an error because the parser interprets it as the start of a new element.

    "&" will generate an error because the parser interprets it as the start of an character entity.

    Some text, like JavaScript code, contains a lot of "<" or "&" characters. To avoid errors script code can be defined as CDATA.

    Everything inside a CDATA section is ignored by the parser.

    0 讨论(0)
提交回复
热议问题