Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

sql server 2005 - The quest for 0x0B

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 &#xB to find the un-escaped 0x0B ... seriously not funny guys!

So this:

  SELECT * from Mytable where Column like '%' + '&#xB' + '%'

Will actually find this:

<?xml version="1.0"?>
      <Hashtable><key>313_other_10</key><value>&#xB</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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...