Switch to full style
XML Schema tutorial
Post a reply

lesson7: XSD Complex Text-Only Elements

Fri Mar 06, 2009 1:01 am

XSD Complex Text-Only Elements:
If your Complex type have only text and attributes .In this case you use SimpleContent tag. You must use extension OR a restriction within the simpleContent element.

Code:
<xs:element name="ID">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:integer">
        <xs:attribute name=" nationality" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>


This is an example of an XSD document that defines the structure of an XML element called "ID". The "xs:element" element is used to define an element in the XML document and the "name" attribute specifies the name of the element. The "xs:complexType" element is used to define the type of the "ID" element. Inside the complexType, an "xs:simpleContent" element is defined, which is used to hold the actual value of the "ID" element. The "xs:extension" element is used to define an extension of a simple type. The "base" attribute specifies the base type, in this case, "xs:integer", which means the ID element is an integer. The "xs:attribute" element is used to define an attribute for the "ID" element, in this case, "nationality" with the data type "xs:string". So this XSD defines an "ID" element with a base type of integer and an attribute called "nationality" of type string. The "ID" element can contain an integer value and also a "nationality" attribute that contains a string value. This can be useful in case you want to include additional information about the ID, like the nationality of the person the ID belongs to.

In addition to what I've mentioned before, it's also worth noting that the "xs:extension" element allows you to add additional information to a simple type, in this case, the integer ID, by adding a new attribute. This can be useful when you need to add extra information to an element, such as a label or an identifier, without changing the underlying data type of the element. This XSD document ensures that the XML document adheres to the structure defined in it and that the data contained in the "ID" element is of the correct data type. This can be useful for ensuring data integrity and consistency when exchanging information between systems.



XML example:
Code:
<ID nationality="Egyptian" >32</ID>


This is an example of an XML document conforming to the structure defined by the earlier XSD document. The "ID" element is the root element, and it contains an attribute called "nationality" with the value "Egyptian" and also a text node with the value "32", which represents the ID number. The "nationality" attribute provides additional information about the "ID" element, which tells us that the ID belongs to an Egyptian person. The text node "32" is the value of the ID element, and it should be an integer as defined in the base attribute of the xs:extension element in the XSD document. This XML document provides specific information about an ID, such as the person's nationality and the ID's value. It adheres to the structure and data types defined in the XSD document, ensuring that the information is organized and consistent.



Post a reply
  Related Posts  to : lesson7: XSD Complex Text-Only Elements
 lesson5: XSD Complex elements     -  
 lesson6: XSD Complex Empty Elements     -  
 Complex Numbers     -  
 Complex numbers calculator (C++)     -  
 Able to Copy Text from Uneditable Text Boxes(JTextfields)     -  
 solve the complex numbers and do operations on it     -  
 lesson9: XSD Complex Types Indicators     -  
 lesson8: XSD Complex Type Mixed Content     -  
 Java- Copy text area into disabled text area     -  
 Add elements to the end of an array     -  

Topic Tags

XSD Elements