Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » Being introduced to XSDs(I am struggling at the first hurdle!)
Being introduced to XSDs [message #768136] Mon, 19 December 2011 16:31 Go to next message
d.shillcock is currently offline d.shillcockFriend
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 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
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/
Previous Topic:Serialize XSD Object
Next Topic:xpath error
Goto Forum:
  


Current Time: Tue Mar 19 04:28:42 GMT 2024

Powered by FUDForum. Page generated in 0.02825 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top