Mega Code Archive

 
Categories / XML Tutorial / XML Schema
 

Declaring Attributes

<attribute name="QName"         ref="QName"         type="QName"         use="optional | prohibited | required"         form="qualified | unqualified"         id="ID"         default="string"         fixed="string"         {any attributes with non-schema namespace} >   Content: (annotation?, (simpleType?)) </attribute> An attribute is always of simple type since it contains neither other elements nor other attributes. An attribute always appears within an element of complex type. An attribute must be declared at the very end of the complex type to which it belongs. File: Schema.xsd <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"   targetNamespace="http://www.rntsoft.com" xmlns="http://www.rntsoft.com"   elementFormDefault="qualified">   <xsd:element name="source">     <xsd:complexType>       <xsd:complexContent>         <xsd:extension base="xsd:anyType">           <xsd:attribute name="sectionid" type="xsd:string" />           <xsd:attribute name="newspaperid" type="xsd:string" />         </xsd:extension>       </xsd:complexContent>     </xsd:complexType>   </xsd:element> </xsd:schema>   File: Data.xml <?xml version="1.0"?> <source xmlns="http://www.rntsoft.com" sectionid="101" newspaperid="21"/>