0
XSD minLength验证我想通过XSD验证XML。 不得不提的就是我的XSD工作正常,除了这一块:通过PHP的DOMDocument :: schemaValidateSource()
<xs:element name="some_element">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
我做了一个包装PHP类来验证此针对XML,并在它的核心,它这样做:
$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();
问题是,即使在<some_element></some_element>
或<some_element>[100_chars_here]</some_element>
,它验证(我没有得到任何错误),并且我希望该元素的最小内容长度为50。
是否有错误?我在这里错过了什么?它适用于XSD中的正则表达式模式,但我不想使用这些。
我在WinXP上使用PHP 5.3.5
和libxml 2.7.7
。
嗯,没有想到这一点。有什么建议么?我会检查XMLPad或Xerces。 – nevvermind 2012-01-10 15:30:00
是的,在命令行中使用libxml2 2.7.8的xmllint,验证失败;应该如此。感谢您指点我正确的方向。 – nevvermind 2012-01-11 08:08:06