Communicating With XML

Introduction

 
HTML mixes content data and makes it difficult to present the same data and standardize presentation across multiple sets of data. XML organize information into tree-like structures with each item of information representing a leaf. The advantage of using XML in preference to proprietary format is when information is structured. The XML is turned to standardize the representation of information in respective areas.
 
XML Document
  1. <?xml version = "1.0" encoding = "ISO-8859-1" ?>    
  2. < starfleet >    
  3.    < title >    
  4.      Startship    
  5.    </ title>    
  6.    < starship name = "USS Enterprise" sn = "NCC-1701" >    
  7.    < class name = "Constitution" />    
  8.       < captain > Jack sparrow    
  9.       < /captain>    
  10.    </ starship>    
  11.    <starship name = "USS Enterprise" sn = "NCC-1701-D" >    
  12.       < class name = "Galaxy " />    
  13.       < captain> Jean </captain>    
  14.    < /starship>    
  15. < /starfleet>    
The above code has standard and the character set used in the document and tags are closed in ending tag and the tag reflect the logical structure of data. XML documents contain processing instructions for the application and comments and document type. To verify the validity of xml documents and to communicate their structure to others by possibility of specifying in a separate document. The main method used to specify document structures are the XML, DTD and XML schemes.
 

XML DTDs

 
DTD is developed for XML predecessor and standard generalized markup language and the syntax of the DTD is shown below. It defines the start fleet element consist of a title element and starship element. Attribute type has many possible values and enumeration of all strings available. 
  1. <! ELEMENT starfleet ( title,starship*) >    
  2. <! ELEMENT title (#PCDATA) >    
  3. <! ELEMENT starshp (class , captain)>    
  4. <! ATTLIST    
  5.              starship name CDATA #REQUIRED    
  6.              sn CDATA #REQUIRED >    
  7. <! ELEMENT class EMPTY >    
  8. <! ATTLIST class name CDATA #REQUIRED >    
  9. <! ELEMENT captain (#PCDATA) >   

XML Schemes

 
It is used to store, handle, and style schemes like an XML document. W3C describes the standardized XML schemes in three document and is complicated. The starfleet element has an attribute to contain other elements. When applied to attribute, default supplies the value of optional attribute and the fixed constraint forces an attribute value and define a vale in an XML document and must match a fixed value assigned in the schema.
  1. <?xml version = "1.0" encoding = "ISO-8859-1" ?>  
  2. <xsd:schema  
  3.     xmlns:xsd = ""http://www.w.org/2001/XMLSchema" >  
  4.     <xsd : annotation >  
  5.         <xsd : documentation xml:lang = "en" >      
  6. Schema      
  7. </xsd : documentation >  
  8.     </xsd : annotation >  
  9.     <xsd : element name = "starfleet" >  
  10.         <xsd : complexType >  
  11.             <xsd : sequence >  
  12.                 <xsd : element name = "title" type = "xsd:string" maxOccurs = "1" />  
  13.                 <xsd:element name = "startship" type = "ShipType" maxOccurs = "unbounded" / >  
  14.                 </xsd : sequence >  
  15.             </xsd : complexType >  
  16.         </xsd : element>  
  17.         <xsd:complexType name = "ShipType" >  
  18.             <xsd : all >  
  19.                 <xsd : element name = "class" type = "ClassType" minOccurs = "1" />  
  20.                 <xsd : element name = "captain" type = "xsd : string" minOccurs = "1" /></xsd : all>  
  21.             <xsd : attribute name = "name" type = "xsd:string" use = "required" />  
  22.             <xsd : attribute name = "sn" type = "xsd:string" use = "required" /></xsd : complexType >  
  23.         <xsd : attribute name = "name" type = "xsd : string" use = "required" /></xsd : complexType >  
  24. </xsd : schema >    

Simple Type

 
Simple type is used to modify already defined type wthout adding attribute or other elements. Whitespace and pattern attributes is used and attributes like length and minLength is possible. The replace is used to line feed, tab characters are replaced with simple spaces and collapse is used to leading and trainling spaces are removed and sequences of multiple spaces are collapsed into single spaces.
  1. < xsd : simpleType name = "myString" >      
  2.    < xsd : restriction base = "xsd:string" >      
  3.    < xsd : maxLength value = "32" >      
  4.    </xsd : restriction >      
  5. </xsdLsimpleType >    

Complex Type

 
Complex type has additional options and it has three models namely sequence, all, the choice is used to group the elements. 
 
Sequence - Elements appeared in a specified sequence.
 
All - one element listed and appear in a specified sequence.
 
Choice - Elements are mutually exclusive.
  1. <xsd : sequence >  
  2.     <xsd : choice >  
  3.         <xsd : element name = "no"  />  
  4.         <xsd : all>  
  5.             <xsd : element name = "yes" / ></xsd :all>  
  6.         </xsd : choice>  
  7.         <xsd : element name = "name" /></xsd : sequence > 


Similar Articles