Validate XML before using it

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I am receiving XML (not a full document, just a node tree) from a remote
party and then inserting it into my bigger XML document using
XmlWriter.WriteRaw(). The problem is that sometimes the XML from the remote
party has invalid characters (such as \x17, \x08, etc). It is a known bug
and they are working on it. But I need a quick solution ASAP to validate
their XML before passing it into my WriteRaw because it puts my XmlWriter
into a bad state (and it may take weeks for them to fix their code).

Basically I just want to detect whether or not their XML is invalid, and if
so, ignore it. What is the best way to do this?

Thanks
 
Hello Bob,

Just to add to Jim see samples over there http://msdn.microsoft.com/library/en-us/cpguide/html/cpconvalidationofxmlwithschemas.asp

B> I am receiving XML (not a full document, just a node tree) from a
B> remote party and then inserting it into my bigger XML document using
B> XmlWriter.WriteRaw(). The problem is that sometimes the XML from the
B> remote party has invalid characters (such as \x17, \x08, etc). It is
B> a known bug and they are working on it. But I need a quick solution
B> ASAP to validate their XML before passing it into my WriteRaw because
B> it puts my XmlWriter into a bad state (and it may take weeks for them
B> to fix their code).
B>
B> Basically I just want to detect whether or not their XML is invalid,
B> and if so, ignore it. What is the best way to do this?
B>
B> Thanks
B>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Yeah they are fixing the problem. The thing is I need a work-around, like,
right now, while they are working on it. I've tried stuff like setting
CheckCharacters=false on the reader and writer. This causes the writer to
no longer throw when writing, but the reader still throws.
 
I solved the problem by making a NullStream class derived from Stream,
making a new XmlWriter directed to that stream, and first testing
XmlWriter.WriteRaw() on the null stream to validate whether or not the input
XML is valid. Seems to work OK.
 
Back
Top