追求0x0B [英] The quest for 0x0B
问题描述
System.InvalidOperationException:XML文档中有一个错误(182) ,16)。---> System.Xml.XmlException:'',十六进制值0x0B,是一个无效的字符。
足够公平,也许数据格式错误。除了,我如何找到凶手行?
SELECT * from Mytable其中列像'%'+ char(0x0B)+ '%'
返回空。
(显然我尝试所有的%+ char,char,char +%组合,以防万一)
终于找到了!
当串行化它时,.NET XML序列化程序正在转义无效字符,但是它不会转义之前取消序列化。
所以我不得不搜索转义的& #xB来找到未转义的0x0B ...严重不好笑的人! / p>
所以这样:
SELECT * from Mytable where Column like'% '+'& #xB'+'%'
实际上会发现:
<?xml version =1.0?>
< Hashtable>< key> 313_other_10< / key>< value>&#xB< / value>< / Hashtable>
虽然这看起来像有效的XML,但会在以下情况引发无效的字符异常:
XmlSerializer xs = new XmlSerializer(Type.GetType(Hashtable));
StringReader stringReader = new StringReader(xml);
obj = xs.Deserialize(stringReader);
非常感谢跳过帮助的人!这是无价的帮助!
I get this error when reading some data from an SQL column then converting it to XML:
"System.InvalidOperationException: There is an error in XML document (182, 16). ---> System.Xml.XmlException: ' ', hexadecimal value 0x0B, is an invalid character."
Fair enough, maybe the data is malformed. Except, how can I find the culprit row?
SELECT * from Mytable where Column like '%' + char(0x0B)+'%'
returns empty.
(obviously I attempted all %+char , char, char+% combinations, just in case)
Finally found it !
The .NET XML serializer was escaping the invalid character when serializing it, but then it was un-escaping it before de-serialization.
So I had to search for the escaped  to find the un-escaped 0x0B ... seriously not funny guys!
So this:
SELECT * from Mytable where Column like '%' + '' + '%'
Will actually find this:
<?xml version="1.0"?>
<Hashtable><key>313_other_10</key><value></value></Hashtable>
And while this looks like valid XML it will throw an invalid character exception when :
XmlSerializer xs = new XmlSerializer(Type.GetType(Hashtable));
StringReader stringReader = new StringReader(xml);
obj = xs.Deserialize(stringReader);
Many thanks to people who jumped in to help! It was unvaluable help!
这篇关于追求0x0B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!