Being introduced to XSDs [message #768136] |
Mon, 19 December 2011 16:31 |
d.shillcock Messages: 1 Registered: December 2011 |
Junior Member |
|
|
Hello everyone,
I am currently writing a document from XML and transforming it into a website. I have thus far been using a DTD to validate the document however that is reaching the limits of what I require. I am using XMLPad to write my XML/XSLT/DTD/XSD. Could someone point me in the right direction as to why this example code is not working?
Note: I've replaced the url with the word 'link' due to posting limits.
<?xml version="1.0"?>
<document xmlns:xsi="link.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="documentation.xsd">
<data>
<authors>
<author>
<name>Daniel Shillcock</name>
<email>d.shillcock@email.com</email>
</author>
</authors>
</data>
</document>
I would like a choice between authors and content elements. I have tried to implement this with the following XSD, however it is not producing the results I expect.
<?xml version="1.0"?>
<xs:schema xmlns:xs="link.w3.org/2001/XMLSchema">
<xs:element name="document">
<xs:complexType>
<xs:sequence>
<xs:element name="data" type="xs:anyType">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="authors" type="xs:anyType"/>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
</xs:sequence>
<xs:element name="content" type="xs:anyType"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I can't imagine how bad this looks to a trained eye. Any help is greatly appreciated!
[Updated on: Mon, 19 December 2011 16:36] Report message to a moderator
|
|
|
Re: Being introduced to XSDs [message #768153 is a reply to message #768136] |
Mon, 19 December 2011 16:57 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
Comments below.
On 19/12/2011 5:32 PM, d.shillcock wrote:
> Hello everyone,
>
> I am currently writing a document from XML and transforming it into a
> website. I have thus far been using a DTD to validate the document
> however that is reaching the limits of what I require. I am using
> XMLPad to write my XML/XSLT/DTD/XSD. Could someone point me in the
> right direction as to why this example code is not working?
>
> Note: I've replaced the url with the word 'link' due to posting limits.
>
> <?xml version="1.0"?>
> <document xmlns:xsi="link.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="documentation.xsd">
> <data>
> <authors>
> <author>
> <name>Daniel Shillcock</name>
> <email>d.shillcock@email.com</email>
> </author>
> </authors>
> </data>
> </document>
>
>
> I would like a choice between authors and content elements. I have
> tried to implement this with the following XSD, however it is not
> producing the results I expect.
>
>
>
> <?xml version="1.0"?>
>
> <xs:schema xmlns:xs="link.w3.org/2001/XMLSchema">
> <xs:element name="document">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="data" type="xs:anyType">
You can't have both a type attribute and an anonymous type, i.e., an
element can have only one type. Have you validated the XSD itself?
> <xs:complexType>
> <xs:choice>
> <xs:sequence>
> <xs:element name="auhors" type="xs:anyType"/>
Again a problem with there being more than one type for this element.
Clearly a type in your element name as well. And there's no nested
"author" element to be seen either.
> <xs:sequence>
> <xs:element name="name" type="xs:string"/>
> <xs:element name="email" type="xs:string"/>
> </xs:sequence>
> </xs:sequence>
> <xs:element name="content" type="xs:anyType"/>
> </xs:choice>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
> I can't imagine how bad this looks to a trained eye. Any help is
> greatly appreciated!
Note that this newsgroup is for asking questions about the XSD model's
API, not general, I need help with designing XML Schemas. It doesn't
look like you've even used XSD to validate your schema, so that would be
a good start to ensure you have something sensible before you start
wondering why your instances aren't validated properly.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03252 seconds