Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 05, 2007 09:45 PM by neutrino
Participant
768 Points
237 Posts
Oct 04, 2007 03:48 PM|LINK
Hello All,
I need to determine that a piece of XML in a character field or variable is well-formed XML. I need to store this validation result (valid or not valid flag) in the table.
Does SQL provide some function for this? Is there any other way?
Thank you!
David
Star
13789 Points
2449 Posts
MVP
Oct 04, 2007 08:55 PM|LINK
You can write your own function to do this either through T-SQL (painful) or .NET.
Oct 05, 2007 09:45 PM|LINK
I ended up doing it in .NET and wrote this method:
{
System.Xml.XPath.
}
neutrino
Participant
768 Points
237 Posts
Transact-SQL IsXML function (wish)
Oct 04, 2007 03:48 PM|LINK
Hello All,
I need to determine that a piece of XML in a character field or variable is well-formed XML. I need to store this validation result (valid or not valid flag) in the table.
Does SQL provide some function for this? Is there any other way?
Thank you!
David
Motley
Star
13789 Points
2449 Posts
MVP
Re: Transact-SQL IsXML function (wish)
Oct 04, 2007 08:55 PM|LINK
You can write your own function to do this either through T-SQL (painful) or .NET.
neutrino
Participant
768 Points
237 Posts
Re: Transact-SQL IsXML function (wish)
Oct 05, 2007 09:45 PM|LINK
I ended up doing it in .NET and wrote this method:
/* Tests well formed XML.*/ public static bool IsXMLValid(string XmlText){
StringReader stringReader = new StringReader(XmlText); try{
System.Xml.XPath.
XPathDocument doc = new System.Xml.XPath.XPathDocument(stringReader); return true;}
catch (Exception){
return false;}
}