0% found this document useful (0 votes)
123 views

Interfacing PB With The Web 1 2 PDF

1) JP Morgan developed an XML interface between a web-based bond trading system called IssueLink and one of their back-office systems to automate bond trading. 2) The XML interface includes an NT service written in PowerBuilder that runs 24/7 listening for messages from IssueLink and parsing the messages. 3) The XML interface has processed over $20 trillion in trades in 9 months, significantly reducing the time to complete trades.

Uploaded by

bhutengs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views

Interfacing PB With The Web 1 2 PDF

1) JP Morgan developed an XML interface between a web-based bond trading system called IssueLink and one of their back-office systems to automate bond trading. 2) The XML interface includes an NT service written in PowerBuilder that runs 24/7 listening for messages from IssueLink and parsing the messages. 3) The XML interface has processed over $20 trillion in trades in 9 months, significantly reducing the time to complete trades.

Uploaded by

bhutengs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

P B D J F E A T U R E

PART 1 OF 2

Developing an XML parser using PowerBuilder

J
P Morgan in London recently used PowerBuilder to es all had computer systems but little information was communicated
electronically. The same deal might be entered into three different sys-
implement an XML interface between a Web-based
tems before it was settled.
bond trading system and one of their back-office sys- The major players in the European bond market ( JP Morgan,
tems. This is the first of two articles that describe how Deutsche Bank, and Citibank) invited a British software house called
this system was developed. Capital Net to develop a system to automate the market. The result was
a Web-based B2B bond trading system called IssueLink that links deal-
ers, banks, and clearing systems.
Participants can access IssueLink via a browser or by developing an
Some Background XML interface to their own systems. JP Morgan decided to pursue the
Trading bonds in Europe was a very old-fashioned process involving XML option. The core component in the interface is an NT Service writ-
many manual processes and disparate systems. When a dealer wanted to ten in PowerBuilder. The service runs 24/7, listening for messages from
purchase a bond they would contact a bank, such as JP Morgan, by tele- IssueLink and parsing them when they arrive. Depending on the type of
phone or fax. The details of the trade would be written down and then message, different actions are performed, such as validating the trade,
entered into a back-office system. The dealers, banks, and clearinghous- updating a back-office system, or notifying a participant. Some incom-

12 PBDJ volume8 issue8 www.PowerBuilderJournal.com


“</name>” to indicate the end of the data. Unlike HTML, which has a
fixed set of tags, the tags in XML are user-defined and can be given
names that are appropriate for the data. The term extensible describes
this ability to define your own tags.
An XML document describes the structure of the data as well as its
content, but doesn’t contain any information on how the data should be
presented. You can use Extensible Stylesheet Language Transformations
(XSLT) to transform the structure of XML documents and Cascading
Style Sheets (CSS) to format them.
Because the names of data elements relate to real-world objects, it’s
possible to determine the purpose of the data without having to refer to
anything other than the XML file. Because of this, XML is said to be self-
describing.
XML documents can contain nested data such as “an employee has an
address and that address has a house number and a street” as well as
repeating data such as “an invoice is for one or more items.” It’s difficult
to represent nested and repeating data in traditional flat files.
XML version 1.0 became a World Wide Web Consortium (W3C) rec-
ommendation in February 1998. Many software vendors, including
Sybase and Microsoft, are XML-enabling their applications. XML is plat-
form- and vendor-independent, and XML documents are text-based,
which means they can be handled by all operating systems. Because of
these characteristics, an XML message generated on a Palm Pilot could
be interpreted on an IBM mainframe.
The following is a simple XML file that contains data relating to a pre-
sentation at TechWave.

<?xml version="1.0"?>
<presentation code="ID352">
<!--Example XML file-->
<title>A PB / XML Messaging System</title>
<presenter>Paul Donohue</presenter>
<audience>PowerBuilder Developers</audience>
<time>13:30</time>
<date>2001-08-13</date>
</presentation>

