I have a mysql 5.1, stored procedure that takes TEXT input which is supposed to contain an XML.
I could successfully parse XML and do everything needed. Now that I am working on error handling part, I need to know how to make sure that the input XML is well formed and valid ?
Thanks
I don’t know of anything in MySQL’s XML support that says “this is well formed XML” but you can fake it. MySQL has an
ExtractValuefunction:But you can also use this to check the XML since:
So if you hand
ExtractValueany valid XPath expression and any valid piece of XML then you will get a non-NULL result but if you use value XPath and invalid XML, you get a NULL back. So all you need to do is build an INSERT and UPDATE triggers that useExtractValueto check the XML andsignalto raise an exception if you get a NULL: