XML Schema Examples

XML Schema Introspection Example

The following is an XML schema example for an XML document that may be used in a business process.
                
	 <?xml version="1.0" encoding="UTF-8" ?> 
	
	 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">  
	   <xsd:simpleType name="Address" type="xsd:string"/>
	   <xsd:simpleType name="CustomerCode" type="xsd:string"/>
	   <xsd:simpleType name="CustomerName" type="xsd:string"/>
	   <xsd:simpleType name="CodPay" type="xsd:string"/>
	   <xsd:simpleType name="CustDisc" type="xsd:string"/>
	   <xsd:simpleType name="CustType" type="xsd:string"/>
	   <xsd:simpleType name="Mail" type="xsd:string"/>
	
	   <xsd:group name="shipAndBill">
	      <xsd:sequence>
	          <xsd:element name="ShipAddress" type="Address"/>
	          <xsd:element name="BillAddress" type="Address"/>
	      </xsd:sequence>
	   </xsd:group>
	
	   <xsd:complexType name="Customer">
	     <xsd:sequence>
	       <xsd:choice>
	        <xsd:element name="CustomerCode" 
	          type="CustomerCode"/>
	        <xsd:element name="CustomerName" 
	          type="CustomerName"/>
	        <xsd:element name="CodPay" type="CodPay"/>
	        <xsd:element name="CustDisc" type="CustDisc"/>
	        <xsd:element name="CustType" type="CustType"/>
	        <xsd:group ref="shipAndBill"/>
	        <xsd:element name="Mail" type="Mail"/>
	       </xsd:choice>
	     </xsd:sequence>
	   </xsd:complexType>
	 
	   <xsd:element name="customer" type="Customer"/>
	
	 </xsd:schema>
	

After introspecting the XML schema detailed above, the Project catalog structure appears as shown in the following image:

Note: You can drag and drop the XML attributes and methods to the Method Editor in order to visualize the usage template.

Create an XML File Based on an Introspected Definition

	customer as XMLCOmp.Customer.Customer
	customer = XMLCOmp.Customer.Customer()
	
	customerDOS as XMLCOmp.Customer.Customer
	customerDOS = XMLCOmp.Customer.Customer()
	
	
	customer.customerCode = "NEW"
	customer.customerName = "John Smith"
	customer.custDisc = null
	customer.billAddress = "Madison 2939 NY"
	customer.shipAddress = "Madison 2939 NY"
	customer.codPay = null
	customer.custType = null
	customer.mail = "pp@com.com"
	
	store customer
	    using targetFile = "C:/tmp/customer.xml"
	

Loading an XML File Using the loadFromUrl

The loadFromUrl method can receive as parameter an URL, pointing the xml file, like file://home/sharedDocuments/test.xml or http://....
	
	customer as XMLComp.Customer.Customer
	customer = XMLComp.Customer.Customer()
	
	customer.loadFromUrl("file://c:/tmp/customer.xml")
	
	

While loadfromUrl( ) method to parse XML documents is interesting from a coding perspective, it is recommended to avoid its use on a large XML file as it uses DOM and reads the whole file into memory.

Load an XML data file containing a customer using the load method

The load method can receive as parameter:
  • an URL,

  • a path location to the xml file OS dependant. This is, for example : C:\\documents\\test.xml or //home//sharedDocuments//test.xml, Windows and Unix.

  • the xml file content.