This example shows the three parts of an XML document that I’ll dis-
cuss in this article.
1. Elements are the core of an XML document: They consist of a start and
an end tag with the data between these tags. Elements may also have
child elements or attributes. In the example, presentation, title, and
time are among the elements.
2. Attributes are also name/value pairs: However, the name and data are
separated by an equal sign. They belong to an element but are not ele-
ments on their own, rather they add some sort of qualification to the
element they belong to. All attributes are strings and enclosed in single
WRITTEN BY PAUL DONOHUE or double quotes. In the example there’s only one attribute, code.
3. Comments are used to annotate XML documents: They begin with
“<!--” and end with “-->”. The example has one comment – “Example
XML file.”

ing messages may trigger outgoing messages that are processed by


IssueLink. Parsing an XML File
In the nine months since it first went live, the interface with IssueLink Although it would be possible to read and write XML files using
has processed trades worth $20,000,000,000. Under the old manual sys- PowerBuilder’s file functions, they’re normally processed with a software
tem trades could take over an hour to complete. Over a quarter of the component called a parser. Parsers fall into two groups: DOM and SAX.
trades now take less than 15 minutes from when the dealer enters the DOM stands for Document Object Model. DOM parsers load an entire
trade until it’s added to JP Morgan’s back-office system. The quickest XML document into memory when the file is parsed. The data is placed
trade took only 1 minute 8 seconds. into a tree of nodes that your application can manipulate. This is only
suitable for small XML files because of the memory overhead. The meth-
ods described in this article use DOM.
What Is XML? SAX stands for Simple API for XML. SAX parsers are event-driven. As
Most readers will be familiar with XML, but for those who aren’t I’ll the document is parsed, you’re notified when certain events occur. An
provide a quick introduction. XML stands for Extensible Markup event might be finding the start or end of an element. SAX can handle
Language. Like HTML, XML uses tags to delimit the boundaries of data. large files because they’re not read into memory. This is useful if you
The basic format is “<name>” to indicate the start of the data and want to process only a subset of the data in a file. The main drawback is

www.PowerBuilderJournal.com PBDJ volume8 issue8 13


