Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare an element with only attributes in a XML schema?

Tags:

xml

schema

xsd

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...

like image 764
Mirko Avatar asked Jan 10 '12 19:01

Mirko


People also ask

How can you declare attributes in XML?

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.

How do I restrict attribute values in XML schema?

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.

How do you declare the grouping elements and attributes in XML?

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.


1 Answers

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>
like image 161
Daniel Haley Avatar answered Jan 02 '23 17:01

Daniel Haley