XML For RPG Programmers: An Introduction: OCEAN Technical Conference Catch The Wave
XML For RPG Programmers: An Introduction: OCEAN Technical Conference Catch The Wave
An Introduction
Susan M. Gantner
susan.gantner @ partner400.com
www.partner400.com Your partner in AS/400 and iSeries Education
© Copyright Partner400, 2002.
XML appears to be the future of data interchange. It provides a powerful way to describe and
encode data that is system independent. Based on HTML, XML is quickly becoming the standard
data interchange language for business-to-business applications.
In this introductory session you will learn what XML is, what the syntax looks like, how it can be used
in your RPG applications, and how it will likely affect your applications in the future.
The author, Susan Gantner, is co-founder of Partner400, a firm specializing in customized education
and mentoring services for AS/400 and iSeries developers. After a 15 year career with IBM,
including several years at the Rochester and Toronto laboratories, Susan is now devoted to
educating developers on techniques and technologies to extend and modernize their applications
and development environments. This is done via on-site custom classes as well as conferences
and user group events.
Together with her partner, Jon Paris, Susan authors regular technical articles for the IBM
publication, eServer Magazine, iSeries edition, and the companion electronic newsletter, iSeries
Extra. You may view articles in current and past issues and/or subscribe to the free newsletter or the
magazine at: http://eservercomputing.com/iseries/.
Feel free to contact the author at: susan.gantner @ partner400.com and visit the Partner400 web
site at www.partner400.com.
What is XML?
eXtensible Markup Language
A markup language for creating other markup languages!
A markup language uses tags inserted into information (such as HTML, UIM)
XML allows the user to define a customized language to be used to
format specific information
You create/define your own tags
Defines the content and nature of the information -- not just how to
display it in a browser
Some similarity to DDS
Standardization and related technologies give it more power
Major focus is to provide a standard way to represent information
Standardization enhances information interchange
XML's Heritage
Limitations of HTML?
HTML tags are concerned with displaying information
Not with describing the content of the information
Fine for "computer to human" interactions
Less effective for computer to computer interactions
HTML XML
A tag based language A tag based language
<tag> </tag> syntax <tag> </tag> syntax
Markup language for text Markup language for information
Focus on presentation Focus on data structure
No meaning implied Data meaning implied
Fixed set of tags Extensible-define your own tags
Loose syntax Stringent syntax
Not case sensitive Case sensitive
End tags often not required End tags always required
Good for Computer to Human Good for Computer to Computer
interaction interaction
Works with any browser Works with few browsers "as is"
Can be transformed to HTML for
presentation purposes
HTML Example
<html>
<br><CENTER>
<table Border=1 CellSpacing=1 CellPadding=5 Width="600">
<th>Contact<th>Company<th>Address<th>City
<tr>
<td>Sally Smith</td>
<td>Acme Computer Supplies</td>
<td>1234 Jones St.</td>
<td>Anytown, MN 55901</td></tr>
<tr>
<td>John Jones</td>
<td>Phones R Us</td>
<td>5678 High Street</td>
<td>Mytown, GA 30033</td></tr>
<tr>
<td>Meanold Miser</td>
<td>Suchadeal Bank</td>
<td>91011 Important Ave.</td>
<td>Bankville, MN 55901</td></tr>
</table>
</html>
XML Example
<?xml version='1.0'?>
<Customers>
<Customer>
<Contact>Sally Smith</Contact>
<Company>Acme Computer Supplies</Company>
<Address>
<Street>1234 Jones St.</Street>
<City>Anytown</City>
<State>MN</State>
<Zip>55901</Zip>
</Address>
</Customer>
<Customer>
<Contact>John Jones</Contact>
<Company>Phones R Us</Company>
<Address>
<Street>5678 High Street</Street>
<City>Mytown</City>
<State>GA</State>
<Zip>30033</Zip>
</Address>
</Customer>
<!-- One customer omitted from this example due to limited space -->
</Customers>
Attributes
Additional information about an element
<Address type="shipping">
Attribute
<!-- Note: This is a subset of the XML Schema for our sample XML -->
<xsd:element name='Address' type='StreetAddress'
<xsd:complexType name='StreetAddress' minOccurs='1' maxOccurs='2'>
<xsd:sequence>
<xsd:element name='Street' type='string'/> Element
<xsd:element name='City' type='string'/> Built-in type 'string'
<xsd:element name='State' type='string'/>
<xsd:element name='Zip' type='USZipCode'/>
</xsd:sequence> Element
</xsd:complexType> User-created type
'USZipCode'
<xsd:simpleType name='USZipCode'>
<xsd:restriction base='xsd:string'>
<pattern value='[0-9]{5} (-[0-9]{4})?'/>
</xsd:simpleType>
XSL Example
This XSL creates a simple HTML table from our XML data
<xsl:template match='/'>
<html><head><title>Customer List</title></head>
<body><CENTER>
<table Border='1' CellSpacing='1' CellPadding='5' Width='600'>
<th>Contact</th><th>Company</th><th>Address</th><th>City</th>
<xsl:for-each select='Customers/Customer'>
<tr><td><xsl:value-of select='Contact'/></td>
<td><xsl:value-of select='Company'/></td>
<td><xsl:value-of select='Address/Street'/></td>
<td><xsl:value-of select='Address/City'/>,
<xsl:value-of select='Address/State'/> -
<xsl:value-of select='Address/Zip'/></td></tr>
</xsl:for-each>
</table>
</CENTER>
</body></html>
</xsl:template>
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match='/'>
<html><head><title>Customer List</title></head>
<body><CENTER>
<table Border='1' CellSpacing='1' CellPadding='5' Width='600'>
<th>Contact</th><th>Company</th><th>Address</th><th>City</th>
<xsl:for-each select='Customers/Customer'>
<tr><td><xsl:value-of select='Contact'/></td>
<td><xsl:value-of select='Company'/></td>
<td><xsl:value-of select='Address/Street'/></td>
<td><xsl:value-of select='Address/City'/>,
<xsl:value-of select='Address/State'/> -
<xsl:value-of select='Address/Zip'/></td></tr>
</xsl:for-each>
</table>
</CENTER>
</body></html>
</xsl:template>
</xsl:stylesheet>
In addition the following line is added to the XML in order to link it to the XSL file (the name of the
file is highlighted in bold:)
Customers
Customer Customer
...
DB2
XML XML
Column Collection
user table
book
XML XML
DOC DOC
XML column
Store and retrieve entire XML documents as DB2 column data
XML data represented by XML column
XML collection
Decompose XML document into a collection of relational tables
Compose XML documents from a collection of relational tables
IBM alphaWorks
Latest tools and enablers supporting XML
http://www.alphaWorks.ibm.com/