that there’s no random access to the data with- and, as the name suggests, you can distribute document. If an error occurs while parsing the
in the document. the parser royalty-free. Although this parser is file, the load method returns false and the
shipped as part of IE, it’s a separate OLE object parseError attribute is populated. This struc-
so any development tool that can access OLE ture will pinpoint the location of the error as
Why Use PowerBuilder for an XML objects can use it. well as the nature of the problem. The impor-
If you install IE on your computer, the tant properties of parseError are shown in
Parser? parser will be registered automatically. The Table 2.
When you think of XML you probably think only drawback to this is that the parser that
of the Internet and Java because these tech- comes with IE may not be the latest version.
nologies have grown up together. However, Early versions don’t support the final specifi- Walking the Tree
there’s no reason why you can’t process XML cation of XSLT so it’s best to download the Remember that DOM parsers load the entire
messages using almost any language – espe- parser on its own from the Microsoft site. XML file into memory, whereas SAX parsers are
cially if there’s a parser available for your devel- Once Internet Explorer is installed it will be event-driven. One advantage of DOM is that you
opment tool. When I worked on my first XML associated with the XML extension. Double- can go straight to the node you require using the
project, my entire team consisted of click on an XML file in Windows Explorer and selectSingleNode() method. This is fine if you
PowerBuilder developers. Although some were IE will display it with the structure and data know the structure of the XML files that you’ll be
familiar with Java, they didn’t have enough color-coded. processing. However, if you’re unsure what the
structure will be, you require a generic solution.
Once the file is in memory it’s represented by
Property Description a tree of nodes. Each node may have siblings
Async Specifies if asynchronous download is permitted. When set to TRUE control (elements at the same level), children (ele-
is returned before the XML document is loaded. (Recommendation = FALSE). ments at a lower level), or attributes. The term
validateOnParse Specifies whether the parser should validate the document against the Document walking the tree refers to processing each node
Type Definition (DTD) when it’s parsed. (Recommendation = TRUE). of the XML file starting at the root node and
moving on to all its children, attributes, and
TABLE 1 XML parser properties siblings. Each time you reach a fork in the tree
you go down one of the branches, forking as
experience to build a mission-critical system required until you reach the leaf nodes. At this
using Java. The project deadlines didn’t allow How to Parse an XML File point you work your way back up the tree, vis-
any time for training so the team investigated Using the parser with PowerBuilder is simi- iting any branches that haven’t yet been
whether we could develop in PB. lar to controlling any other OLE application processed. Although it sounds complicated,
A development tool must meet three criteria such as Word or Excel. Once you get the hang of using recursion makes it simple.
before it can be used to develop a DOM-based the syntax it’s easy to get it working. The mini- In Listing 2 an XML file is loaded into a tree-
XML system. mum code to do this is shown in Listing 1. All view using a recursive function called
1. Be able to parse an XML file: PB has no low- error checking has been removed for clarity. wf_parse_node. The arguments for this function
level XML support built in; however, neither are the XML node to parse and the treeview item
do C++ or Java. Most XML-based systems use CONNECTING to populate. Start wf_parse_node by giving it the
a parser to process the XML data rather than The OLE object variable acts as a reference to root node of the XML file and the root item in
perform low-level file operations. The XML the XML parser. The ConnectToNewObject() the treeview. Use the “documentElement”
parser we decided to use is an OLE object function invokes the Microsoft XML parser. The attribute to find the XML root node.
that PB can access easily. parser that’s shipped with IE5 is identified by the Populating a treeview recursively is pretty
2. Be able to manipulate the data in memory: class name “Microsoft.XMLDOM”. If you install a cool, but if you’re developing a business appli-
When using a DOM parser you need to be newer version, you’ll have to use the class cation you’ll probably want to do something
able to manipulate the nodes of the XML name “MSXML2.DOMDocument.3.0”. Use else with your XML file. The most likely alter-
message in memory. PB’s memory manage- PowerBuilder’s IsValid() function to test if the natives are updating the database, invoking a
ment is not as advanced as C++’s; however, ConnectToNewObject() function was successful. business rule object, writing to a file, or send-
our chosen parser did most of the tricky work Once you’ve connected to the OLE object ing an e-mail. The recursive method of walk-
for us and provided simple methods to access you can access the parser’s methods and ing the tree is very useful for finding the nodes
the data. Using these methods and PB’s properties using notation similar to you require to carry out this processing.
arrays, structures, and nonvisual objects, we “<ole_object_variable>.<method_or_proper-
could do whatever we wanted with the data. ty>”. You can set many different attributes. DISCONNECTING
3. Be able to access the database: XML is a Table 1 shows some useful attributes. When you’ve finished processing one
great technology for data interchange but at or more XML files you need to disconnect
some point you probably need to store the LOADING from the browser and tidy up. The Dis-
data somewhere. PB’s strong point is its The load() method loads and parses an XML ConnectObject() function will terminate your
database access, so it was simple to record
details of the messages and to update our
back-office systems. Property Description
ErrorCode A number that identifies the type of error

The MS Redistributable Parser Filepos


Line
The absolute position of the error in the file
The number of the line that contains the error
There are many XML parsers available.
Linepos The character position of the error (on the error line)
Many are open source and almost all seem to
have a weird name such as expat, XP, Xerces, Reason The reason for the error
hex, and Xparse. Microsoft has included a pars- SrcText The text of the line that contains the error
er with Internet Explorer since version 4.7,
called the Microsoft Redistributable Parser, TABLE 2 Important parseError properties

14 PBDJ volume8 issue8 www.PowerBuilderJournal.com


the XML file shown at the beginning of this The service processes the XML messages from
article, the results aren’t what you would IssueLink.
expect. The resulting DOM tree is shown in
Figure 1. The labels show the node name and
its value in brackets. Resources
The root node is called presentation and has 1. Birbeck, M., et al. (2001). Professional XML.
no value. It has one attribute node, a comment Wrox Press. This is the best XML book I’ve
node, and five child element nodes. The attribute come across.
and comment nodes have values as you would 2. A commercial site with good XML news:
expect, however, the element nodes don’t have a www.xml.com
value of their own. The element’s value is stored 3. The XML industry portal: www.xml.org
in a text child node. This strange behavior is logi- 4. The World Wide Web Consortium – good for
cal if you think of elements as containers. pure XML information: www.w3.org/xml
Elements may contain other elements, attribut- 5. Microsoft’s XML page for developers – bit MS-
FIGURE 1 XML DOM tree es, comments, or data (stored in a child node). centric but quite good: http://msdn.
As a workaround to finding the value of microsoft.com/xml
XML browser session. Make sure you destroy the an element, check if the first node in its child 6. Information on Capital Net’s IssueLink sys-
OLE object variable when you’re finished. node list is of type “TEXT”. In this case you tem: www.capn.com/issuelink ▼
can assume that the text node is the value
for the element. A PowerBuilder example AUTHOR BIO
A Strange Thing About the XML that demonstrates how to code for this Paul Donohue has 15 years’ experience as a solution provider. He has
is available on the PBDJ Web site, worked with PowerBuilder since version 2 and is a Certified
DOM Tree www.PowerBuilderJournal.com. PowerBuilder Developer.
There’s a feature of the DOM tree that can be In Part 2 I’ll discuss how JP Morgan was able
confusing. If you use the sample code to parse to develop an NT Service using PowerBuilder. [email protected]

