[xml] Problems validating a doc with a schema (can I use a DTD?)



Hi There,

   I'm getting strange problems when I'm trying to validate a xml with a
certain schema.

   I keep getting the error for several lines (22<->36 and several other):

file:///C%3A/UserData/personal/work/VC++/IFXLib_c3.0/testingXMLSerializer/De
bug/yoda.xsd:22: element element: Schemas parser error : Element has no name
nor ref


This is my code:

        xmlDocPtr schemaDoc = NULL;
        xmlSchemaParserCtxtPtr schemaParser = NULL;
        xmlSchemaPtr schemaPtr = NULL;
        xmlSchemaValidCtxtPtr validSchema =  NULL;

        schemaDoc = xmlReadFile((const char*)schemaPath,"UTF-8",256);
        schemaParser= xmlSchemaNewDocParserCtxt(schemaDoc);
 
        printf("schema path: %s",schemaPath);
        if (schemaParser)
        {
                int retSchema = 0;
                schemaPtr = xmlSchemaParse(schemaParser);
                if (schemaPtr)
                {
                        validSchema = xmlSchemaNewValidCtxt(schemaPtr);
                        if (validSchema)
                                retSchema =
xmlSchemaValidateDoc(validSchema,doc);
                }
                if (retSchema != 0)
                {
                        status = retSchema;
                }
        }

This is the schema that I use:

(it's quite big, sorry)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:simpleType name="Bool">
                <xs:annotation>
                        <xs:documentation>IFX_BOOL</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:boolean"/>
        </xs:simpleType>
        <xs:simpleType name="String">
                <xs:annotation>
                        <xs:documentation>IFX_STRING</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:string"/>
        </xs:simpleType>
        <xs:complexType name="TField">
                <xs:annotation>
                        <xs:documentation>IfxField</xs:documentation>
                </xs:annotation>
                <xs:choice>
                        <xs:element name="Bool" type="Bool"/>
                        <xs:element name="F32" type="F32"/>
                        <xs:element name="F64" type="F64"/>
                        <xs:element name="I16" type="I16"/>
                        <xs:element name="I32" type="I32"/>
                        <xs:element name="I8" type="I8"/>
                        <xs:element name="I64" type="I64"/>
                        <xs:element name="U16" type="U16"/>
                        <xs:element name="U32" type="U32"/>
                        <xs:element name="U8" type="U8"/>
                        <xs:element name="U64" type="U64"/>
                        <xs:element name="String" type="String"/>
                        <xs:element name="Opaque" type="Opaque"/>
                        <xs:element name="Compressed" type="Compressed"/>
                        <xs:element name="DateTime" type="DateTime"/>
                        <xs:element name="Array" type="Array"/>
                </xs:choice>
                <xs:attribute name="null" type="xs:boolean" use="optional"/>
                <xs:attribute name="name" type="xs:string" use="required"/>
                <xs:attribute name="sub-type" type="xs:string"
use="optional"/>
        </xs:complexType>
        <xs:element name="Document" type="TDocument"/>
        <xs:complexType name="TDocument">
                <xs:annotation>
                        <xs:documentation>IfxDocument</xs:documentation>
                </xs:annotation>
                <xs:sequence minOccurs="0" maxOccurs="unbounded">
                        <xs:choice>
                                <xs:element name="Field" type="TField"/>
                                <xs:element ref="Document"/>
                        </xs:choice>
                </xs:sequence>
                <xs:attribute name="null" type="xs:boolean" use="optional"/>
                <xs:attribute name="name" type="xs:string" use="required"/>
        </xs:complexType>
        <xs:simpleType name="Compressed">
                <xs:annotation>
                        <xs:documentation>IFX_COMPRESSED</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:string"/>
        </xs:simpleType>
        <xs:simpleType name="DateTime">
                <xs:annotation>
                        <xs:documentation>IFX_DATETIME</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:dateTime"/>
        </xs:simpleType>
        <xs:simpleType name="Opaque">
                <xs:annotation>
                        <xs:documentation>IFX_OPAQUE</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:base64Binary"/>
        </xs:simpleType>
        <xs:complexType name="Array">
                <xs:annotation>
                        <xs:documentation>IFX_ARRAY_*</xs:documentation>
                </xs:annotation>
                <xs:choice>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="Bool" type="Bool"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="U64" type="U64"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="F32" type="F32"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="F64" type="F64"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="I16" type="I16"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="String" type="String"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="U8" type="U8"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="U32" type="U32"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="U16" type="U16"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="I64" type="I64"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="I8" type="I8"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="I32" type="I32"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element ref="Document"/>
                        </xs:sequence>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="DateTime"
type="DateTime"/>
                        </xs:sequence>
                </xs:choice>
                <xs:attribute name="type" use="required">
                        <xs:simpleType>
                                <xs:restriction base="xs:string">
                                        <xs:enumeration value="Document"/>
                                        <xs:enumeration value="DateTime"/>
                                        <xs:enumeration value="Bool"/>
                                        <xs:enumeration value="U64"/>
                                        <xs:enumeration value="U32"/>
                                        <xs:enumeration value="U16"/>
                                        <xs:enumeration value="U8"/>
                                        <xs:enumeration value="I64"/>
                                        <xs:enumeration value="I32"/>
                                        <xs:enumeration value="I16"/>
                                        <xs:enumeration value="I8"/>
                                        <xs:enumeration value="String"/>
                                        <xs:enumeration value="F32"/>
                                        <xs:enumeration value="F64"/>
                                </xs:restriction>
                        </xs:simpleType>
                </xs:attribute>
                <xs:attribute name="size" type="xs:long" use="required"/>
        </xs:complexType>
        <xs:simpleType name="F64">
                <xs:annotation>
                        <xs:documentation>IFX_F64</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:double"/>
        </xs:simpleType>
        <xs:simpleType name="F32">
                <xs:annotation>
                        <xs:documentation>IFX_F32</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:float"/>
        </xs:simpleType>
        <xs:simpleType name="I64">
                <xs:annotation>
                        <xs:documentation>IFX_I64</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:long"/>
        </xs:simpleType>
        <xs:simpleType name="U64">
                <xs:annotation>
                        <xs:documentation>IFX_U64</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:unsignedLong"/>
        </xs:simpleType>
        <xs:simpleType name="U32">
                <xs:annotation>
                        <xs:documentation>IFX_U32</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:unsignedInt"/>
        </xs:simpleType>
        <xs:simpleType name="U16">
                <xs:annotation>
                        <xs:documentation>IFX_U16</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:unsignedShort"/>
        </xs:simpleType>
        <xs:simpleType name="U8">
                <xs:annotation>
                        <xs:documentation>IFX_U8</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:unsignedByte"/>
        </xs:simpleType>
        <xs:simpleType name="I8">
                <xs:annotation>
                        <xs:documentation>IFX_I8</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:byte"/>
        </xs:simpleType>
        <xs:simpleType name="I16">
                <xs:annotation>
                        <xs:documentation>IFX_I16</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:short"/>
        </xs:simpleType>
        <xs:simpleType name="I32">
                <xs:annotation>
                        <xs:documentation>IFX_I32</xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:int"/>
        </xs:simpleType>
</xs:schema>


Using XMLSpy this works very well, can you help me ? Is my schema wrong?
Instead of using schema, if I use a DTD is there any way to validate the doc
using libxml2?

Thank You,

Luís Pinho



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]