Validating XML in PHP and generating “human readable” error messages?

goartyMag

New Member
I'm trying to build a tool for validating specific XML and outputting human-readable results. My existing PHP code uses DOMDocument::schemaValidate to validate the XML against a .xsd file, but the error messages aren't very friendly. For example, Let's pretend my XML looks like the sample below and that Latitude should be a decimal:\[code\]<Person> <FirstName>Bret</FirstName> <Location> <Address>123 Test Ave.</Address> <Latitude></Latitude> <Longitude>30.139338</Longitude> </Location></Person>\[/code\]The error message I would currently get would be:\[quote\] Document::schemaValidate(): Element 'Latitude': '' is not a valid value of the atomic type 'xs:decimal'.\[/quote\]I want it to say:\[quote\] Error in XML Line #5: The person "Bret" has an empty Latitude in their address. You must include a valid Latitude in order for us to process this XML.\[/quote\]Similar questions has been asked before:However, I'm willing to write my own brute-force validation code using PHP or Perl if DOMDocument::schemaValidate isn't the right tool for this job. Notice that my error messages need to refer to information stored in parent elements, like the "FirstName" field in my example.My question is: What's a good approach to create this validation tool? Are there any existing code libraries or tutorials to point me in the right direction?Thanks!!
 
Top