开发者

Avoid hexadecimal characters before parsing XML

How to Avoid hexadecimal chara开发者_如何学运维cters before parsing XML?

Avoid hexadecimal characters before parsing XML


Your problem isn't an hexadecimal character (those are all fine). Your problem is a character that is not allowed in XML. The hexadecimal value of that character (all characters have an hexadecimal value) is given in the error message to help you figure out what that character is, which is particularly useful since characters that are disallowed in XML are generally control characters, non-characters and mis-matched surrogates, all of which aren't printable characters anyway.

In other words, if you see this error message you are trying to parse something as XML that is not XML.

There are a few things that can cause this:

  1. A bug in the XML sent (It was meant to be XML, but it's buggy).
  2. You've just picked up the wrong file.
  3. You are using an encrypted and/or compressed file before decryption and/or decompression.
  4. You're picking up artefacts of transmission because you're reading a stream at the wrong level (pretty rare).

The first case can be the worse, because it can be caused by someone else's bug, and some people don't even believe that there are characters disallowed in XML for such things as not actually being characters and won't fix their mess (gah!). Sometimes you can filter out their rubbish though, but this is always fraught.

The fact that you've talk of decryption elsewhere in the code sample makes me suspect case 3: It's encrypted XML and you haven't decrypted it yet.

It could be a mixture of both where someone is trying to package raw encrypted octets into an XML format. This cannot be done, but rather if you need to store encrypted octets within an XML format you must re-encode those octets in an XML-compatible format such as base-64 or hexadecimal. Or alternatively, just not use XML for that at all.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