| By Roy Kiesler | Article Rating: |
|
| January 1, 2003 12:00 AM EST | Reads: |
9,453 |
XML is fast becoming the de facto industry standard for intercomponent and interapplication data transfer. While XML is more commonly used in distributed environments, it can be just as useful, and, at times necessary, in more traditional client/server applications.
The PowerBuilder DataWindow has always excelled in the tasks of retrieving, presenting, and manipulating relational data. With the introduction of XML export and import features, the DataWindow is once again poised to handle the challenges of today's and tomorrow's technologies.
What Is XML?
The Extensible Markup Language is considered the de facto standard for the delivery of structured data on the Web. A subset of SGML, it's a markup language that's used primarily to describe data similar to the way HTML is used to describe the visual structure of Web documents.
XML Terminology
The terminology used to describe XML documents is defined in the body of the XML 1.0 specification, available from the World Wide Web Consortium (W3C) Web site at www.w3.org/TR/REC-xml. I've paraphrased a relevant subset:
<?xml version="1.0"?>
<?xml version="1.0"? encoding="UTF-8">
<name>content</name>
<name/>
<name attribute="value">content</name>
<!-- legal comment -->
<!---- illegal comment ---->
<?xml-stylesheet type="text/css" href="styles.css"?>
<![CDATA[R & D]]>
- Integration with namespaces
- Integration of structural schemas with primitive data types (integers, dates, sequences, and other SQL- and Java-like data types)
- A schema definition is a valid XML document
- Inheritance for element, attribute, and data type definitions
<!ENTITY nbsp " ">
<!ENTITY % HTMLlat1
SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">
%HTMLlat1;
<!NOTATION XML PUBLIC "REC-xml-1998-0210"
"http://www.w3.org/TR/1998/REC-xml-19980210">
<!NOTATION gif SYSTEM "IE">
<foo>well-formed</foo>
<foo>not<bar>well-formed</foo></bar>
XML Parsers
The processing of every XML document begins with the parsing of the document's elements and attributes. To access the document's data, the parser must verify that the document is well formed and, optionally, validates the document's structure against a DTD or a schema referenced by the document.
XML parsers are available from a large number of software vendors, including Microsoft, Sun, Oracle, and a plethora of open-source organizations like Apache and SourceForge.Net. Implementations are available for numerous programming languages, including C++, Java, Visual Basic, C#, Perl, and, of course, PowerScript.
The following is a partial list of XML parsers.
Microsoft XML Core Services (MSXML)
MSXML is a complex hybrid product; an XML parser and an XSLT processor in one, it exports both a traditional COM interface, featuring versions for both client- and server-side (thread-safe) processing, as well as a newer .NET implementation. The MSXML parser supports all major XML standards, including DOM, SAX, namespaces, and schemas.
Apache Xerces
Xerces is an open source XML parser implemented in a variety of programming languages, including Java, C++, and Perl. The parser is fully compliant with the W3C XML 1.0 recommendation, supporting DOM levels 1.0 and 2.0, SAX 1.0 and 2.0, namespaces, and the latest W3C XML Schema recommendation.
Note: At the core of the DataWindow XML export engine is the C++ implementation or Xerces. Xerces/C++ was selected for its cross-platform foundation to ensure that the XML export functionality operates consistently on all platforms supported by the PowerBuilder Virtual Machine (Microsoft Windows, Sun Solaris, HP-UX, and IBM AIX).
PowerBuilder native xml Services (PBDOM)
PBDOM is a new set of PowerBuilder classes that enables users to create, read, write (modify), and manage DOM-based XML documents via PowerScript. PBDOM is a PBNI wrapper for the Xerces/C++ XML parser.
DataWindow Export Engine
The DataWindow Export Engine ("XML Renderer") is a new component in the DataWindow engine (see Figure 1). It uses export templates as the infrastructure for exporting row data into XML format.
The XML renderer analyzes the export template to be used for the XML output. Since the export template is an XML document, it must be parsed first. The renderer uses ,,,,, and will need the services of the XML parser/generator engine in order to analyze the template.
As the renderer analyzes the XML template, it will need to map elements from this template to actual DataWindow controls and their text values. After the mapping operation has been successfully completed, the renderer will perform the final XML syntax generation, again with the help of the XML parser/generator engine.
Export Templates
An export template defines the mapping between DataWindow elements and their XML counterparts.
The following DataWindow objects can be used in export templates:
- Column
- Computed column
- Text control
- Computed field
- Nested report
- Element
- Attribute
Export templates are part of a DataWindow's definition. A DataWindow can contain multiple export templates. Templates are persisted in both the PBL and SRD formats of a DataWindow. A new DataWindow property, Export.XML.UseTemplate, is used to specify a named template object for use in a given export operation. This property can be set at both runtime and design time.
Note: The DataWindow.Export object currently supports XML only; however, in the future, other document types will be supported.
The syntax for XML export templates is shown in Listing 1.
Export Templates -
Graphical User Interface
The DataWindow painter in PowerBuilder 9.0 features a new view for defining and editing XML export templates. In the painter's default layout, this view is located to the left of the existing Column Specification, Data, and Control List views, and is titled "Export Template - XML".
The new XML export template view contains a TreeView control that represents the XML structure of an export template. XML entities (markup and character data) are displayed as TreeView nodes with a distinctive icon and font color to denote the type of entity. Character data is displayed as a child node of the respective element node; thus, element end tags are not shown but assumed. Markup delimiters are also implicit; i.e., angle brackets are not shown but assumed.
Only one export template can be opened in this view for editing at any given time. Figure 2 shows the new XML export template view in the DataWindow painter.
Export Template Header Section
Right-clicking anywhere on the TreeView control's background area brings up a context-sensitive popup menu that includes the following options:
Right-clicking any given node in the export template TreeView control will produce one of a number of additional context menus, depending on the node type and relative location in the tree. For example, the context menu for the XML declaration node displays the following options:
Note: Currently, "1.0" is the only valid value for the version setting, but as the W3C XML specification evolves, additional values will also be supported. Also, deleting the XML declaration node, while allowed in a well-formed document as per the W3C specification, does not affect the generated XML - it still contains the default XML declaration.
The context menu for the document type declaration node displays the following options:
Note: If the current template already has an XML declaration node defined, the corresponding option on the Insert Before cascading menu is disabled.
The context menu for the root node displays the following options:
Note: The XML declaration and document type options on the Insert Before cascading menu will be disabled if the corresponding nodes are already present in the current template. The root node is required and can't be deleted.
Export Template Detail Section
The Detail section is graphically delineated by a gray line across the TreeView control, separating the header section from the detail section, similar to the way a detail band functions in the DataWindow painter's design view. The separator line can be repositioned by the user by checking the "Starts Detail" option on the context menu of the respective element node. This element is then referred to as the Detail Start element.
Only one element can be marked as the Detail Start element, and the root node can't be. By default, the first child of the root element is designated as this element; however, any subsequent child node (and children thereof) may be marked as the Detail Start element, effectively moving all preceding nodes to the header section of the template. At export time, only the Detail Start element, its sibling, and children will be iteratively generated for each row.
The context menu for element nodes in the detail section displays the following options, in addition to the ones displayed by the root node's context menu:
Mapping DataWindow Elements to XML Nodes
Once the structure of your target XML document is finalized, you need to bind data values to XML elements and attributes. The mapping process is done by selecting a DataWindow column, computed field, expression, and/or text controls from a dialog. Alternatively, the user may drag and drop items from the control list painter view. The selected item appears as a child node under the respective element node in the TreeView control. Figure 4 shows the control reference dialog.
Note: Data values mapped to XML elements are treated as character data, regardless of the actual data type (number, date, etc.) of the respective DataWindow column.
Exporting XML
You can export the data in a DataWindow or DataStore object to XML utilizing techniques that are similar to those used for exporting to other formats such as PSR or HTML:
1. Using the Save Rows As menu item in the DataWindow painter when the Preview view is open
2. Using the SaveAs() method:
dw_1.SaveAs( "c:\foo\bar.xml", XML!, TRUE )
3. Using PowerScript dot notation:
ls_xml = dw_1.object.datawindow.data.xml
4. Using PowerScript Describe notation:
ls_xml = dw_1.Describe( "datawindow.data.xml" )
New DataWindow properties are used to fine-tune the generation of XML from DataWindow data. These properties can be set at runtime and design time. The following is a list of those properties and their descriptions.
Export.XML.UseTemplate is used to specify a named template object for use in a given export operation. This property can be selected at design time via a dropdown list box containing all saved export templates, or at runtime using the following syntax:
1. Using PowerScript dot notation:
dw_1.Object.DataWindow.Export.XML.UseTemplate = "value"
2. Using PowerScript Modify notation:
dw_1.Modify( "DataWindow.Export.XML.UseTemplate {= 'value'}" )
Export.XML.MetaDataType is used to specify what metadata will be attached to the XML generated by the DataWindow. This property can be selected at design time via a dropdown list box that contains all saved export templates, or at runtime using the following syntax:
1. Using PowerScript dot notation:
dw_1.Object.DataWindow.Export.XML.MetaDataType = "value"
2. Using PowerScript Modify notation:
dw_1.Modify( "DataWindow.Export.XML.MetaDataType{= 'value'}" )
Table 1 lists the possible values for this property.
Export.XML.SaveMetaData is used to specify how the generated metadata will be stored. This property can be selected at design time via a dropdown list box containing all saved export templates, or at runtime using the following syntax:
1. Using PowerScript dot notation:
dw_1.Object.DataWindow.Export.XML.SaveMetaData = "value"
2. Using PowerScript Modify notation:
dw_1.Modify( "DataWindow.Export.XML.SaveMetaData{= 'value'}" )
Table 2 lists the possible values for this property. Figure 5 shows the DataWindow painter user interface for setting the XML properties of a DataWindow.
Note: The Modify syntax can use both the numeric and enumerated values in the expression.
Importing XML
XML import templates take advantage of the export template foundation. They allow the mapping of XML elements and attributes to the corresponding relational database columns.
Unlike the export process that uses a DOM parser to construct the XML document, XML import uses a SAX parser, which offers a significant performance improvement.
Uses for the XML DataWindow
PowerBuilder developers and InfoMaker users can use the XML export features of the DataWindow in the following ways.
Client/Server Applications
PowerBuilder applications using DataWindows for data entry and/or data reporting could be enhanced with events to export select data values, or the entire contents of the DataWindow, to variously structured XML documents for use by other applications, processes, or systems within or outside the enterprise.
InfoMaker users could also export select subsets, or the entire set of data values from their report ( e.g., a Purchase Order) from within an XML tool that's designed to comply with the DTD or XML Schema of a vendor's PO, for example.
Distributed Applications
PowerBuilder NVO components using DataStores for server-side database processing or for middle-tier data management of client-side DataWindows could include a method to export the contents of the DataStore in XML. This XML could be pushed for processing by a different enterprise component or subsystem, for example, a J2EE Enterprise JavaBean or a Web service over the Internet.
Web applications using the Web Targets and/or the Web DataWindow component (HTMLGenerator90) could also include a similar export XML method on the DataStore invoked via a user action (e.g., on a shopping cart checkout) for subsequent XML processing.
Published January 1, 2003 Reads 9,453
Copyright © 2003 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Roy Kiesler
Roy Kiesler, a senior lead consultant with Percussion Software in Massachusetts, has worked with PowerBuilder for the past seven years. He now spends most of his time with XML and Java. A winner of the 2001 TeamSybase MVP award, Roy has been a member of TeamSybase since 1999.
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- How PowerBuilder Got Its Groove Back
- The Cloud Has Cross-Border Ambitions
- Ulitzer Names The World's 30 Most Influential Virtualization Bloggers
- Ulitzer Named "New Media" Partner of Greatly Anticipated iStrategy Event in Berlin
- Risks and Enterprise Mobility?
- Steps for Success in Enterprise Mobility?
- Are Mobile Luddites Resisting Mobility?
- The Difference Between Web Hosting and Cloud Computing
- Sybase CTO to Speak at 4th International Cloud Computing Expo
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- Five Reasons to Choose a Private Cloud
- Seeding The Cloud: The Future of Data Management
- The Threat Behind the Firewall
- Economy Drives Adoption of Virtual Lab Technology
- Tips for Efficient PaaS Application Design
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- The Top 250 Players in the Cloud Computing Ecosystem
- Custom Common Dialogs Using SetWindowsHookEx
- DDDW Tips and Tricks
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form
- Book Excerpt: Sybase Adaptive Server Anywhere
- Sybase ASE 12.5 Performance and Tuning
- Working with SOA & Web Services in PowerBuilder
- Office 2003 Toolbar: A New Look For Your Old PowerBuilder App
- Dynamically Creating DataWindow Objects

































