XML requests with special characters are not parsed

If API calls had a special character & within the request body which the xml parser does not parse. All the calls which had this special character failed. The calls were successful when the & was encoded as &\; But when different characters were tried as a part of the request, it was noticed that > and , works but < and & doesn't get parsed.

How this is handled and what is the reason for this behaviour? Why some special characters work while some doesn't?

Solved Solved
1 3 2,487
1 ACCEPTED SOLUTION

XML requires that some characters be escaped. the ampersand is not a valid character in XML and must be replaced with an XML entity reference like & amp; . A CDATA section can also be used. This is not an issue/bug with any policy in Apigee Edge. It is an invalid XML document. (user error, not a product error)

View solution in original post

3 REPLIES 3

XML requires that some characters be escaped. the ampersand is not a valid character in XML and must be replaced with an XML entity reference like & amp; . A CDATA section can also be used. This is not an issue/bug with any policy in Apigee Edge. It is an invalid XML document. (user error, not a product error)

CDATA not work in attribute value

let strXml = '<items><item label="<![CDATA[ '+Hello & World+' ]]>" data="00"/><item label="item 2" data="01"/></items>';
parse from DomParser Output error

correct. 

Using a CDATA Section within an attribute value is not well-formed XML.  The reason is that attr values are not allowed to contain open angle brackets. 

attr-value-no-open-angle-brackets.png

Those hieroglyphics say,

  • an attribute value may be enclosed in either single or double quotes.
  • the value inside the quota can be any character that is not open-angle-bracket and not ampersand.* And obviously it cannot have the quote character that is used to surround the value. (* actually the value can contain an ampersand, but it's not interpreted as a plain ampersand.  The ampersand within an attribute value is always interpreted as a marker for a character reference) 
  • the value inside the attr may also include a reference. 

That is based on the XML specification. It's not an Apigee-specific restriction. 

If you want to include something that needs escaping in an attr value, then use numeric character references (&#x26; or &#38;) or named entity references (&amp;).