PDA

View Full Version : XML verification issue



yogesh
4th March 2009, 13:15
Hi,
I am working in a socket application where I am sending the data to the server in xml form and receiving reesponse for it in an xml format. The problem is that when I am trying to parse the message I am getting the error that it cannot parse the xml.
I am using the API
QDomDocument setContent(byteArray);
in the byteArray there is a message in xml format from the server. When I debugged the API I found that the error was because of the comment format in the server response.
The server response was


<?xml version="1.0" encoding="UTF-8"?>
<!--- TCP probe server response v0.121 --->
<probeResponse version="1.0" xmlns="https://www.xxxx.com/schemas/probe/v1_0">
<params>
<period>45</period>
<next>90</next>
<dec>0.71</dec>
<valid>604800</valid>
<count>10</count>
</params>
<detect>
<xaddress>0x0a24654e</xaddress>
<xport>0x068c</xport>
</detect>
<timestamp>44675436</timestamp>
<nonce>JwMFecnLFUz/REJ8HuQE45943</nonce>
<signature method="HMAC-SHA1">ZajDI9xJLFfP3B8UFSVCmk9oyLY=</signature>
</probeResponse>

Now the comment understood by QDomComment is in the form of
<!-- XXXXX -->
Since the server response is having the comment as <!--- XXXX --->
an extra "-" so it is giving error there. When I try to write the response in file and manually remove the "-" from comment and then try to use setContent() it works like charm.
Please help me is there any way I can define the rule to accept such comment as valid comment because the server implementation cant be changed I have to have some kind of work around to make this accept as valid xml message.

Regards,
Yogesh

Lykurg
4th March 2009, 14:45
Well, the trolls - or better nokias(?) - have something against tree dashes. Have a look at the QDomCommentPrivate::save() implementation:

if (value.endsWith(QLatin1Char('-')))
s << ' '; // Ensures that XML comment doesn't end with --->

So the best would be as you self have written:

byteArray.replace("<!---", "<!--").replace("--->", "-->")

Lykurg

P.s.: I am not sure if three dashes are valid XML even if it is only said that comments starts with "<!--" and ends with "-->"...