Question

I want to validate an XML through XSD. I must mention that my XSD works fine, except this one piece:

<xs:element name="some_element">
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:minLength value="50"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>

I made a wrapper PHP class to validate this against an XML and, at it's core, it's doing this:

$dom = new DOMDocument();
$dom->loadXML($xml);

// handle errors manually
set_error_handler(array($this, 'errorHandler'));

// validate
$isValid = $dom->schemaValidateSource($xsd);

// restore default error handler
restore_error_handler();

The problem is that, even on <some_element></some_element> or <some_element>[100_chars_here]</some_element>, it validates (I get no errors), and I would like to have a minimum content length of 50 for that element.

Is there a bug somewhere? What am I missing here? It works with regex patterns in XSD, but I wouldn't want to use those.

I'm using PHP 5.3.5 with libxml 2.7.7 on WinXP.

Was it helpful?

Solution

On the face of it, it looks like a bug, but there's not enough information here to say that with any certainty.

Have you tried running the validation with a different schema processor? That should be your first step if a bug is suspected, as it's likely to confirm it one way or the other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top