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

Matthew

Usenet Archive
Joined
May 1, 2000
Messages
95
Reaction score
0
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 ---
 

Henry S. Thompson

Usenet Archive
Joined
Jan 14, 2000
Messages
309
Reaction score
0
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
 

Matthew Cook

Usenet Archive
Joined
Apr 16, 2003
Messages
10
Reaction score
0
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

Usenet Archive
Joined
Apr 16, 2003
Messages
10
Reaction score
0
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.
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Matthew said:
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.
 

Matthew Cook

Usenet Archive
Joined
Apr 16, 2003
Messages
10
Reaction score
0
Martin said:
Matthew Cook wrote:

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.
 

Priscilla Walmsley

Usenet Archive
Joined
Apr 15, 2004
Messages
77
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top