Title: DEV15: XML in OpenEdge Past, Present and Future
1DEV-15 XML in OpenEdgePast, Present and Future
Robin Brown
Principal Software Engineer
2Why XML is Important
Extensible Markup Language (XML) embodies the
potential to alleviate many of the
interoperability problems associated with the
sharing of documents and data.
XML.Gov home page, http//xml.gov/index.asp
3Why XML is Important
- 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
4OpenEdge Support for XML
9.1A
X-Document Load/Save
Were making XML easier to use
1999 2000 2001 2002 2003
2004 2005 2006
5Agenda
- DOM and SAX Review
- SAX-WRITER Object
- XML Schema Validation
- ProDataSet and Temp-Table to/from XML
- Whats Next
6XML 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
7DOM X-DocumentLOAD( )
lt?xml version1.0?gt ltMusicgt ltItem
ID"1"gtMozart's Requiemlt/Itemgt ltItem
ID"2"gtBig Hitslt/Itemgt lt/Musicgt
CREATE X-DOCUMENT hDoc. hDocLOAD("file",
Music.xml", FALSE).
(Element) Music
(Element) Item ID2
(Element) Item ID1
(Text) Mozarts Requiem
(Text) Big Hits
8DOM Parsing the Tree and Extracting
CREATE X-DOCUMENT hDoc. CREATE X-NODEREF
hRoot. CREATE X-NODEREF hChild. CREATE X-NODEREF
hText. hDocLOAD("file", Music.xml",
FALSE). hDocGET-DOCUMENT-ELEMENT(hRoot). /
ltMusicgt / REPEAT i 1 TO hRootNUM-CHILDREN
hRootGET-CHILD(hChild, i). / ltItemgt /
IF hChildNUM-CHILDREN lt 1 THEN NEXT.
cID hChildGET-ATTRIBUTE(ID).
hChildGET-CHILD(hText, 1). / Item Text /
CValue hTextNODE-VALUE. END.
1
2
6
7
3
4
8
5
9
9DOM Building the Tree and Saving
CREATE X-DOCUMENT hDoc. CREATE X-NODEREF
hRoot. CREATE X-NODEREF hChild. CREATE X-NODEREF
hText. hDocCREATE-NODE(hRoot,"Music","ELEMENT")
. hDocAPPEND-CHILD(hRoot). hDocCREATE-NODE(hChi
ld, "Item", "ELEMENT"). hRootAPPEND-CHILD(hChild)
. hChildSET-ATTRIBUTE("ID", "1"). hDocCREATE-N
ODE(hText, "", "TEXT"). hChildAPPEND-CHILD(hText)
. hTextNODE-VALUE "Mozart's Requiem". hDocSAV
E("file","Music2.xml").
1
2
3
4
5
6
7
8
9
10SAX-ReaderPARSE( )
lt?xml version1.0?gt ltMusicgt ltItem ID"1"gt
Mozart's Requiem lt/Itemgt lt/Musicgt
1
2
3
/ Handler.p / PROC StartElement
END. PROC Characters END. PROC
EndElement END.
4
5
1
2
CREATE SAX-READER hSax. hSaxSET-INPUT-SOURCE("FIL
E", "Music.xml"). RUN Handler.p
Persistent SET h. hSaxHANDLER
h. hSaxPARSE().
3
4
5
11DOM vs. SAX
12Agenda
- DOM and SAX Review
- SAX-WRITER Object
- XML Schema Validation
- ProDataSet and Temp-Table to/from XML
- Whats Next
13SAX-Writer Functionality
- Coding easier than DOM
- Fewer objects
- SAX-Writer object
Syntax
CREATE SAX-WRITER handle IN WIDGET-POOL
pool-nameNO-ERROR.
Example
DEFINE VARIABLE hSAXWriter AS HANDLE
NO-UNDO. CREATE SAX-WRITER hSAXWriter NO-ERROR.
14SAX-Writer Object
Methods (partial list)
- START-DOCUMENT
- START-ELEMENT
- SET-OUTPUT-DESTINATION
- WRITE-CHARACTERS
- DECLARE-NAMESPACE
- END-DOCUMENT
- END-ELEMENT
- INSERT-ATTRIBUTE
- WRITE-DATA-ELEMENT
Attributes
- ENCODING
- FRAGMENT
- STRICT
- WRITE-STATUS (Read-Only)
- FORMATTED
- STANDALONE
- VERSION
15SET-OUTPUT-DESTINATION ( )
Defines the target for XML document
Syntax
handleSET-OUTPUT-DESTINATION (mode,filestream
memptrlongchar).
Example
CREATE SAX-WRITER hSAXWriter. ret
hSAXWriterSET-OUTPUT-DESTINATION
(FILE,C\OpenEdge\WRK\swMusic.xml).
16Invoke 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
17SAXWRITER Example
CREATE SAX-WRITER hSaxW. hSaxWSET-OUTPUT-DESTINA
TION("file", "swMusic.xml"). hSaxWSTART-DOCUMENT
(). hSaxWSTART-ELEMENT("Music"). hSaxWSTART-EL
EMENT("Item"). hSaxWINSERT-ATTRIBUTE("ID",
"1"). hSaxWWRITE-CHARACTERS("Mozart's
Requiem"). hSaxWEND-ELEMENT("Item"). hSaxWEND-E
LEMENT("Music"). hSaxWEND-DOCUMENT().
1
2
3
4
5
6
7
8
9
18STRICT Attribute
- Forces XML to be well-formed
/ STRICT TRUE. / START-DOCUMENT
START-ELEMENT START-ELEMENT
WRITE-DATA-ELEMENT END-ELEMENT
WRITE-CHARACTERS END-DOCUMENT
END-DOCUMENT FAILS!
19Agenda
- DOM and SAX Review
- SAX-WRITER Object
- XML Schema Validation
- ProDataSet and Temp-Table to/from XML
- Whats Next
20XML 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( )
21Schema 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
22New Method / Attributes
Applies to X-Document and Sax-Reader objects
- Method
- ADD-SCHEMA-LOCATION
- Attributes
- SCHEMA-LOCATION
- NONAMESPACE-SCHEMA-LOCATION
23DOM Example
CREATE X-DOCUMENT hDoc. hDocADD-SCHEMA-LOCATION
("urnmusic", "Music.xsd"). hDocLOAD("file",
"Music.xml", TRUE / validate /).
24SAX Example
CREATE SAX-READER hSax. hSaxSET-INPUT-SOURCE
(file, Music.xml). hSaxSCHEMA-LOCATION
urnmusic Music.xsd. hSaxVALIDATION-ENABLED
TRUE. / validate / hSaxPARSE( ).
25Agenda
- DOM and SAX Review
- SAX-WRITER Object
- XML Schema Validation
- ProDataSet and Temp-Table to/from XML
- Whats Next
26ProDataSet Functionality Continues to Mature
- OpenEdge 10.1A simplifies and adds options for
working with ProDataSets
27New Methods Added
- WRITE-XML
- WRITE-XMLSCHEMA
- READ-XML
- READ-XMLSCHEMA
ttItem
- Methods apply to
- ProDataSet
- Temp-Table
- Temp-Table Buffer
.xsd
.xsd
.xml
.xml
28WRITE-XML ( )
Syntax
WRITE-XML (target-type, file stream memptr
handle longchar , formatted , encoding
, schema-location, , write-schema ,
min-schema, write-before-image)
.xml
.xml
ttItem
(write-before-image for ProDataSets only)
29Temp-table Example
TEMP-TABLE ttItemWRITE-XML ("FILE",
/target-type/ "ttItemXML.xml", / file name
/ TRUE, / formatted / ?,
/ encoding / ?, /
schema location / ?, / write
schema / ?). / min XML Schema /
Format the output
30Data ONLY - Temp-Table ttItem
31ProDataSet Example XML with Schema
DATASET dsOrderWRITE-XML ("FILE",
"DSWriteXMLAndSchema.xml",
TRUE, / formatted / ?,
/ encoding / ?, / schema
location / TRUE, / write
schema / TRUE, / min XML
Schema / ?). /
writebeforeimage /
Write XML Schema with the data
32ProDataSet Example writeschemaTRUE
XML Schema
XML data
33ProDataSet Example writeschemaTRUE
XML data
34ProDataSet Example XML with Before-Tables
DATASET mydsWRITE-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
35ProDataSet writebeforeImage TRUE
After table data
Record marked as modified
Record marked as created
36ProDataSet writebeforeImage TRUE
Before-image of modified record
37WRITE-XMLSCHEMA ( )
- Write XML Schema Definition (XSD)
- For Temp-Tables contains
- Table definition, including indexes
- For ProDataSets contains
- Table definitions, including indexes
- Data relation definitions
ttItem
.xsd
.xsd
38Using with Temp-Tables and ProDataSets
Syntax
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
39Progress XML Schema Extensions
MIN-SCHEMA TRUE
MIN-SCHEMA FALSE
40Temp-table Example
TEMP-TABLE ttItemWRITE-XMLSCHEMA ("FILE",
/target-type/ "ttItem.xsd", / file name
/ TRUE, / formatted / ?,
/ encoding / FALSE). / min XML
Schema /
Write XML Schema Extensions
41Progress XML Schema Extensions
prodata namespace
field-level attributes
non-unique index definition
42XML Read Methods
.xsd
ttItem
.xml
.xsd
.xml
43READ-XML Method
- Populates ProDataSet or Temp-Table with
- XML data, XML Schema, or Both
Syntax
READ-XML (source-type, file memptr handle
longchar , read-mode , schema-location
, override-default-mapping ,
field-type-mapping , verify-schema-mode )
44Reading XML Into A ProDataSet
READ-XML( )
- Reads XML containing Before-Image information
- Progress datasetChanges
- Microsoft Diffgram
- ProDataSet events DO NOT fire
- Change tracking is turned OFF
45Using READ-XMLSCHEMA( )
- Create a Progress definition from XML Schema
- Verify XML Schema against Progress definition
Syntax
READ-XMLSCHEMA (source-type, file
memptr handle longchar ,
override-default-mapping , field-type-mapping
, verify-schema-mode )
46New XML Attributes
Gives you Control over XML format
- Available on static definitions
- DEFINE DATASET, TEMP-TABLE, BUFFER
47XML-NODE-TYPE Attribute
BUFFER ttItemBUFFER-FIELD(1)XML-NODE-TYPE
Attribute.
48NESTED Attribute ProDataSet Data-Relation
DATASET CustOrderGET-RELATION(custOrd)NESTED
TRUE.
Order Records NESTED within Customer 1
49ProDataSet and Temp-Table To/From XML
The right features for the right job!
- 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)
50ProDataSet and Temp-Table To/From XML
The right features for the right job!
- 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)
51Demo
52Agenda
- DOM and SAX Review
- SAX-WRITER Object
- XML Schema Validation
- ProDataSet and Temp-Table to/from XML
- Whats Next
53Under 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.
54XML Futures
- SAX-ATTRIBUTES
- XSLT
- XPath / XQuery
- Support for XML 1.1 / 2.0
55In Summary
- XML is Key Component in SOA Architectures
- OpenEdge provides the ABL to work with XML
- Were continuing to make working with XML easier
56For 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
57Education / 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
58Questions?
59Thank you foryour time
60(No Transcript)