Jump to content

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.

 

 

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

Link to post
Share on other sites
  • 8 months later...

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.

Link to post
Share on other sites
  • 2 weeks later...
  • 3 weeks later...

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?
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...