ID:               30814
 Comment by:       anthony at ectrolinux dot com
 Reported By:      pecoes at web dot de
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: windows xp
 PHP Version:      5.0.2
 New Comment:

I second that this issue needs to be addressed, as it's quite tiresome
to code work-arounds for this problem. While not the most elegant
solution, the errors DOM emits when validating an XML document against
a schema can be captured, parsed and processed at the script level to
emulate the functionality you described. 

>From an implementational standpoint, I agree with your idea in
principle, though I believe that a few modifications are necessary:

Let's assume that a user is going to design an XML Schema to validate
user-submitted form data, which will be validated with DOM (using
XPath): this data will be grouped into a set of elements, and then
validated. 

In order to best represent the errors for this scenario, it would be
helpful for DOM to throw a few basic pieces information, including: The
parent path of the faulty element, the name of the element, a
description of the error and the error -code-. In place of an error
-number-, using the W3C-defined error codes for the XML Schema
Structures specification would provide a consistant means of reporting
invalidities. You could then, as you demonstrated, use a simple switch
statement to process the errors as needed.

Though I believe the above would be well suited to addressing the
problem outlined by this bug, as mentioned in the above scenario, it
would also be helpful to know only the elements that -failed- to
validate. A method of "reverse-validating" a document would be quite
helpful, in that it would simply report the elements that failed to
validate. This could be done at the script level if the functionality
was not provided natively by PHP.


Previous Comments:
------------------------------------------------------------------------

[2004-11-17 16:55:14] pecoes at web dot de

Description:
------------
A lot can go wrong during schema validation:

1.) the schema cannot be opened
2.) the schema is not well-formed
3.) the schema itself is invalid
4.) the $dom in question is invalid

Currently there is neither a way to distinguish between these four
problems, nor a way to capture an actual validation error(4). Imho
schemaValidate really needs some refinements. Here's an idea:

schemaValidate (string file [, integer errType [, string errMsg]])

errType and errMsg would describe the error (if any) and schemaValidate
would STOP triggering errors and return false instead. Usage:

if (!$dom->schemaValidate($schema, $errType, $errMsg)) {
    switch ($errType) {
        case SCHEMA_NOT_FOUND:
            throw new Exception("$schema not found");
        case SCHEMA_NOT_WELLFORMED:
            throw new Exception("$schema not well-formed");
        case SCHEMA_INVALID:
            throw new Exception("$schema is invalid");
        case SCHEMA_DOM_INVALID:
            throw new Exception("XML invalid: $errMsg");
    }
}

or simply:

if (!$dom->schemaValidate($schema, $errType, $errMsg)) {
    throw new Exception($errMsg ? $errMsg : "$schema not usable");
}

Whether you like my idea or not, I hope you'll agree that:

if ([EMAIL PROTECTED]>schemaValidate($schema)) {
    throw new Exception("cannot validate or invalid input");
}

is not enough.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30814&edit=1

Reply via email to