convert dtd to schema xml


Hello guys,

can any one help to convert the following dtd into a schema ?
<!ELEMENT medicare (medicare-card)+>
<!ELEMENT medicare-card (card-info,name,date-of-birth,contact,medical-info)>
<!ELEMENT card-info (expiry-date)>
<!ATTLIST card-info id ID #REQUIRED
					 type (Reciprocal | Interim) #REQUIRED> 
<!ELEMENT expiry-date (#PCDATA)>
<!ELEMENT name ((lname),(mname)?,(fname))>
<!ATTLIST name gender (Male|Female) #REQUIRED>
<!ELEMENT lname (#PCDATA)>
<!ELEMENT mname (#PCDATA)>
<!ELEMENT fname (#PCDATA)>

<!ELEMENT date-of-birth (#PCDATA)>
<!ELEMENT contact (address,telephone,email)>
<!ELEMENT address (street,city,state,zipcode) >
<!ELEMENT street (#PCDATA) >
<!ELEMENT city (#PCDATA) >
<!ELEMENT state (#PCDATA) >
<!ELEMENT zipcode (#PCDATA) >
<!ELEMENT telephone (#PCDATA) >
<!ELEMENT email EMPTY >
<!ATTLIST email href CDATA #REQUIRED preferred (true|false) "true">
<!ELEMENT medical-info ( blood,(allergy)? ,(chronic-illness)*)>
<!ELEMENT blood EMPTY>
<!ATTLIST blood type (Opositive|Onegative|Apositive|Anegative|Bpositive|Bnegative|ABpositive|ABnegative) #REQUIRED>
<!ELEMENT allergy (#PCDATA) >
<!ELEMENT chronic-illness (#PCDATA)>

Open in new window

AussieSilverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nishantdewanCommented:
<?xml version="1.0" encoding="UTF-8" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="address">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="street" />
        <xs:element ref="city" />
        <xs:element ref="state" />
        <xs:element ref="zipcode" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="allergy">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="blood">
    <xs:complexType>
      <xs:attribute name="type" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:NMTOKEN">
            <xs:enumeration value="Opositive" />
            <xs:enumeration value="Onegative" />
            <xs:enumeration value="Apositive" />
            <xs:enumeration value="Anegative" />
            <xs:enumeration value="Bpositive" />
            <xs:enumeration value="Bnegative" />
            <xs:enumeration value="ABpositive" />
            <xs:enumeration value="ABnegative" />
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

  <xs:element name="card-info">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="expiry-date" />
      </xs:sequence>
      <xs:attribute name="type" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:NMTOKEN">
            <xs:enumeration value="Reciprocal" />
            <xs:enumeration value="Interim" />
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="id" type="xs:ID" use="required" />
    </xs:complexType>
  </xs:element>

  <xs:element name="chronic-illness">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="city">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="contact">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="address" />
        <xs:element ref="telephone" />
        <xs:element ref="email" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="date-of-birth">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="email">
    <xs:complexType>
      <xs:attribute name="href" type="xs:string" use="required" />
      <xs:attribute name="preferred" use="optional" default="true">
        <xs:simpleType>
          <xs:restriction base="xs:NMTOKEN">
            <xs:enumeration value="true" />
            <xs:enumeration value="false" />
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

  <xs:element name="expiry-date">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="fname">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="lname">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="medical-info">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="blood" />
        <xs:sequence>
          <xs:element ref="allergy" />
        </xs:sequence>
        <xs:sequence>
          <xs:element ref="chronic-illness" />
        </xs:sequence>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="medicare">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="medicare-card" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="medicare-card">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="card-info" />
        <xs:element ref="name" />
        <xs:element ref="date-of-birth" />
        <xs:element ref="contact" />
        <xs:element ref="medical-info" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="mname">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="name">
    <xs:complexType>
      <xs:sequence>
        <xs:sequence>
          <xs:element ref="lname" />
        </xs:sequence>
        <xs:sequence>
          <xs:element ref="mname" />
        </xs:sequence>
        <xs:sequence>
          <xs:element ref="fname" />
        </xs:sequence>
      </xs:sequence>
      <xs:attribute name="gender" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:NMTOKEN">
            <xs:enumeration value="Male" />
            <xs:enumeration value="Female" />
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

  <xs:element name="state">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="street">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="telephone">
    <xs:complexType mixed="true" />
  </xs:element>

  <xs:element name="zipcode">
    <xs:complexType mixed="true" />
  </xs:element>

</xs:schema>
0
AussieSilverAuthor Commented:
sounds good

I need the following restrictions please;

1. A unique identifier – Medicare card number, which must begin with a capital letter
followed by 8 digits;
2. Medicare card type, which must be either “Reciprocal” or “Interim”;
3. Expiry data, which must be in the standard format “YYYY-MM-DD”;
4. Up to 9 persons can be included under the one Medicare card number (Note: persons
grouped under one Medicare card number are often a family);
5. For each person, the following information should be included in the given order:
Personal information
1) Name: last name and first name are required, middle initial is optional.
2) Gender is required, which must be either “Male” or “Female”;
3) Date of birth is required and must be in the standard form “YYYY-MM-DD”;
4) Contact information includes:
a) Mail address, which consists of street, city, state, and 4-digit zip code.
b) Telephone
c) Email
(Note: you should use element attribute to specify the preferred contact method.)
Medical information:
1) Blood type is required and must be one of the following:
• Opositive
• Onegative
• Apositive
• Anegative
• Bpositive
• Bnegative
• ABpositive
• ABnegative
2) Allergy information
3) Chronic illness
0
AussieSilverAuthor Commented:
Hi,

Why the code is not ordered in a sequence as dtd? please help me to finish it asap
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Geert BormansInformation ArchitectCommented:
It is not ordered for two reasons
- ordering of element declarations in XML Schema is not important
- the transform DTD to schema was done by a tool (I suspect Trang) not by hand
Whoever did this would have better ordered the elements logical, to make the Schema more understandable, but you can do that yourself

Here are the restrictions you need

First two...
note that I made the attributes as I suggested in your earlier questio
also note that I force the attribute id to be unique using xs:key. It is superior over using xs:id, as in one of your other questions
    <xs:element name="medicare-card">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="name" />
                <xs:element ref="date-of-birth" />
                <xs:element ref="contact" />
                <xs:element ref="medical-info" />
            </xs:sequence>
            <xs:attribute name="type" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="Reciprocal"/>
                        <xs:enumeration value="Interim"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="id" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:pattern value="[A-Z][0-9]{8}"></xs:pattern>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
        <xs:unique name="unique-id">
            <xs:selector xpath="medicare-card"></xs:selector>
            <xs:field xpath="@id"></xs:field>
        </xs:unique>
    </xs:element>

Open in new window

0
Geert BormansInformation ArchitectCommented:
expiry date.

Looking at the schema, I now must say the tool used was NOT Trang, it likely is an Altova tool, the DTD to schema transformation really sucks

Please get rid of all the #PCDATA that are transformed to complex types
<xs:element name="expiry-date">
    <xs:complexType mixed="true" />
  </xs:element>
This is pure nonsense
- it is a simpleType content
- the first response makes this a complexType with zero content and mixed is true
This is opening a can of worms if you want to do schema aware processing with the resulting XML, or databinding or type inheritance.
Please please please, remove all the complexTypes with mixed=true. These are not mixed content models, these are simple types

For expiry date this is all you need
    <xs:element name="expiry-date" type="xs:date"/>
this will not only check the syntactical form YYYY-MM-DD, but will also disallow illegal dates such as 1999-99-99
0
Geert BormansInformation ArchitectCommented:
Here is another reason why I said earlier that it is not a good idea to model this in DTD.
In schema you can be very precise about the maximal occurence of a certain element in a container
Note that I created a family in which you can have up to 9 person elements
<xs:element name="medicare-card"> 
        <xs:complexType> 
            <xs:sequence> 
                <xs:element ref="expiry-date" />
                <xs:element ref="family"/>
            </xs:sequence> 
            <xs:attribute name="type" use="required"> 
                <xs:simpleType> 
                    <xs:restriction base="xs:string"> 
                        <xs:enumeration value="Reciprocal"/> 
                        <xs:enumeration value="Interim"/> 
                    </xs:restriction> 
                </xs:simpleType> 
            </xs:attribute> 
            <xs:attribute name="id" use="required"> 
                <xs:simpleType> 
                    <xs:restriction base="xs:string"> 
                        <xs:pattern value="[A-Z][0-9]{8}"></xs:pattern> 
                    </xs:restriction> 
                </xs:simpleType> 
            </xs:attribute> 
        </xs:complexType> 
        <xs:unique name="unique-id"> 
            <xs:selector xpath="medicare-card"></xs:selector> 
            <xs:field xpath="@id"></xs:field> 
        </xs:unique> 
    </xs:element>
    <xs:element name="expiry-date" type="xs:date"/>
    <xs:element name="family">
        <xs:complexType>
            <xs:sequence minOccurs="1" maxOccurs="9">
                <xs:element ref="person"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="person">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="date-of-birth" /> 
                <xs:element ref="contact" /> 
                <xs:element ref="medical-info" /> 
            </xs:sequence>
        </xs:complexType>
    </xs:element>

Open in new window

0
Geert BormansInformation ArchitectCommented:
I have added some hints to how to do the rest
<xs:element name="person">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="name" /> 
                <xs:element ref="date-of-birth" /> 
                <xs:element ref="contact" /> 
                <xs:element ref="medical-info" /> 
            </xs:sequence>
            <xs:attribute name="gender" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="male"/>
                        <xs:enumeration value="female"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <xs:element name="date-of-birth" type="xs:date"/>
    <xs:element name="contact">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="mail"/>
                <xs:element ref="telephone"/>
                <xs:element ref="email"/>
            </xs:sequence>
            <xs:attribute name="preferred">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="mail"/>
                        <xs:enumeration value="telephone"/>
                        <xs:enumeration value="email"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert BormansInformation ArchitectCommented:
Note, you now have enough hints to construct the full schema yourself.
That should be sufficient, EE is not there to provide full working solutions, just enough to get you going yourself is what we do. And you are at the stage that you have to bring the little bits together and you are done

But again, throw out every declaration like this
<xs:element name="street">
    <xs:complexType mixed="true" />
  </xs:element>
in favour of
<xs:element name="street" type="xs:string"/>
It will save you a lot of trouble later
0
AussieSilverAuthor Commented:
Hi, I kinda understood the codes but they actually confused me.... would you mid to put all codes all together for a better understanding ?
0
AussieSilverAuthor Commented:
Sorry,

I really got confused... those codes seem different... please help me to collect them together based in the requirement....
0
AussieSilverAuthor Commented:
Gertone:

I really need your kind help ....
0
AussieSilverAuthor Commented:
Gertone:

It seems I can now group them together to have a full code... Once i finish the code and need some help I will post a new thread.....
0
Geert BormansInformation ArchitectCommented:
I was not around yesterday afternoon.
The code indeed is not that hard to compile.
Just give sign when you need help
I am on holidays now so not tracking as frequent as usual, so you might need some patience
0
AussieSilverAuthor Commented:
please help on thread titled:

 xml schema - required fields

ID:          25722000

0
Geert BormansInformation ArchitectCommented:
the answer given by robinu is correct
0
AussieSilverAuthor Commented:
not working....

and where should i put it exactly???
0
Geert BormansInformation ArchitectCommented:
ask there my friend
If you post a follow up there, I can step in,
I can't correct something I think is correct, that would be nice for robinu :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.