Re: [PHP-XML-DEV] Validating XML
[email protected] ("Eamon Reyn") Thu, 17 Jun 2004 00:10:53 +1200
| Newsgroups | php.xml.dev |
|---|---|
| Message-ID | <[email protected]> |
First I would like to say thank you Adam for the quick reply. > On Tue, 16 Jun 2004, %u wrote: > > > Warning: Element comment: failed to validate basic type date in > > c:\program files\apache > > group\Apache\htdocs\xmlimporter\importerfactory.php on line 21 > > > > This is causing me some distress as it is a completely unexpected > > warning that kicks out of my function with no return value. > > This is a libxml2 schema validation error that the PHP DOM extension > is just passing along. When such an error occurs, the schemaValidate() > method should return false. > That is the problem though it did not return false and it showed the above warnings on the web page, I will double check this behaviour in the morning to make sure however. If I use this method and I cannot validate incorrect documents without it putting awful looking warnings on the web page that I am wanting to generate then it may not be of much use I found this about validation on the zend website since posting: " At present, these all simply return true or false. Errors are dumped out as PHP warnings. Obviously this is not the ideal way to give good feedback to the user, and it will be enhanced in one of the releases after PHP 5.0.0. The exact implementation is currently under discussion, but will certainly lead to better error reporting for parse errors and so on." So I assume at some point in the future this behaviour will change? Should I switch off warnings in code before calling schemaValidate() and then switch them back on afterwards (not completely sure how but I think this can be done). > > //original working code from xsd > > <xsd:element name="comment" type="xsd:string"/> > > > > //code which makes xml invalid > > <xsd:element name="comment" type="xsd:date"/> > > What I believe the error is trying to express is that your XML Schema > has declared the comment element to be of the basic (as compared to > complex) type "date," but your document contains a different type of > element. Hence it "failed to validate basic type date." > > I agree that this isn't the most informative of error messages, but as > I said, this is what libxml2 generates. If we want to fix it, we need > to fix the libxml2 sources, which is actually easier done than I'm > making it out do be, but is harder than just making a change to the > PHP DOM extension. > > Make sense? > > -adam Yeah sort of and I understand why you guys would be reluctant to fiddle in something you don't own but I think the warnings should be suppressed or stored in the DOM object for referencing (e.g. a dom->validationErrors call that returns stuff you need to know) at least until a decision of what to do is reached. I take it from what I have discovered there is no in code way of returning what error was encountered and exactly where it was encountered. Eamon.