Is following the valid UPnP Control response? Do they have to escape these characters in the value of <OutProfile>
? UPnP device architecture1.1(sec 3.2.4) says that argument value should be escaped if it contains characters like <, & etc. But I think it should not, if its xml. Can anyone refer some standard document that can clear this confusion? My point is that using escaped characters in following case is unnecessary and makes debugging difficult. But I need to explain this point with solid references to my peers.
<?xml version="1.0"?><s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetABCResponse
xmlns:u="urn:schemas-upnp-org:service:Client:1"><OutProf开发者_JAVA技巧ile><cProfile>
<cID>0</cID>
<iconPreference>
<mimetype>image/bmp</mimetype>
<width>32</width>
<height>32</height>
<depth>24</depth>
</iconPreference>
</cProfile>
</OutProfile></u:SetABCResponse></s:Body></s:Envelope>
First, the XML document you posted is well-formed XML.
Second, reading section 3.2.4 of the PDF document you referenced does not allow to infer that your sample XML document violates that UPnP spec. (On the other hand, I cannot say that it conforms to anything in it, because I won't read it.)
Third, the content of <OutProfile>
is a text node, or in other words, a character string.
Fourth, when extracted and serizalized without output escaping, it is another well-formed XML document.
<?xml version="1.0"?>
<cProfile>
<cID>0</cID>
<iconPreference>
<mimetype>image/bmp</mimetype>
<width>32</width>
<height>32</height>
<depth>24</depth>
</iconPreference>
</cProfile>
So fifth, it is not unlikely that your fellow developers misunderstood some requirement. On the other hand, there could be application reasons why they want the doc to be exactly like this.
Finally, it you want to embed markup as a text node in an XML document, it's preferable to use CDATA sections because that's easier on the eye. On the other hand, there's no hard reason not to go with character escaping.
No need to manually escape characters. <![CDATA[ ]]>
tags allow you to escape anything you want within the tags
<Node>
<![CDATA[<SubNode>Content</SubNode> ]]>
</Node>
http://www.w3schools.com/xml/xml_cdata.asp
精彩评论