Given:
<authentication password="turkey" partnerid="exam" />
how can I declare this element in a XML schema?
I have got:
<xs:element name="authentication" type="auth_type" />
<xs:complexType name ="auth_type">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="password" type="xs:string" />
<xs:attribute name="partnerid" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
but it will allow the element to have text content, will it? I do not want that...
An attribute should be declared using the attribute-list declaration in the DTD (Document Type Definition). An attribute element is used without any quotation and the attribute value is used in a single (' ') or double quotation (” “). An attribute name and its value should always appear in pair.
Restrictions on a Set of Values To limit the content of an XML element to a set of acceptable values, we would use the enumeration constraint. Note: In this case the type "carType" can be used by other elements because it is not a part of the "car" element.
Elements and Attributes can be grouped together using <xs:group> and <xs:attributeGroup>. These groups can then be referred to elsewhere within the schema. Groups must have a unique name and be defined as children of the <xs:schema> element.
You can remove the xs:simpleContent
and xs:extension
....
<xs:element name="authentication" type="auth_type" />
<xs:complexType name ="auth_type">
<xs:attribute name="password" type="xs:string" />
<xs:attribute name="partnerid" type="xs:string" />
</xs:complexType>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With