380 likes | 703 Views
E174 DataWindows, XML & XSL-FO in PowerBuilder 9.0. Angelo Scipione Staff S/W Engineer Sybase, Enterprise Solutions Div. Scipione@sybase.com. Agenda. Review the basic concepts of XML Defining XML Templates in the DataWindow Painter
E N D
E174 DataWindows, XML & XSL-FOin PowerBuilder 9.0 • Angelo Scipione • Staff S/W Engineer • Sybase, Enterprise Solutions Div. • Scipione@sybase.com
Agenda • Review the basic concepts of XML • Defining XML Templates in the DataWindow Painter • New DataWindow Properties to control exporting & importing XML • Enhanced methods for exporting & importing XML • Generating XSL-FO
Review of XML Extensible Markup Language • Extends the ability to represent data • Metadata language=tags & layout can be customized • Data can be hierarchically structured with nesting • Easily parsed across applications, platforms, enterprises, and Web for data interchange • Spec at http://www.w3.org/TR/REC-xml
XML Document • Well-Formed if structure follows XML syntax rules • Contains one or more elements • Element is a tree containing start-tag, content, end-tag • Start-tag is a name, enclosed by angle brackets, with optional attributes • One root; all element tags properly nested • Valid if structure conforms to a DTD or Schema • DTD defines grammar for XML document • Subset can be internal or external
XML Parsing DOM Parser • DOM provides API access to XML tree model • Useful if manipulating or re-traversing the document SAX Parser • Event-driven • Useful if extracting data once in single traversal Apache Xerces-C++ integrated in PowerBuilder 9.0 • More on this (PBDOM) presented in E 171
XML Modeled by DOM Tree <?xml version=“1.0” encoding=“UTF-8”?> <!DOCTYPE menu SYSTEM menu.dtd> <menu> <meal name=“breakfast”> <food> Scrambled Eggs </food> <food> Hash Browns </food> <drink> Orange Juice </drink> </meal> <meal name=“snack”> <food> Chips </food> </meal> </menu> menu meal meal name food food drink “breakfast” “Scrambled Eggs” “Hash Browns” “Orange Juice”
DataWindow Data Templates • Defines the mapping between values from a DataWindow and locations in an external document format, like XML • References can be: • DataWindow control values (text) • Columns • Computed Fields • Texts • DataWindow Expressions (evaluated at runtime) • Columns
DataWindow Data Templates • References are specific to a DataWindow’s namespace • Persists as its child object in PBL, SRD • Can save more than one for a DataWindow • Must be uniquely named • Template employed at runtime by name with the new UseTemplate DataWindow Property • Used for data export and/or import
Other Items in an Export XML Template • XML declaration • Document Type declaration • Root element (required) • Child elements (any level of nesting) • Attributes • Literal text • Comments • Processing instructions • CDATA sections
Export XML Template Divided in 2 Header Section Optionally contains: • XML declaration (dialog) • Document type declaration (dialog) • Comments (dialog) • Processing instructions (dialog) • Root element (required) • Child elements (non-iterative)
Export XML Template Divided in 2 Detail Section Iterated for each row; can contain: • Detail (row) Start element • Child or sibling elements to the Detail Start element • Content and Attribute values (dialog) • DataWindow control references (dialog or drag-drop) • DataWindow Expressions (dialog) • Literal text • Comments, PIs, and CDATA sections
View Features • Item-specific context menus, label-editing & dialogs • Header/Detail marked by line across TreeView • Drag-and-drop from Control List View and Column Specification View • View-level menu • New • New Default • Open (dialog) • Save, SaveAs (dialog) • Delete
Default Template Contains: • XML declaration • Root element (defaults to DataWindow name) • Detail Start element (defaults to DW name + “_row”) • Child elements of the Detail Start element named for each DataWindow column with content reference • Useful as starting point • Same structure assumed at runtime if no UseTemplate specified on XML export or import
DataWindow Properties in PowerScript Export.XML.UseTemplate Controls logical structure of XML data exported by DW PowerBuilder dot notation: dw_control.Object.DataWindow.Export.XML.UseTemplate Describe and Modify argument: “DataWindow.Export.XML.UseTemplate { = ‘value’ }”
DataWindow Properties in PowerScript Export.XML.TemplateCount Returns number of Templates saved for DataWindow PowerBuilder dot notation: dw_control.Object.DataWindow.Export.XML.TemplateCount Describe argument: “DataWindow.Export.XML.TemplateCount”
DataWindow Properties in PowerScript Export.XML.Template[1..n].Name Returns name of Template by array index (storage order) PowerBuilder dot notation: dw_control.Object.DataWindow.Export.XML.Template[1..n].Name Describe argument: “DataWindow.Export.XML.Template[” + n + “].Name”
Runtime Template Enumeration Example String ls_template_count, ls_template_name Long l_template_count, i l_template_count = & Long(dw_1.Object.DataWindow.Export.XML.TemplateCount) For i = 1 to l_template_count ls_template_name = & dw_1.Object.DataWindow.Export.XML.Template[i].Name ddlb_1.AddItem(ls_template_name) Next
DataWindow Properties in PowerScript Export.XML.MetaDataType Controls type of metadata to accompany exported XML PowerBuilder dot notation: dw_control.Object.DataWindow.Export.XML.MetaDataType Describe and Modify argument: “DataWindow.Export.XML.MetaDataType { = ‘value’ }”
DataWindow Properties in PowerScript Export.XML.SaveMetaData Controls location of generated metadata PowerBuilder dot notation: dw_control.Object.DataWindow.Export.XML.SaveMetaData Describe and Modify argument: “DataWindow.Export.XML.SaveMetaData { = ‘value’ }”
Methods to Export XML DataWindow Painter File…Save Rows As… menu item Save as type: XML
Methods to Export XML SaveAs method integer dwcontrol.SaveAs ( string filename, saveastype saveastype, boolean colheading ) SaveAsType
DataWindow Properties in PowerScript Data.XML String containing DataWindow data exported in XML PowerBuilder dot notation: dw_control.Object.DataWindow.Data.XML Describe argument: “DataWindow.Data.XML”
DataWindow Properties in PowerScript Data.XMLSchema String containing XML Schema generated from Template PowerBuilder dot notation: dw_control.Object.DataWindow.Data.XMLSchema Describe argument: “DataWindow.Data.XMLSchema”
DataWindow Properties in PowerScript Data.XMLDTD String containing DTD generated from Template PowerBuilder dot notation: dw_control.Object.DataWindow.Data.XMLDTD Describe argument: “DataWindow.Data.XMLDTD”
Importing XML Data into DataWindow • Analogous to XML export • Piggybacks off of Export XML Template to interpret the logical structure and DataWindow mapping of XML document to import • Uses SAX parser for performance • DataWindow Import methods enhanced
DataWindow Properties in PowerScript Import.XML.UseTemplate Controls logical structure of XML data imported by DW PowerBuilder dot notation: dw_control.Object.DataWindow.Import.XML.UseTemplate Describe and Modify argument: “DataWindow.Import.XML.UseTemplate { = ‘value’ }”
Methods to Import XML long dwcontrol.ImportFile ( { saveastype importtype, } string filename {, long startrow {, long endrow {, long startcolumn {, long endcolumn {, long dwstartcolumn }}}}} ) long dwcontrol.ImportString ( { saveastype importtype, } string string {, long startrow {, long endrow {, long startcolumn {, long endcolumn {, long dwstartcolumn }}}}} ) long dwcontrol.ImportClipboard ( { saveastype importtype {, long startrow {, long endrow {, long startcolumn {, long endcolumn {, long dwstartcolumn }}}}}} )
XSL-FO Generator XSL Formatting Objects • Second part of XSL W3C Recommendation covering presentation of XML • Spec at http://www.w3.org/TR/xsl/slice6.html#fo-section • XSL-FO processors can render to PDF • Apache XML FOP Project • http://xml.apache.org/fop
DataWindow Properties in PowerScript Data.XSLFO String containing DataWindow data & presentation in XSL Formatting Objects PowerBuilder dot notation: dw_control.Object.DataWindow.Data.XSLFO Describe argument: “DataWindow.Data.XSLFO”
Sybase Developer Network (SDN) Additional Resources for Developers/DBAs • Single point of access to developer software, services, and up-to-date technical information: • White papers and documentation • Collaboration with other developers and Sybase engineers • Code samples and beta programs • Technical recordings • Free software • Join today: www.sybase.com/developer or visit SDN at TechWave’s Technology Boardwalk