开发者

Error processing Special Characters

开发者 https://www.devze.com 2023-03-15 12:43 出处:网络
I\'m creating an atom XML packet as part of a REST Service request. A problem happens though when the value for one of the tags in the XML contains the symbol for a registered trademark.

I'm creating an atom XML packet as part of a REST Service request. A problem happens though when the value for one of the tags in the XML contains the symbol for a registered trademark.

The XML is being sent as a "PUT" through WebRequest. When the problem character is in the XML, the complete XML package doesn't make it to the server. The data packet gets truncated and I see the error "Unexpected EOF in start tag" reported on the server.

I do notice at the server that the first part of the request comes in (before being truncated) containing the problem character as "®". I expected to just see "®".

I thought that I开发者_JS百科 only need to worry about these characters in XML:

Double Quote: "

Single Quote: '

Less Than: <

Greater Than >

Ampersand: &

How can I escape or process my string so that I can send any character with no problem?


Xml can trick you in this way. It's not that certain characters are invalid, but that a large swath of unicode is defined as valid, and anything outside of that is verbotten. The trick to getting this right without more complex logic is to use a CDATA section.


Firstly, your terminology is very loose. What do you mean by "the value for one of the tags"? Is the offending character in an element name, or in text content?

You can solve the problem by escaping non-ASCII characters if you must, for example the "registered trademark sign" becomes &#xae;. However, this shouldn't be necessary. It would be better to address the root cause of the problem, which is that the creator of the document and its recipient have different ideas about its encoding. There's something in your configuration that causes this miscommunication, and I have no possible way of knowing what it might be.

0

精彩评论

暂无评论...
验证码 换一张
取 消