XML Schema Examples

An example of using XML Schema Definition representing customer information.

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 cataloging the XML Schema Definition 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 the cataloged components

	customer as XMLCOmp.Customer.Customer
	customer = 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 loadFromUrl

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

The loadFromUrl( ) method uses DOM (Document Object Model) to load the complete XML document in 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. For example: C:\\documents\\test.xml or /documents/test.xml
  • the XML document content.