Jump to content
Sign in to follow this  
crr

schema help

Recommended Posts

Hi,

 

 

For the following XML block i was able to write the xsd code correctly:

-----------

 

<job><year>1990-1995</year><company>A1 University</company><job_title>Professor</job_title></job><job><year>1995-2010</year><company>A2 University</company><job_title>Head of Department</job_title></job><job><year>2011-Present</year><company>A3 University</company><job_title>Research</job_title></job>

------------

as:

 

<xsd:complexType name="jobtype"> <xsd:sequence> <xsd:element name="year" type="xsd:string"/> <xsd:element name="company" type="xsd:string"/> <xsd:element name="job_title" type="xsd:string"/> </xsd:sequence></xsd:complexType>

----------------

However if I want to enclose the XML block inside another tag (jobs) I am lost, can someone please help:

 

<jobs>

<job><year>1990-1995</year><company>A1 University</company><job_title>Professor</job_title></job><job><year>1995-2010</year><company>A2 University</company><job_title>Head of Department</job_title></job><job><year>2011-Present</year><company>A3 University</company><job_title>Research</job_title></job>

</jobs>

 

Thanks very much for any assistance.

 

 

Share this post


Link to post
Share on other sites

I don't work with XML much, but wouldn't you just wrap the entire schema inside the definition for a jobs element?

Share this post


Link to post
Share on other sites

This is how I got it to work :

 

<xsd:element name="jobs"> <xsd:complexType> <xsd:sequence> <xsd:element name="job" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="year" type="xsd:string"/> <xsd:element name="company" type="xsd:string"/> <xsd:element name="job_title" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType></xsd:element>

 

Thanks

Share this post


Link to post
Share on other sites

What did was fine; as you have proven, it works.

However, if the "jobs" element was one in a sequence, it would become obscured by the in-line element type definition. Since you already had a "jobtype" defined, you could have done the following:

<xsd:element name="jobs">    <xsd:complexType>        <xsd:sequence>            <xsd:element name="job" type="jobtype" maxOccurs="unbounded">        </xsd:sequence>    </xsd:complexType></xsd:element>

As you can see this is easier to read which in your case is not important, but in a larger sequence it is much cleaner to define the types of the elements in the sequence and then just name the elements with their occurrence restrictions.

 

I hope that this helps you and others with this type of problem in the future.

Share this post


Link to post
Share on other sites

What did was fine; as you have proven, it works.However, if the "jobs" element was one in a sequence, it would become obscured by the in-line element type definition. Since you already had a "jobtype" defined, you could have done the following:

<xsd:element name="jobs">    <xsd:complexType>        <xsd:sequence>            <xsd:element name="job" type="jobtype" maxOccurs="unbounded">        </xsd:sequence>    </xsd:complexType></xsd:element>
As you can see this is easier to read which in your case is not important, but in a larger sequence it is much cleaner to define the types of the elements in the sequence and then just name the elements with their occurrence restrictions. I hope that this helps you and others with this type of problem in the future.
Could you reword this?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×