I have both my XML and XSD file below.
These have been successfully validated by the ff:
- in the XML online validator site - http://ift.tt/1aWrJdQ
- via command line:xmllint --noout --schema contactmanager.xsd contactmanager.xml
However, validating it in my code, gives an error saying:
Entity: line -1: Schemas validity error: The document has no document element.
Is there anything I missed? What does this error is suggesting?
Any help is greatly appreciated! Thanks!
Here's the C code snippet. (NOTE: only the important lines are here.)
xmlDocPtr doc = xmlTextReaderCurrentDoc(reader);
schema_doc = xmlReadFile(schema_filename, NULL, XML_PARSE_NONET);
ctxt = xmlSchemaNewDocParserCtxt(schema_doc);
schema = xmlSchemaParse(ctxt);
validCtx = xmlSchemaNewValidCtxt(schema);
isValid = (xmlSchemaValidateDoc(validCtx, doc) == 0);
XSD file:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://ift.tt/tphNwY">
<xs:element name="addressbook" type="addressBookType" />
<xs:simpleType name="stringType">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:simpleType name="uuidType">
<xs:restriction base="xs:string">
<xs:length value="36" fixed="true" />
<xs:pattern value="[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[8-9a-bA-B][0-9a-fA-F]{3}-[0-9a-fA-F]{12}" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="simpleContentType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="type" type="stringType" />
<xs:attribute name="primary" type="stringType" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="simpleGroupContentType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="guid" type="uuidType" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="providerType">
<xs:sequence>
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="name" type="stringType" />
</xs:complexType>
<xs:complexType name="phonesType">
<xs:sequence>
<xs:element name="phone" maxOccurs="unbounded" minOccurs="1" type="simpleContentType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="emailsType">
<xs:sequence>
<xs:element name="email" maxOccurs="unbounded" minOccurs="1" type="simpleContentType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="cgroupsType">
<xs:sequence>
<xs:element name="group" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="guid" type="uuidType" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="providersType">
<xs:sequence>
<xs:element name="provider" maxOccurs="unbounded" minOccurs="0" type="providerType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="contactType">
<xs:sequence>
<xs:element name="firstname" minOccurs="0" maxOccurs="1" type="stringType" />
<xs:element name="lastname" minOccurs="0" maxOccurs="1" type="stringType" />
<xs:element name="organization" minOccurs="0" maxOccurs="1" type="stringType" />
<xs:element name="phones" minOccurs="0" maxOccurs="1" type="phonesType" />
<xs:element name="emails" minOccurs="0" maxOccurs="1" type="emailsType" />
<xs:element name="groups" minOccurs="0" maxOccurs="1" type="cgroupsType" />
<xs:element name="providers" minOccurs="0" maxOccurs="1" type="providersType" />
</xs:sequence>
<xs:attribute name="guid" type="uuidType" use="required"/>
</xs:complexType>
<xs:complexType name="contactsType">
<xs:sequence>
<xs:element name="contact" type="contactType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="groupsType">
<xs:sequence>
<xs:element name="group" maxOccurs="unbounded" minOccurs="1" type="simpleGroupContentType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="addressBookType">
<xs:sequence>
<xs:element name="groups" minOccurs="0" maxOccurs="1" type="groupsType" />
<xs:element name="contacts" minOccurs="0" maxOccurs="1" type="contactsType" />
</xs:sequence>
<xs:attribute name="clear" type="stringType" />
</xs:complexType>
</xs:schema>
XML file:
<?xml version="1.0" encoding="UTF-8"?>
<addressbook clear="true">
<groups>
<group guid="771a6d9e-ed28-46e8-8dad-9cdbee2c31ce">Tennis Club</group>
<group guid="ef386d7d-bd1a-4742-a00b-53902fecc6d8">COC</group>
</groups>
<contacts>
<contact guid="3281bbbf-bada-4118-ac0e-eefdd7b1c96b">
<firstname>Roger</firstname>
<lastname>Federer</lastname>
<organization>Swizz</organization>
<phones>
<phone type="" primary="true">23434</phone>
</phones>
<emails>
<email type="" primary="true">rfederer@swizz.com</email>
</emails>
<providers>
<provider name="ContactManagerExtension">
<AboutMe>I'm a tennis player.</AboutMe>
<Arts>0</Arts>
<Gender>0</Gender>
<Music>0</Music>
<Politics>0</Politics>
<ProfessionalWorkExperience>12</ProfessionalWorkExperience>
<Sports>1</Sports>
</provider>
<provider name="PrintUsageProvider">
<color_print_jobs>200</color_print_jobs>
<mono_print_jobs>100</mono_print_jobs>
</provider>
<provider name="ScanUsageProvider">
<scan_to_email>scanToEmail@swizz.com</scan_to_email>
</provider>
</providers>
</contact>
<contact guid="65201a7d-73ac-4c9e-b344-248736aad2b6">
<firstname>Rafael</firstname>
<lastname>Nadal</lastname>
<organization>Spain</organization>
<phones>
<phone type="" primary="true">00000</phone>
</phones>
<emails>
<email type="" primary="true">rnadal@spain.com</email>
</emails>
<groups>
<group guid="771a6d9e-ed28-46e8-8dad-9cdbee2c31ce"/>
</groups>
<providers>
<provider name="ContactManagerExtension">
<AboutMe>Tennis Player</AboutMe>
<Arts>0</Arts>
<Gender>0</Gender>
<Music>0</Music>
<Politics>0</Politics>
<ProfessionalWorkExperience>15</ProfessionalWorkExperience>
<Sports>1</Sports>
</provider>
<provider name="ScanUsageProvider">
<hotdogType>weener</hotdogType>
</provider>
</providers>
</contact>
<contact guid="c469b504-e8de-4370-a7a9-9a8f0d9d4385">
<firstname>Novak</firstname>
<lastname>Djokovic</lastname>
<organization>Serbia</organization>
<emails>
<email type="" primary="true">ndjoko@serbia.com</email>
</emails>
<groups>
<group guid="ef386d7d-bd1a-4742-a00b-53902fecc6d8"/>
</groups>
</contact>
<contact guid="39db4737-ddda-4485-94d9-c3394b5073e3">
<organization>Apple</organization>
</contact>
<contact guid="96ca9d9d-f4f2-4be4-902c-1768f8a20d0e">
<firstname>troy</firstname>
<lastname>helen</lastname>
<organization>Undercover</organization>
<phones>
<phone type="" primary="true">243234234</phone>
</phones>
<emails>
<email type="" primary="true">t.h@aaa.bbb.com</email>
</emails>
</contact>
<contact guid="6c9c204d-49c0-4230-89a9-bc75c947c65d">
<firstname>carl</firstname>
<lastname>santana</lastname>
<organization>Glee</organization>
<phones>
<phone type="" primary="true">2034833</phone>
</phones>
<emails>
<email type="" primary="true">s.carl@hellipas.com</email>
</emails>
<groups>
<group guid="771a6d9e-ed28-46e8-8dad-9cdbee2c31ce"/>
</groups>
<providers>
<provider name="DropBox">
<password>saintclaire</password>
<user_name>csantana</user_name>
</provider>
</providers>
</contact>
</contacts>
</addressbook>
Additional Info:
-bash-4.2$ xmllint --version
xmllint: using libxml version 20901 compiled with:
Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib Lzma
No comments:
Post a Comment