DEV-15: XML in OpenEdge® Past, Present and Future Robin Brown Principal Software Engineer.
-
date post
21-Dec-2015 -
Category
Documents
-
view
230 -
download
0
Transcript of DEV-15: XML in OpenEdge® Past, Present and Future Robin Brown Principal Software Engineer.
DEV-15: XML in OpenEdge®Past, Present and Future
Robin BrownPrincipal Software Engineer
© 2006 Progress Software Corporation2DEV-15: XML in OpenEdge – Past, Present and Future
Why XML is Important
XML.Gov home page, http://xml.gov/index.asp
“Extensible Markup Language (XML) embodies the potential to alleviate many of the interoperability problems associated with the sharing of documents and data.”
© 2006 Progress Software Corporation3DEV-15: XML in OpenEdge – Past, Present and Future
Why XML?• Industry standard format for data exchange
Use Cases• Sending structured data over the Internet
– Back bone of Web Services/SOAP
• Sharing data with 3rd party applications– Crystal Reports
• Persistent storage between 4GL sessions– Context Management
Why XML is Important
© 2006 Progress Software Corporation4DEV-15: XML in OpenEdge – Past, Present and Future
OpenEdge Support for XML
1999 2000 2001 2002 2003 2004 2005 2006
We’re making XML easier to use
X-Document Load/Save
9.1A Sax-Reader
9.1D
Sax-Writer
10.1A
ProDataSet™ to/from XML
XML Schema ValidationWeb Services
Client
10.0A
Web Services Provider
SOA-12
© 2006 Progress Software Corporation5DEV-15: XML in OpenEdge – Past, Present and Future
Agenda
DOM and SAX Review SAX-WRITER Object XML Schema Validation ProDataSet and Temp-Table to/from XML What’s Next
© 2006 Progress Software Corporation6DEV-15: XML in OpenEdge – Past, Present and Future
XML – DOM vs. SAX
Document Object Model (DOM)• W3C standard
• DOM Tree in Memory
• Application logic - Tree traversal & tree building
Simple API for XML (SAX)• De facto standard
• Stream – forward only
• Application logic – Callbacks
© 2006 Progress Software Corporation7DEV-15: XML in OpenEdge – Past, Present and Future
DOM – X-Document:LOAD( )
(Element)Item ID=“1”
(Element)Music
(Text)Mozart’s Requiem
<?xml version=“1.0”?><Music> <Item ID="1">Mozart's Requiem</Item> <Item ID="2">Big Hits</Item></Music>
(Text)Big Hits
(Element)Item ID=“2”
CREATE X-DOCUMENT hDoc.hDoc:LOAD("file", “Music.xml", FALSE).
© 2006 Progress Software Corporation8DEV-15: XML in OpenEdge – Past, Present and Future
DOM – Parsing the Tree and Extracting
CREATE X-DOCUMENT hDoc.CREATE X-NODEREF hRoot.CREATE X-NODEREF hChild.CREATE X-NODEREF hText.
hDoc:LOAD("file", “Music.xml", FALSE).
hDoc:GET-DOCUMENT-ELEMENT(hRoot). /* <Music> */
REPEAT i = 1 TO hRoot:NUM-CHILDREN: hRoot:GET-CHILD(hChild, i). /* <Item> */
IF hChild:NUM-CHILDREN < 1 THEN NEXT.
cID = hChild:GET-ATTRIBUTE(“ID”).
hChild:GET-CHILD(hText, 1). /* Item Text */ CValue = hText:NODE-VALUE. END.
1
2
3
4
5
6
7
8
9
© 2006 Progress Software Corporation9DEV-15: XML in OpenEdge – Past, Present and Future
DOM – Building the Tree and Saving
CREATE X-DOCUMENT hDoc.CREATE X-NODEREF hRoot.CREATE X-NODEREF hChild.CREATE X-NODEREF hText.
hDoc:CREATE-NODE(hRoot,"Music","ELEMENT").hDoc:APPEND-CHILD(hRoot).
hDoc:CREATE-NODE(hChild, "Item", "ELEMENT").hRoot:APPEND-CHILD(hChild).
hChild:SET-ATTRIBUTE("ID", "1").
hDoc:CREATE-NODE(hText, "", "TEXT").hChild:APPEND-CHILD(hText).hText:NODE-VALUE = "Mozart's Requiem".
hDoc:SAVE("file","Music2.xml").
12
34
5
6
7
8
9
© 2006 Progress Software Corporation10DEV-15: XML in OpenEdge – Past, Present and Future
SAX-Reader:PARSE( )
<?xml version=“1.0”?><Music> <Item ID="1"> Mozart's Requiem </Item> </Music>
/* Handler.p */
PROC StartElement: END.
PROC Characters: END.
PROC EndElement: END.
1
2
3
4
5
1 2
3
4 5
CREATE SAX-READER hSax.hSax:SET-INPUT-SOURCE("FILE",
"Music.xml").
RUN Handler.p Persistent SET h. hSax:HANDLER = h.
hSax:PARSE().
© 2006 Progress Software Corporation11DEV-15: XML in OpenEdge – Past, Present and Future
DOM vs. SAX
Advantages Disadvantages
DOM • All data always available
• In-place updates
• Memory Intensive
- Cannot handle large docs
SAX • Much less memory than DOM
• Can stop the parse early
• Can access data from a “bad” document (Partial Load)
• Forward Only
• Requires Context Management
- Callbacks / global variables
© 2006 Progress Software Corporation12DEV-15: XML in OpenEdge – Past, Present and Future
Agenda
DOM and SAX Review SAX-WRITER Object XML Schema Validation ProDataSet and Temp-Table to/from XML What’s Next
© 2006 Progress Software Corporation13DEV-15: XML in OpenEdge – Past, Present and Future
SAX-Writer Functionality
Coding easier than DOM• Fewer objects
SAX-Writer object
CREATE SAX-WRITER
handle [IN WIDGET-POOL pool-name][NO‑ERROR].
Syntax
DEFINE VARIABLE hSAXWriter AS HANDLE NO-UNDO.CREATE SAX-WRITER hSAXWriter NO-ERROR.
Example
© 2006 Progress Software Corporation14DEV-15: XML in OpenEdge – Past, Present and Future
SAX-Writer Object
START-DOCUMENT START-ELEMENT SET-OUTPUT-DESTINATION WRITE-CHARACTERS DECLARE-NAMESPACE
END-DOCUMENT END-ELEMENT INSERT-ATTRIBUTE WRITE-DATA-ELEMENT
Methods (partial list)
ENCODING FRAGMENT STRICT WRITE-STATUS (Read-
Only)
FORMATTED STANDALONE VERSION
Attributes
© 2006 Progress Software Corporation15DEV-15: XML in OpenEdge – Past, Present and Future
SET-OUTPUT-DESTINATION ( )
handle:SET-OUTPUT-DESTINATION (mode,{file|stream|memptr|longchar}).
Defines the target for XML document
CREATE SAX-WRITER hSAXWriter.
ret = hSAXWriter:SET-OUTPUT-DESTINATION
(“FILE”,“C:\OpenEdge\WRK\swMusic.xml”).
Syntax
Example
© 2006 Progress Software Corporation16DEV-15: XML in OpenEdge – Past, Present and Future
Invoke Methods in Typical Order
CREATE SAX-WRITER SET-OUTPUT-DESTINATION START-DOCUMENT START-ELEMENT START-ELEMENT INSERT-ATTRIBUTE WRITE-DATA-ELEMENT
END-ELEMENT WRITE-CHARACTERS END-ELEMENT
END-DOCUMENT
© 2006 Progress Software Corporation17DEV-15: XML in OpenEdge – Past, Present and Future
SAX–WRITER Example
CREATE SAX-WRITER hSaxW.
hSaxW:SET-OUTPUT-DESTINATION("file", "swMusic.xml").
hSaxW:START-DOCUMENT().
hSaxW:START-ELEMENT("Music").
hSaxW:START-ELEMENT("Item").
hSaxW:INSERT-ATTRIBUTE("ID", "1").
hSaxW:WRITE-CHARACTERS("Mozart's Requiem").
hSaxW:END-ELEMENT("Item").
hSaxW:END-ELEMENT("Music").
hSaxW:END-DOCUMENT().
1
2
3
4
5
6
7
8
9
© 2006 Progress Software Corporation18DEV-15: XML in OpenEdge – Past, Present and Future
/* STRICT = TRUE. */ START-DOCUMENT START-ELEMENT START-ELEMENT WRITE-DATA-ELEMENT
END-ELEMENT WRITE-CHARACTERSEND-DOCUMENT
STRICT Attribute
Forces XML to be well-formed
END-DOCUMENTFAILS!
© 2006 Progress Software Corporation19DEV-15: XML in OpenEdge – Past, Present and Future
Agenda
DOM and SAX Review SAX-WRITER Object XML Schema Validation ProDataSet and Temp-Table to/from XML What’s Next
© 2006 Progress Software Corporation20DEV-15: XML in OpenEdge – Past, Present and Future
XML Schema Validation
Verify that data adheres to an agreed upon format
Validation occurs at runtime • X-Document Object
– LOAD( )
• Sax-Reader Object– PARSE( )– PARSE-FIRST( )– PARSE-NEXT( )
© 2006 Progress Software Corporation21DEV-15: XML in OpenEdge – Past, Present and Future
Schema Validation
Pre-10.1A - DTD• Document Type Definition• Older technology• XML Document MUST contain or specify DTD
10.1A - XSD• XML Schema Definition• Emerging standard (W3C)• XSD can be external to XML
Both DTD and XSD supported in 10.1A
© 2006 Progress Software Corporation22DEV-15: XML in OpenEdge – Past, Present and Future
New Method / Attributes
Method• ADD-SCHEMA-LOCATION
Attributes• SCHEMA-LOCATION
• NONAMESPACE-SCHEMA-LOCATION
Applies to X-Document and Sax-Reader objects
© 2006 Progress Software Corporation23DEV-15: XML in OpenEdge – Past, Present and Future
DOM Example
CREATE X-DOCUMENT hDoc.
hDoc:ADD-SCHEMA-LOCATION ("urn:music", "Music.xsd").
hDoc:LOAD("file", "Music.xml", TRUE /* validate */).
© 2006 Progress Software Corporation24DEV-15: XML in OpenEdge – Past, Present and Future
SAX Example
CREATE SAX-READER hSax.
hSax:SET-INPUT-SOURCE (“file”, “Music.xml”).
hSax:SCHEMA-LOCATION = “urn:music Music.xsd”.
hSax:VALIDATION-ENABLED = TRUE. /* validate */
hSax:PARSE( ).
© 2006 Progress Software Corporation25DEV-15: XML in OpenEdge – Past, Present and Future
Agenda
DOM and SAX Review SAX-WRITER Object XML Schema Validation ProDataSet and Temp-Table to/from XML What’s Next
© 2006 Progress Software Corporation26DEV-15: XML in OpenEdge – Past, Present and Future
ProDataSet Functionality Continues to Mature
DataSet
ttOrder
ttOline
Query
hSource
defaultQuery
order query
oline query
Query Buffer
hSource
defaultQuery
Query Buffer
OpenEdge 10.1A simplifies and adds options for working with ProDataSets
© 2006 Progress Software Corporation27DEV-15: XML in OpenEdge – Past, Present and Future
New Methods Added
WRITE-XML WRITE-XMLSCHEMA READ-XML READ-XMLSCHEMA
Methods apply to• ProDataSet• Temp-Table• Temp-Table Buffer
.xsd.xsd
DataSet
ttOrder
ttOline
.xml.xml
ttItem
© 2006 Progress Software Corporation28DEV-15: XML in OpenEdge – Past, Present and Future
WRITE-XML (target-type,
{file | stream | memptr | handle | longchar}
[, formatted [, encoding
[, schema-location, [, write-schema
[, min-schema, write-before-image]]]]]])
WRITE-XML ( )
Syntax
DataSet
ttOrder
ttOline
.xml .xmlttItem
(*write-before-image for ProDataSets only)
© 2006 Progress Software Corporation29DEV-15: XML in OpenEdge – Past, Present and Future
TEMP-TABLE ttItem:WRITE-XML
("FILE", /*target-type*/
"ttItemXML.xml", /* file name */
TRUE, /* formatted */
?, /* encoding */
?, /* schema location */
?, /* write schema */
?). /* min XML Schema */
Temp-table Example
Format the output
© 2006 Progress Software Corporation30DEV-15: XML in OpenEdge – Past, Present and Future
Data ONLY - Temp-Table ttItem
© 2006 Progress Software Corporation31DEV-15: XML in OpenEdge – Past, Present and Future
ProDataSet Example – XML with Schema
DATASET dsOrder:WRITE-XML ("FILE",
"DSWriteXMLAndSchema.xml",
TRUE, /* formatted */
?, /* encoding */
?, /* schema location */
TRUE, /* write schema */
TRUE, /* min XML Schema */
?). /* writebeforeimage */
Write XML Schema with the
data
© 2006 Progress Software Corporation32DEV-15: XML in OpenEdge – Past, Present and Future
ProDataSet Example – writeschema=TRUE
XML data
XML Schema
© 2006 Progress Software Corporation33DEV-15: XML in OpenEdge – Past, Present and Future
ProDataSet Example – writeschema=TRUE
XML data
© 2006 Progress Software Corporation34DEV-15: XML in OpenEdge – Past, Present and Future
ProDataSet Example – XML with Before-Tables
DATASET myds:WRITE-XML("FILE", /* target-type */
“custOrdBefore.xml", /*file*/
TRUE, /* formatted */
?, /* encoding */
?, /* schema location */
?, /* write schema */
?, /* min XML schema */
TRUE)./* write beforeimage */
Write the Before Table data
© 2006 Progress Software Corporation35DEV-15: XML in OpenEdge – Past, Present and Future
ProDataSet – writebeforeImage = TRUE
Record marked as “created”
Record marked as “modified”
After table data
© 2006 Progress Software Corporation36DEV-15: XML in OpenEdge – Past, Present and Future
ProDataSet – writebeforeImage = TRUE
Before-image of modified record
© 2006 Progress Software Corporation37DEV-15: XML in OpenEdge – Past, Present and Future
.xsd
WRITE-XMLSCHEMA ( )
Write XML Schema Definition (XSD)
• For Temp-Tables contains – Table definition,
including indexes
• For ProDataSets contains– Table definitions,
including indexes– Data relation
definitions
DataSet
ttOrder
ttOlinettItem
.xsd
© 2006 Progress Software Corporation38DEV-15: XML in OpenEdge – Past, Present and Future
Using with Temp-Tables and ProDataSets
WRITE-XMLSCHEMA (target-type, {file |
stream | memptr | handle | longchar}
[, formatted [, encoding
[, min-xmlschema ]]])
min-xmlschema – • if TRUE only write standard XML Schema
structures• if FALSE, add XML Schema extensions from
‘prodata’ namespace– Allows round-trip of Progress definition
Syntax
© 2006 Progress Software Corporation39DEV-15: XML in OpenEdge – Past, Present and Future
Progress XML Schema Extensions
Standard XML Schema
Dataset DataSet / Table names
Table Table / Field names
Field Name
Data Type
Extent
Initial value
Index Unique Indexes
Relation Unique Data-Relations
XML Schema Extensions
None
Temp-Table UNDO status
Format
Label
Decimals
Case-sensitive
Read-only...
Non-unique Indexes
Non-Unique Data-Relations
+
MIN-SCHEMA = TRUE
MIN-SCHEMA = FALSE
© 2006 Progress Software Corporation40DEV-15: XML in OpenEdge – Past, Present and Future
TEMP-TABLE ttItem:WRITE-XMLSCHEMA
("FILE", /*target-type*/
"ttItem.xsd", /* file name */
TRUE, /* formatted */
?, /* encoding */
FALSE). /* min XML Schema */
Temp-table Example
Write XML Schema
Extensions
© 2006 Progress Software Corporation41DEV-15: XML in OpenEdge – Past, Present and Future
Progress XML Schema Extensions
non-unique index definition
field-level attributes
“prodata” namespace
© 2006 Progress Software Corporation42DEV-15: XML in OpenEdge – Past, Present and Future
XML Read Methods
READ-XML
READ-XMLSCHEMA .xsd
.xsdDataSet
ttOrder
ttOline
.xml
.xml
ttItem
© 2006 Progress Software Corporation43DEV-15: XML in OpenEdge – Past, Present and Future
READ-XML Method
READ-XML (source-type,
{file | memptr | handle | longchar}
, read-mode
, schema‑location
, override-default-mapping
[, field-type-mapping
[, verify-schema-mode ]])
Syntax
Populates ProDataSet or Temp-Table with:• XML data, XML Schema, or Both
© 2006 Progress Software Corporation44DEV-15: XML in OpenEdge – Past, Present and Future
Reads XML containing Before-Image information
–Progress “datasetChanges”
–Microsoft “Diffgram”
ProDataSet events DO NOT fire
Change tracking is turned OFF
Reading XML Into A ProDataSet
READ-XML( )
© 2006 Progress Software Corporation45DEV-15: XML in OpenEdge – Past, Present and Future
Using READ-XMLSCHEMA( )
Create a Progress definition from XML Schema
Verify XML Schema against Progress definition
READ-XMLSCHEMA (source-type,
{file | memptr | handle | longchar}
, override-default-mapping
[, field-type-mapping
[, verify-schema-mode ]])
Syntax
© 2006 Progress Software Corporation46DEV-15: XML in OpenEdge – Past, Present and Future
New XML Attributes
Attribute Applies to...
NAMESPACE-URI / NAMESPACE-PREFIX
ProDataSet, Temp-Table and Buffer
XML-NODE-TYPE Buffer-Field
XML-DATA-TYPE Buffer-Field
NESTED Data-Relation
Available on static definitions• DEFINE DATASET, TEMP-TABLE, BUFFER
Gives you Control over XML format
© 2006 Progress Software Corporation47DEV-15: XML in OpenEdge – Past, Present and Future
XML-NODE-TYPE = “Attribute”
BUFFER ttItem:BUFFER-FIELD(1):XML-NODE-TYPE = “Attribute”.
© 2006 Progress Software Corporation48DEV-15: XML in OpenEdge – Past, Present and Future
NESTED Attribute ProDataSet Data-Relation
Order Records NESTED within
Customer 1
DATASET CustOrder:GET-RELATION(“custOrd”):NESTED = TRUE.
© 2006 Progress Software Corporation49DEV-15: XML in OpenEdge – Past, Present and Future
ProDataSet and Temp-Table To/From XML
Easier than DOM and SAX • Productivity increase
Faster than DOM and SAX• Performance increase
Relational structure maps well to XML• XML data (.xml)
• XML Schema (.xsd)
The right features for the right job!
© 2006 Progress Software Corporation50DEV-15: XML in OpenEdge – Past, Present and Future
ProDataSet and Temp-Table To/From XML
Easier than SAX and DOM • Productivity increase
Faster than SAX and DOM• Performance increase
Relational structure maps well to XML• XML data (.xml)
• XML Schema (.xsd)
The right features for the right job!
DOM and SAX still have their
uses!
© 2006 Progress Software Corporation51DEV-15: XML in OpenEdge – Past, Present and Future
Demo
© 2006 Progress Software Corporation52DEV-15: XML in OpenEdge – Past, Present and Future
Agenda
DOM and SAX Review SAX-WRITER Object XML Schema Validation ProDataSet and Temp-Table to/from XML What’s Next
© 2006 Progress Software Corporation53DEV-15: XML in OpenEdge – Past, Present and Future
D I S C L A I M E R
Under Development
This talk includes information about potential future products and/or product enhancements.
What I am going to say reflects our current thinking, but the information contained herein is preliminary and subject to change. Any future products we ultimately deliver may be materially different from what is described here.
D I S C L A I M E R
© 2006 Progress Software Corporation54DEV-15: XML in OpenEdge – Past, Present and Future
XML Futures
SAX-ATTRIBUTES XSLT XPath / XQuery Support for XML 1.1 / 2.0
© 2006 Progress Software Corporation55DEV-15: XML in OpenEdge – Past, Present and Future
In Summary
XML is Key Component in SOA Architectures
OpenEdge provides the ABL to work with XML
We’re continuing to make working with XML easier
© 2006 Progress Software Corporation56DEV-15: XML in OpenEdge – Past, Present and Future
For More Information...
Relevant Exchange Sessions• DEV-9: Using the ProDataSet in OpenEdge 10
• SOA-12: Integrate over the Web with OpenEdge Web Services
Other Resources• PSDN
• http://www.xml.com
© 2006 Progress Software Corporation57DEV-15: XML in OpenEdge – Past, Present and Future
Education / Documentation References
Course• XML Essentials • 4GL Development with XML• What's New in OpenEdge 10.1: SOA Support
Documentation• OpenEdge Development: Progress 4GL
Reference• OpenEdge Development: Programming
Interfaces
© 2006 Progress Software Corporation58DEV-15: XML in OpenEdge – Past, Present and Future
Questions?
© 2006 Progress Software Corporation59DEV-15: XML in OpenEdge – Past, Present and Future
Thank you foryour time
© 2006 Progress Software Corporation60DEV-15: XML in OpenEdge – Past, Present and Future