Avoid hexadecimal characters before parsing XML
How to Avoid hexadecimal chara开发者_如何学运维cters 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:
- A bug in the XML sent (It was meant to be XML, but it's buggy).
- You've just picked up the wrong file.
- You are using an encrypted and/or compressed file before decryption and/or decompression.
- 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.
精彩评论