long ll_treeview // The newly inserted treeview item


Listing 1
// Declare an OLE object as a reference to the parser
oleobject lole_xml_document // Determine the node's name, type and value
ls_node_name = aole_node.nodename
ls_node_type = Upper(aole_node.nodetypestring)
// Identify the file to parse ls_node_value = String(aole_node.nodevalue)
string ls_filename = „C:\DEMO.XML„
IF IsNull(ls_node_value) THEN
ls_node_value = "<NULL>"
// Create the OLE Object END IF
lole_xml_document = CREATE oleobject

// Add this node to the treeview


// Connect to the parser // I am using a picture index of 1 however
// NOTE : This example uses the parser from IE5. // you could use the nodetypestring to determine
// Use the class name „MSXML2.DOMDocument.3.0‰ // the node‚s type and use an appropriate picture
// for the latest version. ls_label = ls_node_name + " (" + ls_node_value + ")"
lole_xml_document.ConnectToNewObject("Microsoft.XMLDOM") ll_treeview = tv_xml.InsertItemLast (al_treeview_parent,
ls_label, )

// Load the file into memory (this will parse it)


lole_xml_document.load(ls_filename) // If this node has attributes process them
lole_attribute_node_list = aole_node.attributes

// ******************************************** IF IsValid(lole_attribute_node_list) THEN


// THE XML FILE HAS BEEN PARSED AND IS IN MEMORY ll_max_attribute_nodes = lole_attribute_node_list.length
// YOU CAN INVOKE PARSER METHODS TO MANIPULATE IT ELSE
// ******************************************** ll_max_attribute_nodes = 0
wf_parse_node(this function has some arguments) END IF

FOR ll_attribute_idx = 0 TO ll_max_attribute_nodes - 1


// Disconnect from the XML parser lole_attribute_node =
lole_xml_document.DisConnectObject() lole_attribute_node_list.Item(ll_attribute_idx)
wf_parse_node (ll_treeview, lole_attribute_node) /* RECUR-
SIVE */
// Destroy the OLE object NEXT
DESTROY lole_xml_document

// If this node is an element and it has children process them


Listing 2 IF ls_node_type = "ELEMENT" THEN
wf_parse_node(node, treeview) lole_child_node_list = aole_node.childNodes
// Arguments IF IsValid(lole_child_node_list) THEN
oleobject aole_node // The node to process ll_max_child_nodes = lole_child_node_list.length
long al_treeview_parent // The treeview item to add ELSE
nodes to ll_max_child_nodes = 0
END IF
// local variables
string ls_node_type // The type of the current node FOR ll_child_idx = 0 TO ll_max_child_nodes - 1
string ls_node_name // The name of the current node lole_child_node =
string ls_node_value // The value of the current node lole_child_node_list.Item(ll_child_idx)
oleobject lole_attribute_node_list // The attributes for wf_parse_node(ll_treeview, lole_child_node) /* RECUR-
this node SIVE */

the Code!
oleobject lole_attribute_node // An attribute for this node NEXT
oleobject lole_child_node_list // The child nodes for this
load
Down
node END IF
oleobject lole_child_node // The current child node
long ll_max_attribute_nodes // The number of attribute
nodes
long ll_max_child_nodes // The number of child nodes
long ll_attribute_idx // A counter The code listing for this article can also be located at
long ll_child_idx // A counter
string ls_label // The label for the treeview www.PowerBuilderJournal .com

www.PowerBuilderJournal.com PBDJ volume8 issue8 15

You might also like