Is XML Doc wrong or is Schema wrong? (or both)

Discussion in 'XML' started by Matthew, Dec 18, 2004.

  1. Matthew

    Matthew Guest

    I am writing an XML schema to describe the format of entries in a
    reference of Japanese grammar. I finished the Schema for the most
    part, and it validates correctly as a Schema document.

    However, I tried writing a sample XML document based on the Schema, but
    every parser I run it through says that none of my tags have been
    defined. I'm sure I'm missing something simple, but I'm stumped. I
    have tired several methods of tieing the XML doc to the schema (none of
    which really made much sense to me). What is the best way to do this?

    Here are copies of the schema and the XML sample: (note, the sample
    contains Japanese characters)

    --- schema ---
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsd:annotation>
    <xsd:documentation xml:lang="en">
    XML Schema for Japanese Grammar Reference Entry
    Revision 0.1a
    </xsd:documentation>
    </xsd:annotation>

    <xsd:complexType name="reference">
    <xsd:sequence>
    <xsd:element name="referenceEntry" type="referenceEntryType"
    minOccurs="0" maxOccurs="unbounded" />
    </xsd:sequence>
    <xsd:attribute name="revision" type="xsd:string" use="required" />
    <xsd:attribute name="abridged" type="xsd:boolean" use="required" />
    </xsd:complexType>

    <xsd:complexType name="referenceEntryType">
    <xsd:sequence>
    <xsd:element name="entry" type="entryType" maxOccurs="unbounded" />
    <xsd:element name="definition" type="definitionType" maxOccurs="unbounded" />
    <xsd:element name="usageNotes" type="usageNotesType" maxOccurs="unbounded" />
    <xsd:element name="example" type="exampleType" maxOccurs="unbounded"
    nillable="true" />
    <xsd:element name="relatedForms" type="relatedFormsType"
    maxOccurs="unbounded" nillable="true"/>
    </xsd:sequence>
    <xsd:attributeGroup ref="referenceAttributeGroup" />
    </xsd:complexType>

    <xsd:attributeGroup name="referenceAttributeGroup"
    id="referenceAttributeGroup">
    <xsd:attribute name="id" type="xsd:positiveInteger" use="required" />
    <xsd:attribute name="vulgar" type="xsd:boolean" use="optional"
    default="false" />
    <xsd:attribute name="colloquial" type="xsd:boolean" use="optional"
    default="false" />
    <xsd:attribute name="archaic" type="xsd:boolean" use="optional"
    default="false" />
    <xsd:attribute name="juvenile" type="xsd:boolean" use="optional"
    default="false" />
    </xsd:attributeGroup>

    <xsd:complexType name="entryType" mixed="true">
    <xsd:sequence>
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
    <xsd:element name="noun" type="nounType" />
    <xsd:element name="verb" type="verbType" />
    <xsd:element name="adjective" type="adjectiveType" />
    <xsd:element name="adverb" type="adverbType" />
    <xsd:element name="conjunction" type="conjunctionType" />
    <xsd:element name="interjection" type="interjectionType" />
    <xsd:element name="subsentence" type="subsentenceType" />
    <xsd:element name="clause" type="clauseType" />
    </xsd:choice>
    </xsd:sequence>
    <xsd:attribute name="gender" type="genderType" use="optional"
    default="neutral" />
    </xsd:complexType>

    <xsd:simpleType name="genderType">
    <xsd:restriction base="xsd:string">
    <xsd:enumeration value="male" />
    <xsd:enumeration value="female" />
    <xsd:enumeration value="neutral" />
    </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="nounType">
    <xsd:complexContent>
    <xsd:restriction base="xsd:anyType">
    <!-- empty marker -->
    </xsd:restriction>
    </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="verbType">
    <xsd:complexContent>
    <xsd:restriction base="xsd:anyType">
    <xsd:attribute name="verbConjugation" type="verbConjugationType"
    use="required" />
    <xsd:attribute name="verbQuality" type="verbQualityType"
    use="optional" default="n/a" />
    <xsd:attribute name="verbFormality" type="verbFormalityType"
    use="optional" default="n/a" />
    </xsd:restriction>
    </xsd:complexContent>
    </xsd:complexType>

    <xsd:simpleType name="verbConjugationType">
    <xsd:restriction base="xsd:string">
    <xsd:enumeration value="non-past" />
    <xsd:enumeration value="past" />
    <xsd:enumeration value="te-form" />
    <xsd:enumeration value="conditional" />
    <xsd:enumeration value="provisional" />
    <xsd:enumeration value="potential" />
    <xsd:enumeration value="passive" />
    <xsd:enumeration value="causative" />
    <xsd:enumeration value="causative-passive" />
    <xsd:enumeration value="volitional" />
    <xsd:enumeration value="conjectural" />
    <xsd:enumeration value="alternative" />
    <xsd:enumeration value="imperative" />
    </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="verbQualityType">
    <xsd:restriction base="xsd:string">
    <xsd:enumeration value="affirmative" />
    <xsd:enumeration value="negative" />
    <xsd:enumeration value="n/a" />
    </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="verbFormalityType">
    <xsd:restriction base="xsd:string">
    <xsd:enumeration value="informal" />
    <xsd:enumeration value="formal" />
    <xsd:enumeration value="n/a" />
    </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="adjectiveType">
    <xsd:complexContent>
    <xsd:restriction base="xsd:anyType">
    <xsd:attribute name="adjectiveGroup" type="adjectiveGroupType"
    use="required" />
    <xsd:attribute name="adjectiveConjugation"
    type="adjectiveConjugationType" use="required" />
    <xsd:attribute name="adjectiveQuality" type="adjectiveQualityType"
    use="required" />
    </xsd:restriction>
    </xsd:complexContent>
    </xsd:complexType>

    <xsd:simpleType name="adjectiveGroupType">
    <xsd:restriction base="xsd:string">
    <xsd:enumeration value="i-adjective" />
    <xsd:enumeration value="na-adjective" />
    </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="adjectiveConjugationType">
    <xsd:restriction base="xsd:string">
    <xsd:enumeration value="plain" />
    <xsd:enumeration value="te-form" />
    <xsd:enumeration value="adverbial" />
    </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="adjectiveQualityType">
    <xsd:restriction base="xsd:string">
    <xsd:enumeration value="affirmative" />
    <xsd:enumeration value="negative" />
    </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="adverbType">
    <xsd:complexContent>
    <xsd:restriction base="xsd:anyType">
    <!-- empty marker -->
    </xsd:restriction>
    </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="conjunctionType">
    <xsd:complexContent>
    <xsd:restriction base="xsd:anyType">
    <!-- empty marker -->
    </xsd:restriction>
    </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="interjectionType">
    <xsd:complexContent>
    <xsd:restriction base="xsd:anyType">
    <!-- empty marker -->
    </xsd:restriction>
    </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="subsentenceType">
    <xsd:complexContent>
    <xsd:restriction base="xsd:anyType">
    <!-- empty marker -->
    </xsd:restriction>
    </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="clauseType">
    <xsd:complexContent>
    <xsd:restriction base="xsd:anyType">
    <!-- empty marker -->
    </xsd:restriction>
    </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="definitionType">
    <xsd:simpleContent>
    <xsd:extension base="xsd:string">
    <xsd:attribute name="language" type="xsd:language" use="required" />
    </xsd:extension>
    </xsd:simpleContent>
    </xsd:complexType>

    <xsd:complexType name="usageNotesType">
    <xsd:simpleContent>
    <xsd:extension base="xsd:string">
    <xsd:attribute name="language" type="xsd:language" use="required" />
    </xsd:extension>
    </xsd:simpleContent>
    </xsd:complexType>

    <xsd:complexType name="exampleType">
    <xsd:sequence>
    <xsd:element name="japaneseSentence" type="japaneseSentenceType" />
    <xsd:element name="translatedSentence" type="translationStringType"
    maxOccurs="unbounded" nillable="true" />
    <xsd:element name="source" type="xsd:string" />
    </xsd:sequence>
    <xsd:attribute name="trusted" type="xsd:boolean" use="optional"
    default="false" />
    </xsd:complexType>

    <xsd:complexType name="japaneseSentenceType" mixed="true">
    <xsd:sequence>
    <xsd:element name="kanjiReading" type="xsd:string" minOccurs="0"
    maxOccurs="unbounded" />
    <xsd:element name="usage" type="xsd:string" maxOccurs="unbounded" />
    <xsd:element name="kanjiReading" type="xsd:string" minOccurs="0"
    maxOccurs="unbounded" />
    </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="translationStringType">
    <xsd:simpleContent>
    <xsd:extension base="xsd:string">
    <xsd:attribute name="language" type="xsd:language" use="required" />
    </xsd:extension>
    </xsd:simpleContent>
    </xsd:complexType>

    <xsd:complexType name="relatedFormsType">
    <xsd:complexContent>
    <xsd:restriction base="xsd:anyType">
    <xsd:attribute name="id" type="xsd:positiveInteger" use="required" />
    </xsd:restriction>
    </xsd:complexContent>
    </xsd:complexType>

    </xsd:schema>
    --- schema ---

    --- sample ---
    <?xml version="1.0" encoding="utf-8"?>

    <reference revision="0.1a" abridged="true">

    <referenceEntry id="0" vulgar="false" colloquial="false"
    archaic="false" juvenile="false">
    <entry gender="neutral">
    <verb verbConjugation="te-form" verbQuality="n/a" verbFormality="n/a" />??
    </entry>
    <definition language="en-us">after</definition>
    <usageNotes language="en-us">This form expresses the order of a
    sequece of 2 actions.</usageNotes>
    <example trusted="true">
    <japaneseSentence>
    <ruby><rb>??</rb><rt>???</rt>?<rb>?</rb><rt>???</rt>??<rb>???</rb><rt>?????</rt>????<usage>??</usage><rb>?</rb><rt>?</rt>????</ruby>
    </japaneseSentence>
    <translatedSentence

    </japaneseSentence>
    <translatedSentence language="en-us">
    I came today after breakfast.
    </translatedSentence>
    <source>Unknown</source>
    </example>
    <example trusted="true">
    <japaneseSentence>
    <ruby>????<rb>?</rb><rt>??</rt>???????<rb>?</rb><rt>??</rt>?<rb>??</rb><rt>????</rt>????<usage>??</usage><rb>?</rb><rt>?</rt>????</ruby>
    </japaneseSentence>
    <translatedSentence

    </japaneseSentence>
    <translatedSentence language="en-us">
    After I become a little more skillful, I will buy such a guitar.
    </translatedSentence>
    <source>Unknown</source>
    </example>
    <example trusted="false">
    <japaneseSentence>
    <ruby>????<rb>??</rb><rt>??</rt>?<rb>?</rb><rt>?</rt>??<usage>??</usage><rb>?</rb><rt>?</rt>????</ruby>
    </japaneseSentence>
    <translatedSentence

    </japaneseSentence>
    <translatedSentence language="en-us">
    After Godzilla ate the city, he went to sleep!
    </translatedSentence>
    <source>Unknown</source>
    </example>
    <relatedForms id="" />
    </referenceEntry>

    </reference>
    --- sample ---
    Matthew, Dec 18, 2004
    #1
    1. Advertising

  2. You don't actually show _any_ connection between your instance
    document and your schema document.

    Some tools (e.g. XSV [1]) will let you specify both on the command
    line.

    W3C XML Schema provides the schemaLocation and
    noNamespaceSchemaLocation attributes in the
    http://www.w3.org/2001/xmlschema-instance namespace to make
    instance->schema document connections explicit -- have you tried this?

    <reference revision="0.1a" abridged="true"
    xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
    xsi:noNamespaceSchemaLocation="[URL for your schema document]">

    ht
    --
    Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
    Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    Fax: (44) 131 650-4587, e-mail:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
    Henry S. Thompson, Dec 20, 2004
    #2
    1. Advertising

  3. Matthew

    Matthew Cook Guest

    On 2004-12-20 00:56:51 -0600, (Henry S. Thompson) said:

    > You don't actually show _any_ connection between your instance
    > document and your schema document.


    I have tired a few, I took them out for posting clarity.

    > Some tools (e.g. XSV [1]) will let you specify both on the command
    > line.


    Thanks, I'll check it out.

    > W3C XML Schema provides the schemaLocation and
    > noNamespaceSchemaLocation attributes in the
    > http://www.w3.org/2001/xmlschema-instance namespace to make
    > instance->schema document connections explicit -- have you tried this?


    I tried this format, however, I don't have web-space to store the
    schema. I tried using just the file name, or various incarnations of
    the localhost URL, but I don't run a web server locally either. Is
    there some other method? Or better yet, some kind of central server
    akin to a PGP key server?
    Matthew Cook, Dec 20, 2004
    #3
  4. Matthew

    Matthew Cook Guest

    Namespace and Schema Confusion (was: Is XML Doc wrong or ...)

    I am having a great deal of trouble trying to validate an XML document
    against a Schema that I wrote. I can't seem to figure out how to
    connect the XML document to the Schema correctly. So far this is what I
    have:

    I have a Schema that validates correctly and starts out like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <!-- stuff -->
    </xsd:schema>

    I have placed this schema document on the web at <mysite>.com/<title>.xsd

    Next I have my XML document which starts out like this:
    <?xml version="1.0" encoding="utf-8"?>

    <reference revision="0.1a" abridged="true"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://<mysite>.com/<title>.xsd">
    <!-- stuff -->
    </reference>

    The revision and abridged stuff is from my Schema, from what I can tell,
    the xmlns attribute will tie the xsi namespace to some schema or DTD at
    w3.org thought I'm not sure why it points to a folder and not a specific
    document. I'm not sure exactly what's going on with that xsi: part.

    With this set up, when I got to validate my XML document (i've been
    using http://apps.gotdotnet.com/xmltools/xsdvalidator/ but all seem to
    be about the same), the validater comes back saying that every tag and
    attribute in my XML document instance is not defined.

    I have been pouring over tutorials and manuals from w3.org and others,
    but everything i can find either leaves this stuff out of examples
    figuring that everyone knows it, or gets into complicated namespace
    stuff. I don't think I need a lot of namespace stuff as everything
    should be defined in the Schema but I could be wrong. Any pointers
    would be greatly appreciated.
    Matthew Cook, Dec 22, 2004
    #4
  5. Re: Namespace and Schema Confusion

    Matthew Cook wrote:

    > I am having a great deal of trouble trying to validate an XML document
    > against a Schema that I wrote. I can't seem to figure out how to
    > connect the XML document to the Schema correctly.
    > With this set up, when I got to validate my XML document (i've been
    > using http://apps.gotdotnet.com/xmltools/xsdvalidator/ but all seem to
    > be about the same), the validater comes back saying that every tag and
    > attribute in my XML document instance is not defined.


    That page has three input fields, you are supposed to upload your XML
    file and your XML schema file there to do the validation. I don't think
    xsi:noNamespaceSchemaLocation is of any help on that page.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Dec 22, 2004
    #5
  6. Matthew

    Matthew Cook Guest

    Re: Namespace and Schema Confusion

    Martin Honnen wrote:
    >
    > Matthew Cook wrote:
    >
    >
    >>I am having a great deal of trouble trying to validate an XML document
    >>against a Schema that I wrote. I can't seem to figure out how to
    >>connect the XML document to the Schema correctly.
    >>With this set up, when I got to validate my XML document (i've been
    >>using http://apps.gotdotnet.com/xmltools/xsdvalidator/ but all seem to
    >>be about the same), the validater comes back saying that every tag and
    >>attribute in my XML document instance is not defined.

    >
    >
    > That page has three input fields, you are supposed to upload your XML
    > file and your XML schema file there to do the validation. I don't think
    > xsi:noNamespaceSchemaLocation is of any help on that page.
    >


    I have tired uploading one and uploading both, the results are the same.

    I also tried using xmllint to validate the document, but no luck:

    titanium:~ admin$ xmllint --schema mojibake.xsd reference.xml
    <reference xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    revision="0.1a" abridged="true"
    xsi:noNamespaceSchemaLocation="http://xn--m3h.net/mojibake.xsd">

    .... output of my xml file ...

    </reference>
    reference.xml:5: element reference: Schemas validity error : Element
    reference not declared
    reference.xml:5: element reference: Schemas validity error : Element
    reference not declared
    reference.xml fails to validate
    titanium:~ admin$

    "reference" on line 5 is the first tag of my XML file. I'm pretty sure
    it's some simple thing wrong, I just can't for the life of me figure out
    what.
    Matthew Cook, Dec 22, 2004
    #6
  7. Re: Namespace and Schema Confusion

    Your files look ok, at the level you've described them. Have you
    tried the XSV web form [1]?

    ht

    [1] http://www.w3.org/2001/03/webdata/xsv
    --
    Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
    Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    Fax: (44) 131 650-4587, e-mail:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
    Henry S. Thompson, Jan 7, 2005
    #7
  8. Re: Namespace and Schema Confusion (was: Is XML Doc wrong or ...)

    Hello,

    I don't see any actual declaration for a "reference" element in your
    schema. You have a complex type named "reference", but that is not the
    same thing.

    If you add:

    <xsd:element name="reference" type="reference"/>

    at the top level of your schema, does it work then?

    Hope that helps,
    Priscilla

    ----------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema
    http://www.datypic.com
    ----------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Priscilla Walmsley, Jan 7, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page