How To Convert Relational Data To XML - Melbourne
How To Convert Relational Data To XML - Melbourne
OBJECTIVES
Describe reasons why conversion of relational data to XML may
be considered.
Detail situations when conversion appears to be a candidate
for consideration.
Describe how to convert relational data to XML for
Acknowledgements
Phil Grainger of BMC Software
From his education seminar, DB2 9 for z/OS In Depth presented at
IDUG Australia 2011, came the idea about using XML.
And for his introduction of me to
Disclaimer
The following presentation is the views and opinions of the
author / presenter. It in no way represents the views of
Westpac NZ Ltd or IBM.
The facts presented as part of this presentation were observed
in a specific environmental configuration that existed within
Westpac NZ Ltd and are factual only to that environment.
They should by no means constitute a guarantee of results
achievable in any other environment and as such are therefore
indicative only.
Other observations are factual events that the author /
presenter encountered.
Agenda
WHY?
6
Curiosity at work
7
10
11
12
13
WHEN
14
15
16
17
18
FIRSTNME
LASTNAME
SEX
HIREDATE
CHAR(6)
VARCHAR(12)
VARCHAR(15)
CHAR(1)
DATE
000010
CHRISTINE
HAAS
1965-01-01
000020
MICHEAL
THOMPSON
1973-10-10
EMPPROJACT
EMPNO
PROJNO
EMSTDATE
EMENDATE
CHAR(6)
CHAR(6)
000010
MA2100
1982-01-01
1982-11-01
000010
MA2110
1982-01-01
1983-02-01
000010
AD3100
1982-01-01
1982-07-01
000020
PL2100
1982-01-01
1982-09-05
XMLFOREST
Allows the creation of multiple XML elements within a XML Document
with one XML command.
19
20
Result
<FIRST>CHRISTINE</FIRST>
21
Result
<FIRST>CHRISTINE</FIRST>
<FIRST>MICHAEL</FIRST>
22
Result
<NAME><FIRST>CHRISTINE</FIRST><LAST>HAAS</LAST></NAME>
23
24
Result
<NAME><FIRST>CHRISTINE</FIRST><LAST>HAAS</LAST></NAME>
25
26
27
Row 2
<NAME>
<FIRST>CHRISTINE</FIRST>
<LAST>HAAS</LAST>
<PROJECTDETAILS>
<PROJECTID>MA2100</PROJECTID>
<STARTDATE>1982-01-01</STARTDATE>
<ENDDATE>1982-11-01</ENDDATE>
</PROJECTDETAILS>
<PROJECTDETAILS>
<PROJECTID>MA2110</PROJECTID>
<STARTDATE>1982-01-01</STARTDATE>
<ENDDATE>1983-02-01</ENDDATE>
</PROJECTDETAILS>
<PROJECTDETAILS>
<PROJECTID>AD3100</PROJECTID>
<STARTDATE>1982-01-01</STARTDATE>
<ENDDATE>1982-07-01</ENDDATE>
</PROJECTDETAILS>
</NAME>
<NAME>
<FIRST>MICHAEL</FIRST>
<LAST>THOMPSON</LAST>
<PROJECTDETAILS>
<PROJECTID>PL2100</PROJECTID>
<STARTDATE>1982-01-01</STARTDATE>
<ENDDATE>1982-09-05</ENDDATE>
</PROJECTDETAILS>
</NAME>
28
29
31
32
1.
2.
3.
Three Choices
Do nothing specific and just create XML as you would.
Specifically ask to create an empty element.
Specifically dont create an element.
33
Would result in
<NAME><FIRST>CHRISTINE</FIRST><LAST>HAAS</LAST><LEAVEDATE/></NAME>
34
35
36
1.
2.
3.
3 Options
Create XML as is
Specifically create an EMPTY tag
Specifically do not create a tag.
Default behaviour if nothing specifically specified i.e. option 1
is followed, is to create an EMPTY tag.
Specification of an option is allowed in both the XMLELEMENT
and XMLFOREST syntax.
37
38
39
40
Cursor
Child
Cursor 10
Child
Cursor 9
Child
Cursor 8
Child
Cursor 1
Child
Cursor 4
Child
Cursor 6
Child
Cursor 5
Child
Cursor 2
Child
Cursor 3
41
42
43
44
Other Suggestions /
Observations /
XML Syntax
45
Results
<FIRST>CHRISTINE</FIRST>
Note be careful in z/OS as you cannot serialise to a VARCHAR, in version 9 at least.
46
47
<EMPLOYEEDETAILS SEX="FEMALE">
<FirstName>CHRISTINE</FirstName>
<LastName>HAAS</LastName>
</EMPLOYEEDETAILS>
48
Result
NOT XML
<FIRST>CHRISTINE</FIRST><LAST>HAAS</LAST>
49
Result
<NAME><FIRST>CHRISTINE</FIRST><LAST>HAAS</LAST></NAME>
50
Other Observations
Be careful of open Pandoras box.
People treating this a one size fits all solution or
A magic silver bullet.
51
52
Conclusion
Conversion from relational data to XML can provide benefits.
In certain circumstances these could be significant.
The benefits are not derived in all circumstances. Treat each
situation as its own and develop a solution accordingly. XML
conversion is not of a one size fits all approach so please be
sensible when applying.
The conversion process is not overly onerous and requires little
specialist knowledge of DB2 XML functionality. Just a good
understand of really only three SQL XML functions and
Common Table Expressions.
53
QUESTIONS
54
THANK YOU
55
Paul Murray
Westpac New Zealand Ltd
[email protected]
Session D02
From Relational Data to XML :
A Users unexpected journey.