xmlReader.ReadInnerXml throws xmlexception for invalid hexadecimal characters
-
11 Juli 2012 3:18
Hi All,
I have a xml file that holds metadata properties info of an listitem in a library. The metadata properties holds some invalid hexadecimal characters. I use the below code to read the xml file, it throws invalid hexadecimal characters xml exception.
CharacterSettings - checkcharacter doesnt seem to work. can anyone help me on how to handle this exception to remove those invalid xml values:
SpFile ItemAuditFile = ListItem.File ;\\xml file with info on properties
Stream AuditFile = ItemAuditFile.OpenBinaryStream();
var charSettings = new XmlReaderSettings()
{
CheckCharacters = false
};
XmlReader xmlReader = XmlReader.Create(AuditFile , charSettings);
xmlReader.MoveToContent();
try
{
AuditXmlOriginal = xmlReader.ReadInnerXml();
}
catch
{
}
xmlReader.Close()Thanks,
AV1810
Semua Balasan
-
11 Juli 2012 5:15
Hello,
You can use following code the remove the invalid character
http://baleinoid.com/whaly/2011/08/xml-deserialization-invalid-character/
http://seattlesoftware.wordpress.com/2008/09/11/hexadecimal-value-0-is-an-invalid-character/
Hope this will work.
Hiren Patel | Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you.
-
11 Juli 2012 6:37Hi,
The above references explains as how to validate a string. But the code throws the invalid value exception While trying to read the xml file to convert as a string on line - xmlReader.ReadInnerXml();
Sorry am not aware of it. Can you let me know as how to implement it in the above code.
Thanks,
AV1810