-3

I want to create an xml file that contains invalid characters such as "&", "=" ... etc.

Is it possible because I can not find a solution? Can I convert these characters?

I wonder if it is not better to generate JSON instead?

Cyclonecode
  • 29,115
  • 11
  • 72
  • 93
jlafforgue
  • 287
  • 2
  • 5
  • 15

1 Answers1

1

You can include any character in the text "payload" of an XML document. However, as you note, in the case of special reserved characters, you may need to escape them first.

For example, & becomes &amp; - short for ampersand, < becomes &lt; and > becomes &gt;, less than and greater than respectively. However, as the wikipedia link above shows, = does not need to be escaped.

Fortunately, PHP includes functions that take care of escpaing strings for you, so I'd recommend just wescaping your text before you add it into the document.

Community
  • 1
  • 1