I have errors checking the generated XML string. I downloaded the XML-String using the XML-Reader and assigned an XSD file for verification.
There are object identifiers and URLs for validating the pattern of valid characters. I think the ids and urls are correct. But why does the verification process generate errors?
I have error messages like:
Element 'objectID': [facet 'pattern'] The value 'ffc89' is not accepted by the pattern '^[a-z]{1,1}[a-z0-9.-]{3,14}$'.
Element 'objectID': 'ffc89' is not a valid value of the local atomic type.
Element 'originUrl': [facet 'pattern'] The value 'http://domain.com/images/89/f972c66982290125.jpg' is not accepted by the pattern '^(http|https){1}(://){1}[a-zA-Z0-9\-\./#?&_]+'.
Element 'originUrl': 'http://domain.com/images/89/f972c66982290125.jpg' is not a valid value of the local atomic type.
Here is the code snippet:
$reader = new XMLReader();
libxml_use_internal_errors(true);
$reader->xml($xml_str_tocheck);
$reader->setSchema($xsd_file_name);
while( $reader->read() ) ;
$reader->close();
$errors = libxml_get_errors();
libxml_use_internal_errors(false);
if( count($errors) )
{
foreach ($errors as $error)
{
echo $error->message;
}
}
This is an XML String to validate:
<?xml version="1.0" encoding="UTF-8"?>
<oimages startFetchDate="2015-06-10T12:48:20+00:00">
<object>
<objectID>ffc89</objectID>
<images>
<image>
<originUrl>http://domain.com/images/89/f972c66982290125.jpg</originUrl>
</image>
</images>
</object>
</oimages>
This is the XSD file:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="images">
<xs:complexType>
<xs:sequence>
<xs:element name="object" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="objectID" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="4"/>
<xs:maxLength value="15"/>
<xs:pattern value="^[a-z]{1,1}[a-z0-9.-]{3,14}$"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="images" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="image" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="url" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="10"/>
<xs:pattern value="^(http|https){1}(://){1}[a-zA-Z0-9\-\./#?&_]+" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
source
share