Presentation is loading. Please wait.

Presentation is loading. Please wait.

Knowledge Transfer: DataWindow XML Export/Import in PowerBuilder 9.0.

Similar presentations


Presentation on theme: "Knowledge Transfer: DataWindow XML Export/Import in PowerBuilder 9.0."— Presentation transcript:

1 Knowledge Transfer: DataWindow XML Export/Import in PowerBuilder 9.0

2 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. n John Strano n PowerBuilder Evangelist n

3 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Module Objectives n Review the basic concepts of XML n Defining XML Templates in the DataWindow Painter n New Properties to control exporting & importing DataWindow data in XML n Enhanced methods for exporting & importing DataWindow data in XML n Generating DataWindow presentation in XSL-FO n PowerScript functions for XML document parsing/validation

4 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Review of XML Extensible Markup Language n Extends the ability to represent data n Metadata language=tags & layout can be customized n Data can be hierarchically structured with nesting n Easily parsed across applications, platforms, enterprises, and Web for data interchange n World Wide Web Consortium (W3C) XML 1.0 Recommendation at

5 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Document n Well-Formed if structure follows XML syntax rules l Contains one or more elements s Element is a tree containing start-tag, content, end-tag Start-tag is a name, enclosed by angle brackets, with optional attributes Attribute names must be unique for element; order insignificant Attribute values must be quoted l One root; all element tags properly nested s Parsed element cannot contain recursive reference to itself n Valid if structure conforms to a DTD or Schema l DTD defines grammar for XML document s Subset can be internal or external

6 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Names and Entity References n XML Names l can only contain alphanumeric characters (also non-english, such as ä, ç etc.), _ Underscore, - Hyphen,. Period l have to start with letter or underscore l are case-sensitive n Predefined entity references cannot occur within element text content and have to be replaced l < replaces < (less-than sign) l > replaces > (greater-than sign) l & replaces & (ampersand) l " replaces '' (double quote) l &apos replaces ' (single quote)

7 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Document Example  root element Fran  text content Whitney  empty element  alternative notation

8 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Parsing DOM Parser n DOM provides API access to XML tree model n Useful if manipulating or re-traversing the document SAX Parser n Event-driven n Useful if extracting data once in single traversal Core Interfaces Specified by W3C n Extensions denoted by ‘DOM Level 2’, ‘DOM Level 3’

9 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Industry-leading Parser Implementations Java n Apache Xerces Java n JDOM l Higher level than DOM interface Native n MSXML n Apache Xerces-C++ l Ports available on Win32, Solaris, HP-UX, AIX

10 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Parsing in PowerBuilder 9.0 Apache Xerces-C++ Integration n Integrated as internal ‘XML Service’ in PBXerces90.dll n PB9 GA dependent on xerces-c_1_5_1.dll n Post-PB9 likely dependent on xerces-c_2_1_0.dll n Consumed by: l DataWindow Painter l DataWindow Engine s Deploy with Pbdwe90.dll for DW XML apps l PBVM s If calling PowerScript XML parse/validation functions l PBDom90.dll (PBDom90.pbd) s More on this (PBDOM) presented in KT by Bio Liong Lim

11 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Modeled by DOM Tree Scrambled Eggs Hash Browns Orange Juice Chips menu meal drinkfood name “Orange Juice” “Hash Browns” “Scrambled Eggs” “breakfast” meal

12 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Mapping DataWindow to DOM Tree

13 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow Export/Import Template n Defines the mapping between values from a DataWindow and locations in an external document format, like XML n References can be: l DataWindow control values (text) s Column s Computed column s Text control s Computed field s Nested report l DataWindow Expressions (evaluated at runtime) s Data source column

14 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow Export/Import Template n References in Template are specific to a DW namespace n Template persists within DW definition in PBL & SRD as a dependent object n Multiple Templates may be defined & saved for a DW n Each must be uniquely named within a DW namespace n Template applied at runtime or in Painter by name with the new DW property UseTemplate n Used for DW data export, data import, or both

15 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Export/Import Template - XML View DataWindow Painter

16 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Other Items in an XML Template n XML declaration n Document Type declaration n Root element (required) n Child elements (any level of nesting) n Attributes n Literal text n Comments n Processing instructions n CDATA sections

17 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Template Divided in 2 Header Section Optionally contains: n XML declaration (dialog) n Document type declaration (dialog) n Comments (dialog) n Processing instructions (dialog) n Root element (required) n Child elements (non-iterative) n Group Header elements* (iterative) l Child elements (iterative)

18 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Template Divided in 2 Detail Section Iterated for each row; can contain: n Detail (Row) Start element* n Child or sibling elements to the Detail Start element n Content and Attribute values (dialog) l DataWindow control references (dialog) s Drag-drop from the Control List View l DataWindow Expressions (dialog) s Drag-drop from the Column Specification View n Literal text n Comments, PIs, and CDATA sections

