DTD to XML

Discussion in 'XML' started by Ritu, Sep 2, 2004.

  1. Ritu

    Ritu Guest

    Hello Folks,

    I am struggling to convert an existing DTD file to the XSD format. I
    encountered some problems and was hoping someone could help me out
    here.

    I am using XMLspy to create the schema.

    My original DTD statement looks like this

    <!ELEMENT AC_RECORD_ID (#PCDATA)>
    <!ATTLIST AC_RECORD_ID
    e-dtype NMTOKEN #FIXED "int"
    >




    In XSD I represent this by adding an atrribute to the AC_RECORD_ID
    element as in

    <xs:complex type name="PHRASE">
    <xs:sequence>
    <xs:element name="AC_RECORD_ID">
    <xs:complexType>
    <xs:attribute name="e-dtype" type="xs:NMTOKEN" fixed="int"/>
    </xs:complexType>
    </xs:element>
    .... other elements
    </xs:sequence>
    </xs:complexType>

    When I try to validate my XML against this I get the following error

    "unexpected element contents - AC_RECORD_ID is defined as EMPTY"

    The XML block that gives this error is

    <AC_RECORD_ID>124</AC_RECORD_ID>


    My problem is that I have not defined AC_RECORD_ID to be empty
    anywhere. Why does adding an attribute to it trigger this error?. Is
    there something missed out in the definition? If I remove the
    attribute the XML piece validates without problem.

    I would really appreciate any pointers in this direction.

    Cheers
    Ritu
     
    Ritu, Sep 2, 2004
    #1
    1. Advertising

  2. Ritu

    Ed Day Guest

    I think the problem is that you do not have any content defined for
    the element. Therefore, the only thing that is allowed is a null
    element with a single attribute. You can use simpleContent to add an
    attribute to a simple base type as follows:

    <xs:complex type name="PHRASE">
    <xs:sequence>
    <xs:element name="AC_RECORD_ID">
    <xs:complexType>
    <xs:simpleContent>
    <xs:extension base="xs:string">
    <xs:attribute name="e-dtype" type="xs:NMTOKEN"
    fixed="int"/>
    </xs:extension>
    </xs:simpleContent>
    </xs:complexType>
    </xs:element>
    ... other elements
    </xs:sequence>
    </xs:complexType>

    Regards,

    Ed Day
    Objective Systems, Inc.


    (Ritu) wrote in message news:<>...
    > Hello Folks,
    >
    > I am struggling to convert an existing DTD file to the XSD format. I
    > encountered some problems and was hoping someone could help me out
    > here.
    >
    > I am using XMLspy to create the schema.
    >
    > My original DTD statement looks like this
    >
    > <!ELEMENT AC_RECORD_ID (#PCDATA)>
    > <!ATTLIST AC_RECORD_ID
    > e-dtype NMTOKEN #FIXED "int"
    > >

    >
    >
    >
    > In XSD I represent this by adding an atrribute to the AC_RECORD_ID
    > element as in
    >
    > <xs:complex type name="PHRASE">
    > <xs:sequence>
    > <xs:element name="AC_RECORD_ID">
    > <xs:complexType>
    > <xs:attribute name="e-dtype" type="xs:NMTOKEN" fixed="int"/>
    > </xs:complexType>
    > </xs:element>
    > ... other elements
    > </xs:sequence>
    > </xs:complexType>
    >
    > When I try to validate my XML against this I get the following error
    >
    > "unexpected element contents - AC_RECORD_ID is defined as EMPTY"
    >
    > The XML block that gives this error is
    >
    > <AC_RECORD_ID>124</AC_RECORD_ID>
    >
    >
    > My problem is that I have not defined AC_RECORD_ID to be empty
    > anywhere. Why does adding an attribute to it trigger this error?. Is
    > there something missed out in the definition? If I remove the
    > attribute the XML piece validates without problem.
    >
    > I would really appreciate any pointers in this direction.
    >
    > Cheers
    > Ritu
     
    Ed Day, Sep 3, 2004
    #2
    1. Advertising

  3. Ritu

    Ritu Guest

    (Ed Day) wrote in message news:<>...
    > I think the problem is that you do not have any content defined for
    > the element. Therefore, the only thing that is allowed is a null
    > element with a single attribute. You can use simpleContent to add an
    > attribute to a simple base type as follows:


    Thanks Ed, this does work!

    Regards
    Ritu
     
    Ritu, Sep 8, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Jessel
    Replies:
    0
    Views:
    418
    Ben Jessel
    Aug 5, 2004
  2. Joseph Tilian
    Replies:
    0
    Views:
    360
    Joseph Tilian
    Dec 21, 2004
  3. Ronald Fischer
    Replies:
    4
    Views:
    1,772
    Ronald Fischer
    Mar 17, 2005
  4. Syntext, Inc
    Replies:
    0
    Views:
    381
    Syntext, Inc
    Aug 21, 2003
  5. test
    Replies:
    2
    Views:
    2,083
    Oliver Wong
    Jul 28, 2006
Loading...

Share This Page