Very basic question re: schema. Please advise...

  • Thread starter austris.bahanovskis
  • Start date
A

austris.bahanovskis

Hi,

I must apollgize beforehand for the basic question but i was strugling
to get my code fixed. I also must admit that this is my first .xml
attempt and i failed to find answers on MS support site or searching
this group.

So, i can't get the schema right for this datafile.
Data file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<country xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="country2.xsd">
<entry>
<name>China</name>
<population>22.2</population>
<continent>Asia</continent>
</entry>
<entry>
<name>France</name>
<population>12</population>
<continent>Europe</continent>
</entry>
</country>

And this is the schema (i'm sure i'm getting the ComplexType/child/
parent tags wrong):

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="country" type="Country"/>
<xs:complexType name="Country">
<xs:sequence>
<xs:element name="entry" type="Entry"/>
<xs:complexType name="Entry">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="population" type="xs:decimal"/>
<xs:element name="continent" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:sequence>
</xs:complexType>
</xs:schema>

I just haven't figured out the logic behind grouping the elements in
the schema file - any advise would be greatly appreciated.

Thanks!
A.
 
U

usenet

Hi,

...
And this is the schema (i'm sure i'm getting the ComplexType/child/
parent tags wrong):

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="country" type="Country"/>
<xs:complexType name="Country">
<xs:sequence>
<xs:element name="entry" type="Entry"/>
<xs:complexType name="Entry">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="population" type="xs:decimal"/>
<xs:element name="continent" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:sequence>
</xs:complexType>
</xs:schema>

I just haven't figured out the logic behind grouping the elements in
the schema file - any advise would be greatly appreciated.

You can either do:

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="country" type="Country"/>

<xs:complexType name="Country">
<xs:sequence>
<xs:element name="entry">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="population" type="xs:decimal"/>
<xs:element name="continent" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>

</xs:schema>

Or (possibly better):

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="country" type="Country"/>

<xs:complexType name="Country">
<xs:sequence>
<xs:element name="entry" type="Entry"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="Entry">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="population" type="xs:decimal"/>
<xs:element name="continent" type="xs:string"/>
</xs:sequence>
</xs:complexType>

</xs:schema>

Note that a named complexType can only be at the global level (a
direct child of the <schema> element). If you want a complexType to
be local to an element, then don't give it a name, don't use type= on
the <element> element, and have the complexType a child of the
<element> element.

HTH,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx/
http://www.codalogic.com/lmx/
=============================================
 
A

austris.bahanovskis

You can either do:

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="country" type="Country"/>

<xs:complexType name="Country">
<xs:sequence>
<xs:element name="entry">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="population" type="xs:decimal"/>
<xs:element name="continent" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>

</xs:schema>

Or (possibly better):

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="country" type="Country"/>

<xs:complexType name="Country">
<xs:sequence>
<xs:element name="entry" type="Entry"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="Entry">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="population" type="xs:decimal"/>
<xs:element name="continent" type="xs:string"/>
</xs:sequence>
</xs:complexType>

</xs:schema>

Note that a named complexType can only be at the global level (a
direct child of the <schema> element). If you want a complexType to
be local to an element, then don't give it a name, don't use type= on
the <element> element, and have the complexType a child of the
<element> element.

HTH,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visithttp://www.tech-know-ware.com/lmx/http://www.codalogic.com/lmx/
=============================================


Thanks Pete!
But it still says (in both cases) when I refresh the list (with
validation) in .xls:
Error Code : -1072898028
URL : >not-supplied>
Reason : Element 'entry' is unexpected according to content model of
parent element ' country'.
Line : 0
Column : 0
File Offset : 0

Any idea?

It goes without saying that your help is greately appreciated!

Austris
 
U

usenet

Thanks Pete!
But it still says (in both cases) when I refresh the list (with
validation) in .xls:
Error Code : -1072898028
URL : >not-supplied>
Reason : Element 'entry' is unexpected according to content model of
parent element ' country'.
Line : 0
Column : 0
File Offset : 0

Any idea?

It goes without saying that your help is greately appreciated!

Austris- Hide quoted text -

- Show quoted text -

This is a problem with the number of occurences of entry that the
schema is expecting the xml instance to have.

Try changing the line:

<xs:element name="entry" type="Entry"/>

to:

<xs:element name="entry" type="Entry" minOccurs="0"
maxOccurs="unbounded"/>

HTH,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx/
http://www.codalogic.com/lmx/
=============================================
 
A

austris.bahanovskis

This is a problem with the number of occurences of entry that the
schema is expecting the xml instance to have.

Try changing the line:

<xs:element name="entry" type="Entry"/>

to:

<xs:element name="entry" type="Entry" minOccurs="0"
maxOccurs="unbounded"/>

HTH,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visithttp://www.tech-know-ware.com/lmx/http://www.codalogic.com/lmx/
=============================================

That was it!!
Thanks a lot! What i really like about these groups is that people
actually do respond and help!
Thanks again!
 

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

Forum statistics

Threads
474,008
Messages
2,570,268
Members
46,867
Latest member
Lonny Petersen

Latest Threads

Top