19 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Attributes Dialog

20 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. View Features n Item-specific context menus, label-editing & dialogs n Header/Detail marked by line across TreeView n Drag-and-drop from Control List View and Column Specification View n View-level menu s New s New Default s Open (dialog) s Save, SaveAs (dialog) s Delete

21 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Default Template Contains: n XML declaration n Root element (defaults to DataWindow name) n Detail Start element (defaults to DW name + “_row”) n Child elements of the Detail Start element named for each DataWindow column with content reference n Useful as starting point n Same structure assumed for XML export or import in Painter or at runtime if no UseTemplate specified

22 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Grouped DataWindow: Grouping Elements in Template

23 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Nested & Composite DataWindows: Referencing a Nested Report in Template

24 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow Properties View

25 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow Properties in PowerScript Export.XML.UseTemplate Controls logical structure & mapping of XML data exported by DataWindow. PowerBuilder dot notation: dw_control.Object.DataWindow.Export.XML.UseTemplate Describe and Modify argument: “ DataWindow.Export.XML.UseTemplate { = ‘value’ }”

26 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. 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”

27 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. 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”

28 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Runtime Template Enumeration Example

29 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow Properties in PowerScript Export.XML.HeadGroups Controls iteration of elements in Template Header section as group headers. PowerBuilder dot notation: dw_control.Object.DataWindow.Export.XML.HeadGroups Describe and Modify argument: “ DataWindow.Export.XML.HeadGroups { = value }”

30 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow Properties in PowerScript Export.XML.IncludeWhitespace Controls formatting of exported XML document by including whitespace to beautify. PowerBuilder dot notation: dw_control.Object.DataWindow.Export.XML.IncludeWhitespace Describe and Modify argument: “ DataWindow.Export.XML.IncludeWhitespace { = value }”

31 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. 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 }”

32 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. 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 }”

33 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Example XMLDocument n XML Document with external grammar references - or R & D 501 …

34 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Example DTD

35 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Example XMLSchema

36 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Schema Options Dialog

37 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Methods to Export XML Data DataWindow Painter File…Save Rows As… menu item Save as type: XML

38 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Methods to Export XML Data SaveAs method integer dwcontrol. SaveAs ( string filename, saveastype saveastype, boolean colheading ) SaveAsType

39 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. 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”

40 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. 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”

41 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. 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”

42 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Importing XML Data into DataWindow n Analogous to XML export n DataWindow Import methods enhanced n XML Default Import l Assumes coincident column data in XML document n XML Template Import l Piggybacks off same XML Template as for export to interpret logical structure and DataWindow mapping of XML document to import n Internally uses SAX parser for performance

43 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Methods to Import XML Data 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 }}}}}} ) Example: dw_1.ImportFile( XML!, "c:\temp\customers.xml") Possible SaveAsTypes for import are XML!, CSV! and TXT!

44 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow XML Default Import n Import without Import.XML.UseTemplate specified n XML document data (element text content) has to correspond to DataWindow column definition n XML element text content is imported in order of occurrence within XML document n Element tag names and all other content of the XML document are ignored n XML nesting within the document is disregarded

45 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Empty Elements in XML Default Import n Empty elements are assumed to be empty values and imported as such into the DataWindow column n An element that contains only space, carriage return, new line or tab characters is treated as an empty element n An element that contains no text content, but any other content, e.g. a child element or comment, it is not regarded as an empty element and will be skipped for import

46 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Example XML Default Import XML Document: 102  empty element Fran Whitney Column Import into DataWindow: Column 1Column 2Column 3Column FranWhitney

47 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Advantages of XML Template Import n XML document structure doesn’t have to match DataWindow columns n Order of elements within XML doesn’t have to reflect DataWindow column order n Attribute values can be imported

48 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow XML Template Import n Import Template needs to be created in DataWindow painter XML Template View n Template for export may be reused for import n Import.XML.UseTemplate property needs to be set in DataWindow painter or programmatically NOTE : Nested DataWindow XML export supported via SaveAs() per TeamSybase request. But, like other import formats XML import does not currently support importing nested output.

49 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Template View

50 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Import Template n Defines mappings between XML element and attribute names of the XML document and DataWindow column names n Reflects nesting level where element and/or attribute import items can be located within the XML document n If “Starts Detail” marker exists, element and attribute contents above this marker line are ignored n If “Starts Detail” marker does not exist, all element and attribute mappings within the template are used for import n Other information within the Template (controls, comments, etc.) is ignored

51 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Example XML Document Fran Whitney 49 East Washington Street Needham MA

52 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Example XML Template Import

53 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Import Properties in the DW Painter

