Reputation: 269
I have this DTD:
<!DOCTYPE a [
<!ELEMENT a (b?, c*, (d|e)+)>
<!ELEMENT b (#PCDATA)>
<!ELEMENT c (#PCDATA)>
<!ELEMENT d (#PCDATA)>
<!ELEMENT e EMPTY>
<!ATTLIST c attr CDATA #IMPLIED>
]>
I want to convert (manually not by program) it to XML Schema, but I don't understand how do I create attribute for the c
element.
Upvotes: 1
Views: 560
Reputation: 111581
Here's how in XSD to declare that c
has string content and an attribute named attr
:
<xs:element name="c" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="attr" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Here's the entire DTD written as an XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element name="b" minOccurs="0" type="xs:string"/>
<xs:element name="c" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="attr" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:choice maxOccurs="unbounded">
<xs:element name="d" type="xs:string"/>
<xs:element name="e">
<xs:complexType/>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Upvotes: 1