54 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow Properties in PowerScript Import.XML.UseTemplate Controls logical structure & mapping of XML data imported by DataWindow. PowerBuilder dot notation: dw_control.Object.DataWindow.Import.XML.UseTemplate Describe and Modify argument: “ DataWindow.Import.XML.UseTemplate { = ‘value’ }”

55 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow Properties in PowerScript Import.XML.Trace Enables trace logging during DataWindow XML import. PowerBuilder dot notation: dw_control.Object.DataWindow.Import.XML.Trace Describe and Modify argument: “ DataWindow.Import.XML.Trace { = ‘value’ }”

56 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. DataWindow Properties in PowerScript Import.XML.TraceFile Specifies name of file for DataWindow XML import trace logging. PowerBuilder dot notation: dw_control.Object.DataWindow.Import.XML.TraceFile Describe and Modify argument: “ DataWindow.Import.XML.TraceFile { = ‘value’ }”

57 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Generating DataWindow Presentation in XML: XSL-FO XSL Formatting Objects n Part 2 of XSL W3C Recommendation covering presentation or formatting of XML n XSL 1.0 (aka XSL-FO) Recommendation at: n XSL-FO processors can render to PDF, etc. l Apache XML FOP Project s l Check Software on left side of: s

58 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Methods to Export XML Presentation DataWindow Painter File…Save Rows As… menu item Save as type: XSL-FO

59 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Methods to Export XML Presentation SaveAs method integer dwcontrol. SaveAs ( string filename, saveastype saveastype, boolean colheading ) SaveAsType

60 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. 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”

61 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Processing XSL-FO to PDF using FOP

62 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. PowerScript XML Parsing/Validation n Parsing/validation of XML document in PowerScript l can determine whether XML document is wellformed s complies to W3C XML specification l can determine whether XML document is valid s also matches a given grammar (DTD or XMLSchema) l uses Apache Xerces SAX l needs PBXerces90.dll and Xerces-C_1_5_1.dll in the path NOTE : The Apache Xerces parser does not support parsing internal XMLSchema (MS format) although this can be generated with SaveAs()

63 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. XML Parsing/Validation Functions New PowerScript system functions: n XMLParseFile l long = XMLParseFile(string xmlfilename {,valscheme validationscheme } {,string parsingerrors } {,boolean namespaceprocessing {,boolean schemaprocessing {,boolean schemafullchecking }}}) n XMLParseString l long = XMLParseString(string xmlstring {,valscheme validationscheme } {,string parsingerrors } {,boolean namespaceprocessing {,boolean schemaprocessing {,boolean schemafullchecking }}})

64 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Validation Scheme n ValScheme – new PowerBuilder enumerated value l ValNever! s Only check for wellformedness l ValAlways! s Validate the XML document. If no DTD or XMLSchema exists the parse check will give an error l ValAuto! s If DTD or XMLSchema exists validate the XML document, otherwise check for wellformedness only Example, checking XML file for wellformedness only: XMLParseFile(“c:\temp\mydoc.xml”, ValNever!)

65 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Suppressing Error Messages n To suppress the error message box when the parser detects errors supply the optional argument string parsingerrors Example: long ll_ret string ls_err ll_ret = XMLParseFile(“c:\temp\mydoc.xml”, ls_err) If ll_ret <> 0 then // do something, XMLParseFile returned error End if

66 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Further Grammar Parsing Arguments n namespaceprocessing (defaults to FALSE) l If TRUE, the parser enforces the rules defined by the name space specification l If the validationscheme is set to ValAlways or ValAuto, then the document must contain a grammar that supports name spaces n schemaprocessing (defaults to FALSE) l If TRUE, the parser will process XMLSchema l namespaceprocessing must also be turned on n schemafullchecking (defaults to FALSE) l If TRUE the schema grammar itself is checked for additional errors l Only takes effect if schemaprocessing is set to TRUE

67 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. More Parsing/Validation Examples n If external XMLSchema is referenced the document will be validated, otherwise the parser will check for wellformedness: l XMLParseFile(“c:\temp\mydoc.xml”, TRUE, TRUE) n Parses XML document string, validates against a referenced XMLSchema (has to exist), saves any possible errors in a string variable (suppresses message boxes on error): l XMLParseString(s_myXMLstring, ValAlways!, ls_err, TRUE, TRUE) n Parses XML document, validates against a referenced XMLSchema (has to exist) – also parses Schema itself for additional errors: l XMLParseFile(“c:\temp\mydoc.xml”, ValAlways!, TRUE TRUE,TRUE)

68 ©2000 Sybase, Inc. and its subsidiaries. All rights reserved. Q & A n John Strano n PowerBuilder Evangelist n


Download ppt "Knowledge Transfer: DataWindow XML Export/Import in PowerBuilder 9.0."

Similar presentations


Ads by Google