Creating XML from Relational Tables using java
I would like to create an XML document by querying relational tables in java
try {
connection = getConnection();
final String qryStr = "select XMLElement( foo, 'bar' ) from dual";
final OracleXMLQuery qry = new OracleXMLQuery(connection, qryStr);
final String xmlString = qry.getXMLString();
I would expect this to give the following result that I get from running the statement in SQL Developer
select XMLElement( foo, 'bar' ) from dual
<FOO>bar</FOO>
Instead I get
<?xml version = '1.0'?>
<ERROR>oracle.xml.sql.OracleXMLSQLException: Character ')' is not allowed in an XML tag name.</ERROR>
Is this the correct way to go about this?
Is this the correct way to go about this?
Not really.
OracleXMLQuery class is the Java-side implementation of DBMS_XMLQUERY APIs.
It's mostly designed to generate a canonical XML document out of a SQL query.
Assuming a query like "SELECT col1, col2 FROM my_table", the resulting XML should appear like this :
<ROWSET>
<ROW>
<COL1>123</COL1>
<COL2>ABC</COL2>
</ROW>
<ROW>
<COL1>456</COL1>
<COL2>XYZ</COL2>
</ROW>
</ROWSET>
So in your test, since the resulting column is not aliased (XMLElement), you're actually trying to generate something like this :
<ROWSET>
<ROW>
<XMLELEMENT(FOO,'BAR')>
<FOO>bar</FOO>
</XMLELEMENT(FOO,'BAR')>
</ROW>
<ROWSET>
which of course is invalid, hence the error message.
If you want to generate only <FOO>bar</FOO> as output, just use a regular PreparedStatement with your query and access the document in the ResultSet with the proper getter.
Similar Messages
-
How to create XML from relational tables based on an XML Schema ?
There is no automated way in Oracle XML DB to define an automatic mapping between a set of columns in some existing relational tables and the elements and attributres defined by an XML Schema.
However it is easy solve this problem by using the SQL/XML operators (XMLAGG, XMLELEMENT, XMLFOREST, XMLATTRIBUTES, etc) to generate XML documents that are compliant with an XML Schema directly from a SQL statement.
If the XML Schema is registered with Oracle XML DB and the appropraite Schema Location information is added into the generated document using XMLAttributes then it becomes very easy to ensure that the generated documents are valid.
The following example show an easy way to do this by creating an XML View that contains the documents to be validated.
SQL> drop table PURCHASEORDER_LINEITEM
2 /
Table dropped.
SQL> drop table PURCHASEORDER_REJECTION
2 /
Table dropped.
SQL> drop table PURCHASEORDER_SHIPPING
2 /
Table dropped.
SQL> drop TABLE PURCHASEORDER_ACTION
2 /
Table dropped.
SQL> drop TABLE PURCHASEORDER_TABLE
2 /
Table dropped.
SQL> create table PURCHASEORDER_TABLE
2 (
3 REFERENCE VARCHAR2(28),
4 PRIMARY KEY ("REFERENCE"),
5 REQUESTER VARCHAR2(48),
6 USERID VARCHAR2(32),
7 COSTCENTER VARCHAR2(3),
8 SPECIALINSTRUCTIONS VARCHAR2(2048)
9 )
10 /
Table created.
SQL> create table PURCHASEORDER_ACTION
2 (
3 REFERENCE,
4 FOREIGN KEY ("REFERENCE") REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
5 ACTIONEDBY VARCHAR2(32),
6 DATEACTIONED DATE
7 )
8 /
Table created.
SQL> create table PURCHASEORDER_SHIPPING
2 (
3 REFERENCE,
4 FOREIGN KEY ("REFERENCE") REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
5 PRIMARY KEY ("REFERENCE"),
6 SHIPTONAME VARCHAR2(48),
7 ADDRESS VARCHAR2(512),
8 PHONE VARCHAR2(32)
9 )
10 /
Table created.
SQL> create table PURCHASEORDER_REJECTION
2 (
3 REFERENCE,
4 FOREIGN KEY ("REFERENCE") REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
5 PRIMARY KEY ("REFERENCE"),
6 REJECTEDBY VARCHAR2(32),
7 DATEREJECTED DATE,
8 COMMENTS VARCHAR2(2048)
9 )
10 /
Table created.
SQL> create table PURCHASEORDER_LINEITEM
2 (
3 REFERENCE,
4 FOREIGN KEY ("REFERENCE") REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
5 LINENO NUMBER(10),
6 PRIMARY KEY ("REFERENCE","LINENO"),
7 UPC VARCHAR2(14),
8 DESCRIPTION VARCHAR2(128),
9 QUANTITY NUMBER(10),
10 UNITPRICE NUMBER(12,2)
11 )
12 /
Table created.
SQL> insert into PURCHASEORDER_TABLE values ('SMCCAIN-20030109123335470PDT','Samuel B. McCain','SMCCAIN','A10','Courier')
2 /
1 row created.
SQL> insert into PURCHASEORDER_ACTION values ('SMCCAIN-20030109123335470PDT','SVOLLMAN',NULL)
2 /
1 row created.
SQL> insert into PURCHASEORDER_SHIPPING values ('SMCCAIN-20030109123335470PDT','Samuel B. McCain','800 Bridge Parkway,Redwood Shores,CA,9406
5,USA','650 506 7800')
2 /
1 row created.
SQL> insert into PURCHASEORDER_REJECTION values ('SMCCAIN-20030109123335470PDT',null,null,null)
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','1','715515010320','Life of Brian - Monty Python''s','2','39.
95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','2','37429145227','The Night Porter','2','29.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','3','37429128121','Oliver Twist','1','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','4','715515012720','Notorious','4','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','5','715515012928','In the Mood for Love','3','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','6','37429130926','Alphaville','2','29.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','7','37429166529','General Idi Amin Dada','4','29.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','8','715515012928','In the Mood for Love','3','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','9','715515009423','Flesh for Frankenstein','3','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','10','715515008976','The Killer','1','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','11','37429167922','Ballad of a Soldier','2','29.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','12','37429158623','Ordet','2','0')
2 /
1 row created.
SQL> var schemaPath varchar2(256)
SQL> --
SQL> begin
2 :schemaURL := 'http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd';
3 :schemaPath := '/public/purchaseOrder.xsd';
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> call dbms_xmlSchema.deleteSchema(:schemaURL,4)
2 /
Call completed.
SQL> declare
2 res boolean;
3 xmlSchema xmlType := xmlType(
4 '<!-- edited with XML Spy v4.0 U (http://www.xmlspy.com) by Mark (Drake) -->
5 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" version="1.0" xdb:storeVarrayAsTable="tr
ue">
6 <xs:element name="PurchaseOrder" type="PurchaseOrderType" xdb:defaultTable="PURCHASEORDER"/>
7 <xs:complexType name="PurchaseOrderType" xdb:SQLType="PURCHASEORDER_T" xdb:maintainDOM="false">
8 <xs:sequence>
9 <xs:element name="Reference" type="ReferenceType" xdb:SQLName="REFERENCE"/>
10 <xs:element name="Actions" type="ActionsType" xdb:SQLName="ACTIONS"/>
11 <xs:element name="Reject" type="RejectionType" minOccurs="0" xdb:SQLName="REJECTION"/>
12 <xs:element name="Requestor" type="RequestorType" xdb:SQLName="REQUESTOR"/>
13 <xs:element name="User" type="UserType" xdb:SQLName="USERID"/>
14 <xs:element name="CostCenter" type="CostCenterType" xdb:SQLName="COST_CENTER"/>
15 <xs:element name="ShippingInstructions" type="ShippingInstructionsType" xdb:SQLName="SHIPPING_INSTRUCTIONS"/>
16 <xs:element name="SpecialInstructions" type="SpecialInstructionsType" xdb:SQLName="SPECIAL_INSTRUCTIONS"/>
17 <xs:element name="LineItems" type="LineItemsType" xdb:SQLName="LINEITEMS"/>
18 </xs:sequence>
19 </xs:complexType>
20 <xs:complexType name="LineItemsType" xdb:SQLType="LINEITEMS_T" xdb:maintainDOM="false">
21 <xs:sequence>
22 <xs:element name="LineItem" type="LineItemType" maxOccurs="unbounded" xdb:SQLName="LINEITEM" xdb:SQLCollType="L
INEITEM_V"/>
23 </xs:sequence>
24 </xs:complexType>
25 <xs:complexType name="LineItemType" xdb:SQLType="LINEITEM_T" xdb:maintainDOM="false">
26 <xs:sequence>
27 <xs:element name="Description" type="DescriptionType" xdb:SQLName="DESRIPTION"/>
28 <xs:element name="Part" type="PartType" xdb:SQLName="PART"/>
29 </xs:sequence>
30 <xs:attribute name="ItemNumber" type="xs:integer" xdb:SQLName="ITEMNUMBER" xdb:SQLType="NUMBER"/>
31 </xs:complexType>
32 <xs:complexType name="PartType" xdb:SQLType="PART_T" xdb:maintainDOM="false">
33 <xs:attribute name="Id" xdb:SQLName="PART_NUMBER" xdb:SQLType="VARCHAR2">
34 <xs:simpleType>
35 <xs:restriction base="xs:string">
36 <xs:minLength value="10"/>
37 <xs:maxLength value="14"/>
38 </xs:restriction>
39 </xs:simpleType>
40 </xs:attribute>
41 <xs:attribute name="Quantity" type="moneyType" xdb:SQLName="QUANTITY"/>
42 <xs:attribute name="UnitPrice" type="quantityType" xdb:SQLName="UNITPRICE"/>
43 </xs:complexType>
44 <xs:simpleType name="ReferenceType">
45 <xs:restriction base="xs:string">
46 <xs:minLength value="18"/>
47 <xs:maxLength value="30"/>
48 </xs:restriction>
49 </xs:simpleType>
50 <xs:complexType name="ActionsType" xdb:SQLType="ACTIONS_T" xdb:maintainDOM="false">
51 <xs:sequence>
52 <xs:element name="Action" maxOccurs="4" xdb:SQLName="ACTION" xdb:SQLCollType="ACTION_V">
53 <xs:complexType xdb:SQLType="ACTION_T" xdb:maintainDOM="false">
54 <xs:sequence>
55 <xs:element name="User" type="UserType" xdb:SQLName="ACTIONED_BY"/>
56 <xs:element name="Date" type="DateType" minOccurs="0" xdb:SQLName="DATE_ACTIONED"/>
57 </xs:sequence>
58 </xs:complexType>
59 </xs:element>
60 </xs:sequence>
61 </xs:complexType>
62 <xs:complexType name="RejectionType" xdb:SQLType="REJECTION_T" xdb:maintainDOM="false">
63 <xs:all>
64 <xs:element name="User" type="UserType" minOccurs="0" xdb:SQLName="REJECTED_BY"/>
65 <xs:element name="Date" type="DateType" minOccurs="0" xdb:SQLName="DATE_REJECTED"/>
66 <xs:element name="Comments" type="CommentsType" minOccurs="0" xdb:SQLName="REASON_REJECTED"/>
67 </xs:all>
68 </xs:complexType>
69 <xs:complexType name="ShippingInstructionsType" xdb:SQLType="SHIPPING_INSTRUCTIONS_T" xdb:maintainDOM="false">
70 <xs:sequence>
71 <xs:element name="name" type="NameType" minOccurs="0" xdb:SQLName="SHIP_TO_NAME"/>
72 <xs:element name="address" type="AddressType" minOccurs="0" xdb:SQLName="SHIP_TO_ADDRESS"/>
73 <xs:element name="telephone" type="TelephoneType" minOccurs="0" xdb:SQLName="SHIP_TO_PHONE"/>
74 </xs:sequence>
75 </xs:complexType>
76 <xs:simpleType name="moneyType">
77 <xs:restriction base="xs:decimal">
78 <xs:fractionDigits value="2"/>
79 <xs:totalDigits value="12"/>
80 </xs:restriction>
81 </xs:simpleType>
82 <xs:simpleType name="quantityType">
83 <xs:restriction base="xs:decimal">
84 <xs:fractionDigits value="4"/>
85 <xs:totalDigits value="8"/>
86 </xs:restriction>
87 </xs:simpleType>
88 <xs:simpleType name="UserType">
89 <xs:restriction base="xs:string">
90 <xs:minLength value="1"/>
91 <xs:maxLength value="10"/>
92 </xs:restriction>
93 </xs:simpleType>
94 <xs:simpleType name="RequestorType">
95 <xs:restriction base="xs:string">
96 <xs:minLength value="0"/>
97 <xs:maxLength value="128"/>
98 </xs:restriction>
99 </xs:simpleType>
100 <xs:simpleType name="CostCenterType">
101 <xs:restriction base="xs:string">
102 <xs:minLength value="1"/>
103 <xs:maxLength value="4"/>
104 </xs:restriction>
105 </xs:simpleType>
106 <xs:simpleType name="VendorType">
107 <xs:restriction base="xs:string">
108 <xs:minLength value="0"/>
109 <xs:maxLength value="20"/>
110 </xs:restriction>
111 </xs:simpleType>
112 <xs:simpleType name="PurchaseOrderNumberType">
113 <xs:restriction base="xs:integer"/>
114 </xs:simpleType>
115 <xs:simpleType name="SpecialInstructionsType">
116 <xs:restriction base="xs:string">
117 <xs:minLength value="0"/>
118 <xs:maxLength value="2048"/>
119 </xs:restriction>
120 </xs:simpleType>
121 <xs:simpleType name="NameType">
122 <xs:restriction base="xs:string">
123 <xs:minLength value="1"/>
124 <xs:maxLength value="20"/>
125 </xs:restriction>
126 </xs:simpleType>
127 <xs:simpleType name="AddressType">
128 <xs:restriction base="xs:string">
129 <xs:minLength value="1"/>
130 <xs:maxLength value="256"/>
131 </xs:restriction>
132 </xs:simpleType>
133 <xs:simpleType name="TelephoneType">
134 <xs:restriction base="xs:string">
135 <xs:minLength value="1"/>
136 <xs:maxLength value="24"/>
137 </xs:restriction>
138 </xs:simpleType>
139 <xs:simpleType name="DateType">
140 <xs:restriction base="xs:date"/>
141 </xs:simpleType>
142 <xs:simpleType name="CommentsType">
143 <xs:restriction base="xs:string">
144 <xs:minLength value="1"/>
145 <xs:maxLength value="2048"/>
146 </xs:restriction>
147 </xs:simpleType>
148 <xs:simpleType name="DescriptionType">
149 <xs:restriction base="xs:string">
150 <xs:minLength value="1"/>
151 <xs:maxLength value="256"/>
152 </xs:restriction>
153 </xs:simpleType>
154 </xs:schema>
155 ');
156 begin
157 if (dbms_xdb.existsResource(:schemaPath)) then
158 dbms_xdb.deleteResource(:schemaPath);
159 end if;
160 res := dbms_xdb.createResource(:schemaPath,xmlSchema);
161 end;
162 /
PL/SQL procedure successfully completed.
SQL> begin
2 dbms_xmlschema.registerSchema
3 (
4 :schemaURL,
5 xdbURIType(:schemaPath).getClob(),
6 TRUE,TRUE,FALSE,FALSE
7 );
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> create or replace view PURCHASEORDER_XML
2 of xmltype
3 xmlSCHEMA "http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd" Element "PurchaseOrder"
4 with object id
5 (
6 substr(extractValue(object_value,'/PurchaseOrder/Reference'),1,32)
7 )
8 as
9 select xmlElement
10 (
11 "PurchaseOrder",
12 xmlAttributes
13 (
14 'http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd' as "xsi:noNamespaceSchemaLocation",
15 'http://www.w3.org/2001/XMLSchema-instance' as "xmlns:xsi"
16 ),
17 xmlElement("Reference",p.REFERENCE),
18 xmlElement
19 (
20 "Actions",
21 ( select xmlAgg
22 (
23 xmlElement
24 (
25 "Action",
26 xmlElement("User",ACTIONEDBY),
27 case
28 when DATEACTIONED is not null
29 then xmlElement("Date",DATEACTIONED)
30 end
31 )
32 )
33 from PURCHASEORDER_ACTION a
34 where a.REFERENCE = p.REFERENCE
35 )
36 ),
37 xmlElement
38 (
39 "Reject",
40 xmlForest
41 (
42 REJECTEDBY as "User",
43 DATEREJECTED as "Date",
44 COMMENTS as "Comments"
45 )
46 ),
47 xmlElement("Requestor",REQUESTER),
48 xmlElement("User",USERID),
49 xmlElement("CostCenter",COSTCENTER),
50 xmlElement
51 (
52 "ShippingInstructions",
53 xmlElement("name",SHIPTONAME),
54 xmlElement("address",ADDRESS),
55 xmlElement("telephone",PHONE)
56 ),
57 xmlElement("SpecialInstructions",SPECIALINSTRUCTIONS),
58 xmlElement
59 (
60 "LineItems",
61 ( select xmlAgg
62 (
63 xmlElement
64 (
65 "LineItem",
66 xmlAttributes(LINENO as "ItemNumber"),
67 xmlElement("Description",DESCRIPTION),
68 xmlElement
69 (
70 "Part",
71 xmlAttributes
72 (
73 UPC as "Id",
74 QUANTITY as "Quantity",
75 UNITPRICE as "UnitPrice"
76 )
77 )
78 )
79 )
80 from PURCHASEORDER_LINEITEM l
81 where l.REFERENCE = p.REFERENCE
82 )
83 )
84 )
85 from PURCHASEORDER_TABLE p, PURCHASEORDER_REJECTION r, PURCHASEORDER_SHIPPING s
86 where r.REFERENCE = p.REFERENCE
87 and s.REFERENCE = p.REFERENCE
88 /
View created.
SQL> set long 10000 pages 0 lines 140
SQL> --
SQL> select x.object_value.extract('/*')
2 from PURCHASEORDER_XML x
3 /
<PurchaseOrder xsi:noNamespaceSchemaLocation="http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Reference>SMCCAIN-20030109123335470PDT</Reference>
<Actions>
<Action>
<User>SVOLLMAN</User>
</Action>
</Actions>
<Reject/>
<Requestor>Samuel B. McCain</Requestor>
<User>SMCCAIN</User>
<CostCenter>A10</CostCenter>
<ShippingInstructions>
<name>Samuel B. McCain</name>
<address>800 Bridge Parkway,Redwood Shores,CA,94065,USA</address>
<telephone>650 506 7800</telephone>
</ShippingInstructions>
<SpecialInstructions>Courier</SpecialInstructions>
<LineItems>
<LineItem ItemNumber="1">
<Description>Life of Brian - Monty Python's</Description>
<Part Id="715515010320" Quantity="2" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="2">
<Description>The Night Porter</Description>
<Part Id="37429145227" Quantity="2" UnitPrice="29.95"/>
</LineItem>
<LineItem ItemNumber="3">
<Description>Oliver Twist</Description>
<Part Id="37429128121" Quantity="1" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="4">
<Description>Notorious</Description>
<Part Id="715515012720" Quantity="4" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="5">
<Description>In the Mood for Love</Description>
<Part Id="715515012928" Quantity="3" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="6">
<Description>Alphaville</Description>
<Part Id="37429130926" Quantity="2" UnitPrice="29.95"/>
</LineItem>
<LineItem ItemNumber="7">
<Description>General Idi Amin Dada</Description>
<Part Id="37429166529" Quantity="4" UnitPrice="29.95"/>
</LineItem>
<LineItem ItemNumber="8">
<Description>In the Mood for Love</Description>
<Part Id="715515012928" Quantity="3" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="9">
<Description>Flesh for Frankenstein</Description>
<Part Id="715515009423" Quantity="3" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="10">
<Description>The Killer</Description>
<Part Id="715515008976" Quantity="1" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="11">
<Description>Ballad of a Soldier</Description>
<Part Id="37429167922" Quantity="2" UnitPrice="29.95"/>
</LineItem>
<LineItem ItemNumber="12">
<Description>Ordet</Description>
<Part Id="37429158623" Quantity="2" UnitPrice="0"/>
</LineItem>
</LineItems>
</PurchaseOrder>
SQL> begin
2 for x in (select object_value from PURCHASEORDER_XML) loop
3 x.object_value.schemaValidate();
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL>There is no automated way in Oracle XML DB to define an automatic mapping between a set of columns in some existing relational tables and the elements and attributres defined by an XML Schema.
However it is easy solve this problem by using the SQL/XML operators (XMLAGG, XMLELEMENT, XMLFOREST, XMLATTRIBUTES, etc) to generate XML documents that are compliant with an XML Schema directly from a SQL statement.
If the XML Schema is registered with Oracle XML DB and the appropraite Schema Location information is added into the generated document using XMLAttributes then it becomes very easy to ensure that the generated documents are valid.
The following example show an easy way to do this by creating an XML View that contains the documents to be validated.
SQL> drop table PURCHASEORDER_LINEITEM
2 /
Table dropped.
SQL> drop table PURCHASEORDER_REJECTION
2 /
Table dropped.
SQL> drop table PURCHASEORDER_SHIPPING
2 /
Table dropped.
SQL> drop TABLE PURCHASEORDER_ACTION
2 /
Table dropped.
SQL> drop TABLE PURCHASEORDER_TABLE
2 /
Table dropped.
SQL> create table PURCHASEORDER_TABLE
2 (
3 REFERENCE VARCHAR2(28),
4 PRIMARY KEY ("REFERENCE"),
5 REQUESTER VARCHAR2(48),
6 USERID VARCHAR2(32),
7 COSTCENTER VARCHAR2(3),
8 SPECIALINSTRUCTIONS VARCHAR2(2048)
9 )
10 /
Table created.
SQL> create table PURCHASEORDER_ACTION
2 (
3 REFERENCE,
4 FOREIGN KEY ("REFERENCE") REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
5 ACTIONEDBY VARCHAR2(32),
6 DATEACTIONED DATE
7 )
8 /
Table created.
SQL> create table PURCHASEORDER_SHIPPING
2 (
3 REFERENCE,
4 FOREIGN KEY ("REFERENCE") REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
5 PRIMARY KEY ("REFERENCE"),
6 SHIPTONAME VARCHAR2(48),
7 ADDRESS VARCHAR2(512),
8 PHONE VARCHAR2(32)
9 )
10 /
Table created.
SQL> create table PURCHASEORDER_REJECTION
2 (
3 REFERENCE,
4 FOREIGN KEY ("REFERENCE") REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
5 PRIMARY KEY ("REFERENCE"),
6 REJECTEDBY VARCHAR2(32),
7 DATEREJECTED DATE,
8 COMMENTS VARCHAR2(2048)
9 )
10 /
Table created.
SQL> create table PURCHASEORDER_LINEITEM
2 (
3 REFERENCE,
4 FOREIGN KEY ("REFERENCE") REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE,
5 LINENO NUMBER(10),
6 PRIMARY KEY ("REFERENCE","LINENO"),
7 UPC VARCHAR2(14),
8 DESCRIPTION VARCHAR2(128),
9 QUANTITY NUMBER(10),
10 UNITPRICE NUMBER(12,2)
11 )
12 /
Table created.
SQL> insert into PURCHASEORDER_TABLE values ('SMCCAIN-20030109123335470PDT','Samuel B. McCain','SMCCAIN','A10','Courier')
2 /
1 row created.
SQL> insert into PURCHASEORDER_ACTION values ('SMCCAIN-20030109123335470PDT','SVOLLMAN',NULL)
2 /
1 row created.
SQL> insert into PURCHASEORDER_SHIPPING values ('SMCCAIN-20030109123335470PDT','Samuel B. McCain','800 Bridge Parkway,Redwood Shores,CA,9406
5,USA','650 506 7800')
2 /
1 row created.
SQL> insert into PURCHASEORDER_REJECTION values ('SMCCAIN-20030109123335470PDT',null,null,null)
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','1','715515010320','Life of Brian - Monty Python''s','2','39.
95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','2','37429145227','The Night Porter','2','29.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','3','37429128121','Oliver Twist','1','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','4','715515012720','Notorious','4','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','5','715515012928','In the Mood for Love','3','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','6','37429130926','Alphaville','2','29.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','7','37429166529','General Idi Amin Dada','4','29.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','8','715515012928','In the Mood for Love','3','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','9','715515009423','Flesh for Frankenstein','3','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','10','715515008976','The Killer','1','39.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','11','37429167922','Ballad of a Soldier','2','29.95')
2 /
1 row created.
SQL> insert into PURCHASEORDER_LINEITEM values ('SMCCAIN-20030109123335470PDT','12','37429158623','Ordet','2','0')
2 /
1 row created.
SQL> var schemaPath varchar2(256)
SQL> --
SQL> begin
2 :schemaURL := 'http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd';
3 :schemaPath := '/public/purchaseOrder.xsd';
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> call dbms_xmlSchema.deleteSchema(:schemaURL,4)
2 /
Call completed.
SQL> declare
2 res boolean;
3 xmlSchema xmlType := xmlType(
4 '<!-- edited with XML Spy v4.0 U (http://www.xmlspy.com) by Mark (Drake) -->
5 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" version="1.0" xdb:storeVarrayAsTable="tr
ue">
6 <xs:element name="PurchaseOrder" type="PurchaseOrderType" xdb:defaultTable="PURCHASEORDER"/>
7 <xs:complexType name="PurchaseOrderType" xdb:SQLType="PURCHASEORDER_T" xdb:maintainDOM="false">
8 <xs:sequence>
9 <xs:element name="Reference" type="ReferenceType" xdb:SQLName="REFERENCE"/>
10 <xs:element name="Actions" type="ActionsType" xdb:SQLName="ACTIONS"/>
11 <xs:element name="Reject" type="RejectionType" minOccurs="0" xdb:SQLName="REJECTION"/>
12 <xs:element name="Requestor" type="RequestorType" xdb:SQLName="REQUESTOR"/>
13 <xs:element name="User" type="UserType" xdb:SQLName="USERID"/>
14 <xs:element name="CostCenter" type="CostCenterType" xdb:SQLName="COST_CENTER"/>
15 <xs:element name="ShippingInstructions" type="ShippingInstructionsType" xdb:SQLName="SHIPPING_INSTRUCTIONS"/>
16 <xs:element name="SpecialInstructions" type="SpecialInstructionsType" xdb:SQLName="SPECIAL_INSTRUCTIONS"/>
17 <xs:element name="LineItems" type="LineItemsType" xdb:SQLName="LINEITEMS"/>
18 </xs:sequence>
19 </xs:complexType>
20 <xs:complexType name="LineItemsType" xdb:SQLType="LINEITEMS_T" xdb:maintainDOM="false">
21 <xs:sequence>
22 <xs:element name="LineItem" type="LineItemType" maxOccurs="unbounded" xdb:SQLName="LINEITEM" xdb:SQLCollType="L
INEITEM_V"/>
23 </xs:sequence>
24 </xs:complexType>
25 <xs:complexType name="LineItemType" xdb:SQLType="LINEITEM_T" xdb:maintainDOM="false">
26 <xs:sequence>
27 <xs:element name="Description" type="DescriptionType" xdb:SQLName="DESRIPTION"/>
28 <xs:element name="Part" type="PartType" xdb:SQLName="PART"/>
29 </xs:sequence>
30 <xs:attribute name="ItemNumber" type="xs:integer" xdb:SQLName="ITEMNUMBER" xdb:SQLType="NUMBER"/>
31 </xs:complexType>
32 <xs:complexType name="PartType" xdb:SQLType="PART_T" xdb:maintainDOM="false">
33 <xs:attribute name="Id" xdb:SQLName="PART_NUMBER" xdb:SQLType="VARCHAR2">
34 <xs:simpleType>
35 <xs:restriction base="xs:string">
36 <xs:minLength value="10"/>
37 <xs:maxLength value="14"/>
38 </xs:restriction>
39 </xs:simpleType>
40 </xs:attribute>
41 <xs:attribute name="Quantity" type="moneyType" xdb:SQLName="QUANTITY"/>
42 <xs:attribute name="UnitPrice" type="quantityType" xdb:SQLName="UNITPRICE"/>
43 </xs:complexType>
44 <xs:simpleType name="ReferenceType">
45 <xs:restriction base="xs:string">
46 <xs:minLength value="18"/>
47 <xs:maxLength value="30"/>
48 </xs:restriction>
49 </xs:simpleType>
50 <xs:complexType name="ActionsType" xdb:SQLType="ACTIONS_T" xdb:maintainDOM="false">
51 <xs:sequence>
52 <xs:element name="Action" maxOccurs="4" xdb:SQLName="ACTION" xdb:SQLCollType="ACTION_V">
53 <xs:complexType xdb:SQLType="ACTION_T" xdb:maintainDOM="false">
54 <xs:sequence>
55 <xs:element name="User" type="UserType" xdb:SQLName="ACTIONED_BY"/>
56 <xs:element name="Date" type="DateType" minOccurs="0" xdb:SQLName="DATE_ACTIONED"/>
57 </xs:sequence>
58 </xs:complexType>
59 </xs:element>
60 </xs:sequence>
61 </xs:complexType>
62 <xs:complexType name="RejectionType" xdb:SQLType="REJECTION_T" xdb:maintainDOM="false">
63 <xs:all>
64 <xs:element name="User" type="UserType" minOccurs="0" xdb:SQLName="REJECTED_BY"/>
65 <xs:element name="Date" type="DateType" minOccurs="0" xdb:SQLName="DATE_REJECTED"/>
66 <xs:element name="Comments" type="CommentsType" minOccurs="0" xdb:SQLName="REASON_REJECTED"/>
67 </xs:all>
68 </xs:complexType>
69 <xs:complexType name="ShippingInstructionsType" xdb:SQLType="SHIPPING_INSTRUCTIONS_T" xdb:maintainDOM="false">
70 <xs:sequence>
71 <xs:element name="name" type="NameType" minOccurs="0" xdb:SQLName="SHIP_TO_NAME"/>
72 <xs:element name="address" type="AddressType" minOccurs="0" xdb:SQLName="SHIP_TO_ADDRESS"/>
73 <xs:element name="telephone" type="TelephoneType" minOccurs="0" xdb:SQLName="SHIP_TO_PHONE"/>
74 </xs:sequence>
75 </xs:complexType>
76 <xs:simpleType name="moneyType">
77 <xs:restriction base="xs:decimal">
78 <xs:fractionDigits value="2"/>
79 <xs:totalDigits value="12"/>
80 </xs:restriction>
81 </xs:simpleType>
82 <xs:simpleType name="quantityType">
83 <xs:restriction base="xs:decimal">
84 <xs:fractionDigits value="4"/>
85 <xs:totalDigits value="8"/>
86 </xs:restriction>
87 </xs:simpleType>
88 <xs:simpleType name="UserType">
89 <xs:restriction base="xs:string">
90 <xs:minLength value="1"/>
91 <xs:maxLength value="10"/>
92 </xs:restriction>
93 </xs:simpleType>
94 <xs:simpleType name="RequestorType">
95 <xs:restriction base="xs:string">
96 <xs:minLength value="0"/>
97 <xs:maxLength value="128"/>
98 </xs:restriction>
99 </xs:simpleType>
100 <xs:simpleType name="CostCenterType">
101 <xs:restriction base="xs:string">
102 <xs:minLength value="1"/>
103 <xs:maxLength value="4"/>
104 </xs:restriction>
105 </xs:simpleType>
106 <xs:simpleType name="VendorType">
107 <xs:restriction base="xs:string">
108 <xs:minLength value="0"/>
109 <xs:maxLength value="20"/>
110 </xs:restriction>
111 </xs:simpleType>
112 <xs:simpleType name="PurchaseOrderNumberType">
113 <xs:restriction base="xs:integer"/>
114 </xs:simpleType>
115 <xs:simpleType name="SpecialInstructionsType">
116 <xs:restriction base="xs:string">
117 <xs:minLength value="0"/>
118 <xs:maxLength value="2048"/>
119 </xs:restriction>
120 </xs:simpleType>
121 <xs:simpleType name="NameType">
122 <xs:restriction base="xs:string">
123 <xs:minLength value="1"/>
124 <xs:maxLength value="20"/>
125 </xs:restriction>
126 </xs:simpleType>
127 <xs:simpleType name="AddressType">
128 <xs:restriction base="xs:string">
129 <xs:minLength value="1"/>
130 <xs:maxLength value="256"/>
131 </xs:restriction>
132 </xs:simpleType>
133 <xs:simpleType name="TelephoneType">
134 <xs:restriction base="xs:string">
135 <xs:minLength value="1"/>
136 <xs:maxLength value="24"/>
137 </xs:restriction>
138 </xs:simpleType>
139 <xs:simpleType name="DateType">
140 <xs:restriction base="xs:date"/>
141 </xs:simpleType>
142 <xs:simpleType name="CommentsType">
143 <xs:restriction base="xs:string">
144 <xs:minLength value="1"/>
145 <xs:maxLength value="2048"/>
146 </xs:restriction>
147 </xs:simpleType>
148 <xs:simpleType name="DescriptionType">
149 <xs:restriction base="xs:string">
150 <xs:minLength value="1"/>
151 <xs:maxLength value="256"/>
152 </xs:restriction>
153 </xs:simpleType>
154 </xs:schema>
155 ');
156 begin
157 if (dbms_xdb.existsResource(:schemaPath)) then
158 dbms_xdb.deleteResource(:schemaPath);
159 end if;
160 res := dbms_xdb.createResource(:schemaPath,xmlSchema);
161 end;
162 /
PL/SQL procedure successfully completed.
SQL> begin
2 dbms_xmlschema.registerSchema
3 (
4 :schemaURL,
5 xdbURIType(:schemaPath).getClob(),
6 TRUE,TRUE,FALSE,FALSE
7 );
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> create or replace view PURCHASEORDER_XML
2 of xmltype
3 xmlSCHEMA "http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd" Element "PurchaseOrder"
4 with object id
5 (
6 substr(extractValue(object_value,'/PurchaseOrder/Reference'),1,32)
7 )
8 as
9 select xmlElement
10 (
11 "PurchaseOrder",
12 xmlAttributes
13 (
14 'http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd' as "xsi:noNamespaceSchemaLocation",
15 'http://www.w3.org/2001/XMLSchema-instance' as "xmlns:xsi"
16 ),
17 xmlElement("Reference",p.REFERENCE),
18 xmlElement
19 (
20 "Actions",
21 ( select xmlAgg
22 (
23 xmlElement
24 (
25 "Action",
26 xmlElement("User",ACTIONEDBY),
27 case
28 when DATEACTIONED is not null
29 then xmlElement("Date",DATEACTIONED)
30 end
31 )
32 )
33 from PURCHASEORDER_ACTION a
34 where a.REFERENCE = p.REFERENCE
35 )
36 ),
37 xmlElement
38 (
39 "Reject",
40 xmlForest
41 (
42 REJECTEDBY as "User",
43 DATEREJECTED as "Date",
44 COMMENTS as "Comments"
45 )
46 ),
47 xmlElement("Requestor",REQUESTER),
48 xmlElement("User",USERID),
49 xmlElement("CostCenter",COSTCENTER),
50 xmlElement
51 (
52 "ShippingInstructions",
53 xmlElement("name",SHIPTONAME),
54 xmlElement("address",ADDRESS),
55 xmlElement("telephone",PHONE)
56 ),
57 xmlElement("SpecialInstructions",SPECIALINSTRUCTIONS),
58 xmlElement
59 (
60 "LineItems",
61 ( select xmlAgg
62 (
63 xmlElement
64 (
65 "LineItem",
66 xmlAttributes(LINENO as "ItemNumber"),
67 xmlElement("Description",DESCRIPTION),
68 xmlElement
69 (
70 "Part",
71 xmlAttributes
72 (
73 UPC as "Id",
74 QUANTITY as "Quantity",
75 UNITPRICE as "UnitPrice"
76 )
77 )
78 )
79 )
80 from PURCHASEORDER_LINEITEM l
81 where l.REFERENCE = p.REFERENCE
82 )
83 )
84 )
85 from PURCHASEORDER_TABLE p, PURCHASEORDER_REJECTION r, PURCHASEORDER_SHIPPING s
86 where r.REFERENCE = p.REFERENCE
87 and s.REFERENCE = p.REFERENCE
88 /
View created.
SQL> set long 10000 pages 0 lines 140
SQL> --
SQL> select x.object_value.extract('/*')
2 from PURCHASEORDER_XML x
3 /
<PurchaseOrder xsi:noNamespaceSchemaLocation="http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Reference>SMCCAIN-20030109123335470PDT</Reference>
<Actions>
<Action>
<User>SVOLLMAN</User>
</Action>
</Actions>
<Reject/>
<Requestor>Samuel B. McCain</Requestor>
<User>SMCCAIN</User>
<CostCenter>A10</CostCenter>
<ShippingInstructions>
<name>Samuel B. McCain</name>
<address>800 Bridge Parkway,Redwood Shores,CA,94065,USA</address>
<telephone>650 506 7800</telephone>
</ShippingInstructions>
<SpecialInstructions>Courier</SpecialInstructions>
<LineItems>
<LineItem ItemNumber="1">
<Description>Life of Brian - Monty Python's</Description>
<Part Id="715515010320" Quantity="2" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="2">
<Description>The Night Porter</Description>
<Part Id="37429145227" Quantity="2" UnitPrice="29.95"/>
</LineItem>
<LineItem ItemNumber="3">
<Description>Oliver Twist</Description>
<Part Id="37429128121" Quantity="1" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="4">
<Description>Notorious</Description>
<Part Id="715515012720" Quantity="4" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="5">
<Description>In the Mood for Love</Description>
<Part Id="715515012928" Quantity="3" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="6">
<Description>Alphaville</Description>
<Part Id="37429130926" Quantity="2" UnitPrice="29.95"/>
</LineItem>
<LineItem ItemNumber="7">
<Description>General Idi Amin Dada</Description>
<Part Id="37429166529" Quantity="4" UnitPrice="29.95"/>
</LineItem>
<LineItem ItemNumber="8">
<Description>In the Mood for Love</Description>
<Part Id="715515012928" Quantity="3" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="9">
<Description>Flesh for Frankenstein</Description>
<Part Id="715515009423" Quantity="3" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="10">
<Description>The Killer</Description>
<Part Id="715515008976" Quantity="1" UnitPrice="39.95"/>
</LineItem>
<LineItem ItemNumber="11">
<Description>Ballad of a Soldier</Description>
<Part Id="37429167922" Quantity="2" UnitPrice="29.95"/>
</LineItem>
<LineItem ItemNumber="12">
<Description>Ordet</Description>
<Part Id="37429158623" Quantity="2" UnitPrice="0"/>
</LineItem>
</LineItems>
</PurchaseOrder>
SQL> begin
2 for x in (select object_value from PURCHASEORDER_XML) loop
3 x.object_value.schemaValidate();
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> -
Creating XML from Oracle Tables
Would it be possible to post me a snapshot of the ODI Flow diagram for an Oracle to XML conversion? Does the staging area have to be on the Target (XML)? What KMs & CM should be used? Can the XML be written straight back to an .xml file? What should the XML Schema look like?
These are the KMs I use: LKM-SQL to SQL; IKM-SQL Incremental Update; CKM-SQL.
My flow is straight from source (oracle) to target (xml), with staging area on target (doesn't feel right).
My Oracle Dataserver & Schema work fine. Not sure about the XML dataserver setup though - I think this is where the problem lies. These are my JDBC settings:
- com.sunopsis.jdbc.driver.xml.SnpsXmlDriver
- jdbc:snps:xml?f=E:\Oracle ODI\Member.xsd
I am evaluating ODI for a client and I wanted to throw together a quick demo showing how easily ODI can generate XML from any source. I know this is the case as I understand the concept of ODI's components - just haven't had time to read manuals thoroughly.
Many thanks for your help,
SteveHello,
1. Try to test the connection to the XML dataserver.
2. Create a model and reverse-engineer this dataserver. You'll see what the XML structure is mapped to immediately.
3. Integrate data to this model (using standard KM targeting "SQL").
You can put the staging area on the Oracle source or in the XML driver if you want. Both solutions will work.
just haven't had time to read manuals thoroughly.I think you should quickly read the "Sunopsis ODI with... XML" section in the manual.
It is not very long and very helpful. Have also a quick look at the XML driver documentation.
Regards,
-FX -
Create XML from oracle table if not null
Hello dear community,
I have a problem by creating an XML file in oracle and hope you could help me.
What I have is an table named "description" with three rows there:
person varchar2(50)
adress varchar2(50)
Nr number
Reading this table I am going to create an XML file like that:
Procedure Create_XML (iNr IN number, cXmlFile OUT clob) is
varPerson varchar2(50);
varAdress varchar2(50);
Begin
varPerson := ... ;
varAdress := ... ;
select
xmlserialize
content
xmlelement
"Head",
xmlelement
"Node",
xmlelement
"Line",
xmlelement("ATNAM", 'PERSON'),
xmlelement("ATWRT", PERSON),
xmlelement("ATFOR", varPerson)
xmlelement
"Line",
xmlelement("ATNAM", 'ADRESS'),
xmlelement("ATWRT", ADRESS),
xmlelement("ATFOR", varAdress)
indent
) as xml
into cXmlFile
from description
where Nr = iNr;
End Create_XML;
What I want to do, is just to take the value from the both rows "person" and "adress" and fill the xml file with additional info.
1. My first question is, if it is possible to create any kind of routine for the xmlelement "Line" instead of doing it all over and over again? How?
2. An other issue is very important to me: how can I check here if f.i. the row person is empty or not? If it is, the xmlelement "Line" with person information in it should not be created at all.
Any answer would really help me!
Thank you a lot in advance!Hi,
Could you elaborate a little on your first question?
Are you looking for something like :
SELECT xmlquery(
'<head>
<node>
for $i in ora:view("DESCRIPTION")/ROW[NR=$nr]/*[local-name()!="NR"]
return element Line {
element ATNAM {local-name($i)},
element ATWRT {$i/text()}
</node>
</head>'
passing sys_xmlgen(1) as "nr"
returning content
FROM dual;but since you use a specific variable for each "line" type, I don't see how we can generalize the construction of the line element. -
Creating XML from a POJO using StAX
Hi Experts,
I have a POJO and now want to create an XML which has the elements as that of the POJO using StAX.
Can anybody please help me out.
Thanks in advance.swati_pekam wrote:
Yes I totally agree with you, had initially used JAXB....however client needs StAX to be used.. :(What? Why?
Do you mean "client" as in "client side program"?
In that case, the requirement is bullshit, because the receiving end of the XML doesn't know which technology is used to create it.
Do you mean "client" as in "the people who pay me to do that"?
In that case, the requirement is bullshit, because they should not force you to use tools that are not fit for the task ..
Please clarify this requirement. Why exactly do you think (or does the client think) that you need to use StAX? -
Generating XML from relational tables and storing back in CLOB field
I have been reviewing the documentation and trying to figure out the best approach. I am on v 10.2.0.3 and need to select from a parent table and three child tables and want to generate the results as xml that I will place in a clob field in another table. I looked at XMLQuery and dbms_xmlgen.getxml. The difference appears to be that getxml allows you to code traditional sql to join the tables.
I would greatly appreciate it if someone could provide some feedback and any sample code along the line that I describe above.
Thank you in advance for your help!
JerryAny feedback to the above questions would be greatly appreciated!
-
Create Big XML files ( extract ) from Relational Tables
Experts: I need to create a big XML extract more than 5Gb , from relations tables using SQLX. I read the excellent FAQ given by MDrake in the following thread.
https://forums.oracle.com/thread/418001
Question
1) Is it better to use XML schema, My XML output format is pretty much going to be static, so I can register an XML schema .
2) Does Registering the XMLschema help with better memory management. I recall I used to get out of memory exception when I generated xml documents on oracle 10g using DBMS_XMLGEN.
3) Can I generate this 5 Gb of XML file using oracle's default DOM parser?
Thanks
KevinHi Kevin,
1) Is it better to use XML schema, My XML output format is pretty much going to be static, so I can register an XML schema .
2) Does Registering the XMLschema help with better memory management. I recall I used to get out of memory exception when I generated xml documents on oracle 10g using DBMS_XMLGEN.
No, an XML schema won't help for the generation.
It is useful though if you're looking for the opposite task, i.e. loading an XML file into database tables.
3) Can I generate this 5 Gb of XML file using oracle's default DOM parser?
What is the default DOM parser ? Do you mean DBMS_XMLDOM APIs?
Since you want to generate XML, there's not much to parse.
Generally, using SQL/XML functions is the way to go.
You may still hit some performance/memory issues while reaching such a size, especially with large XMLAgg aggregation context.
If you do, you may switch to chunk generation instead. I've got some pretty good result with this approach and the parallel query feature. -
XML Data from Relational Tables
Hi,
My requirement is to pull data from relational tables into xml format and port it to the user (either as a file or allow the user to access it directly from their browser). What is the best way to accomplish this. Your suggestions are appreciated.
thanks.Marco,
Thanks for your reply, did try that , but I want the users to query this view also. Due to the nature of the xml structure I am getting the correct results. May be my xpath query is not right? My xml is as below:
<node1 attribute-node1 = "somevalue1">
<cnode1 attribute-cnode1 = "somevalue2">
<cnode2 attribute-cnode2 = "somevalue3">
<cnode3>somevalue4</cnode3>
<cnode4>somevalue5</cnode4>
</cnode2>
<cnode2 attribute-cnode2 = "somevlaue6">
<cnode3>somevalue6</cnode3>
<cnode4>somevalue7</cnode4>
</cnode2>
</cnode1>
</node1>
and my requirement is like : the user wants to see only cnode2 with attribute value "somevalue3" (along with the rest of the xml) ie
<node1 attribute-node1 = "somevalue1">
<cnode1 attribute-cnode1 = "somevalue2">
<cnode2 attribute-cnode2 = "somevalue3">
<cnode3>somevalue4</cnode3>
<cnode4>somevalue5</cnode4>
</cnode2>
</cnode1>
</node1>
Need the correct xpath query for this.
Thanks -
I am trying to create xml from raw data. It works well in the format builder but
when I instanciate the MFLObject and run convert to xml, the output only contains
wrappers for my first field described in the mfl. Are there any known issues
using this progmattic conversion to XML.
My mfl is the following:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE MessageFormat SYSTEM 'mfl.dtd'>
<!-- Enter description of the message format here. -->
<MessageFormat name='BossRecord' version='2.01'>
<FieldFormat name='Header' type='String' length='102' codepage='windows-1252'/>
<StructFormat name='TransactionControlRecord' delim='999'>
<FieldFormat name='TransactionTypeNumber' type='String' length='3' codepage='windows-1252'/>
<FieldFormat name='TransactionData' type='String' codepage='windows-1252'>
<LenField type='Numeric' length='4'/>
</FieldFormat>
</StructFormat>
<StructFormat name='Generic' repeat='*'>
<FieldFormat name='GenericTypeNumber' type='String' length='3' codepage='windows-1252'/>
<FieldFormat name='GenericData' type='String' codepage='windows-1252'>
<LenField type='Numeric' length='4'/>
</FieldFormat>
</StructFormat>
<FieldFormat name='IgnoreTheRest' type='Filler' optional='y' length='1' repeat='*'>
<!--
This field is useful for testing partially constructed formats. Adding
this field to the
end of a format will cause any leftover bytes on the end of a binary file to be
ignored when the data is converted to XML.
-->
</FieldFormat>
</MessageFormat>
Are there any issues with this that are easy to spot?
Here is some sample output:
_BossRecordDoc : <BossRecord>
<Header>0601uskyloupw7vu0 IBVRTR 000006RSQ1010246000000000000020436000001-01-01-00.00.00.00000000000100170</Header>
<Header>90100581D4EBC00AA3C18629ACA0004AC02E54BD289357023141961111F1111 99900207141D4EBC00AA3C18629ACA0004AC0</Header>
<Header>2E54BD2893570231RIBBONS & BUTTONS 9 00000000000010.50CAD00000000000000.5</Header>
<Header>0USD00000000000000.00USD00000000000077.00CAD 0CAUS00000000000000.91KGSA215D100CF3C18619AC</Header>
<Header>90004AC02E54B 01 0001-0</Header>
<Header>1-012003-04-072003-06-2501P/P03003984196000010100000000000000.00CAD 00
FR00000000000000</Header>
<Header>.0000000000000000000.00KGS00000000000000.00USD 00UPS T1</Header>
<Header>0001-01-010001-01-01 0 000000000000000.00000000000000000.00USD0</Header>
<Header>000000000000000.00 1 22222222222220 0100304061DC30500AA3C18629ACA</Header>
<Header>0004AC02E54B1D4EBC00AA3C18629ACA0004AC02E54B</Header>
<Header> 0010001-01-01 00000000000000.00USD00</Header>
<Header>000000000000.00CAD00000000000010.00CAD</Header>
<Header> 00000000000010.00CAD000000000000000010001-01-01K00404862A8D2C00AA3C186</Header>
<Header>29ACA0004AC02E54B1DC30500AA3C18629ACA0004AC02E54B001 PURPLE RIBBONS</Header>
It just keeps finding my first record instead of finding the remaing structure.
I appreciate any help.
Thanks,
MichaelOkay, I've got some coding off a site that looks like it will do what I want. It's quite a robust applications which will do more than I need but as long as it does at least what I want, i could care less. As it will extract files from the datastream for me, it is going to save them to disk.
I believe I have to specify a directory to save it to. I believe this is the line I'm going to modify, so assuming that's the case, how do I specify a directory here:
private File fileOutPutDirectory = null;
Do I have to use absolute paths or can I use relative. Also, what directory construct is expected by java? Anyone with an example of what urls are supposed to look like in this case?
Thanks,
destin -
I have created PDF from hardcopy by using my scanner. After I run OCR option for my PDF by using Acrobat Pro 9. But "Text-to-speech" functionality of the PDF says that an error message comes up that says the page is empty when I turns on the read out loud option in Acrobat. Kindly help me to sortout this problems?
So I tried generating the same PDFs on two other computers that have Acrobat 9 Pro. Results were reproduced. The verdict is:
- complex PDF files (that is, containing cross-references, tables of contents, and bookmarks) generated by Acrobat 9.x Pro are roughly 2-5x larger than the identical file generated with Acrobat 8.x Pro.
- different PDF conversion settings make a negligable difference (less than 10% rather than 70-80%).
- using the "Reduce File Size" or "Optimize PDF" option cuts the file size roughly in half, almost always resulting in a "image downsampling mask" warning message, which requires acknowledgement (that is a problem for batch processing or automation).
- adding an Acrobat watermark to the file cuts the file size roughly in half.
- just using Save As to another filename has no effect on file size.
- generating the PDF in Acrobat 9 with links but no PDF bookmarks still results in the inflated file size.
- generating the PDF in Acrobat 9 without any links or bookmarks results in approximately the same file size as the Acrobat 8 PDF with full links and bookmarks.
It appears that Acrobat 9's manner of adding links is what's bloating the files, and in my case it's probably not related to images or image resolution/print quality. It's a shame, because Acrobat 9 seems to have made some improvements to the Review Tracker interface, and a few other bells and whistles which I haven't really gotten around to exporing yet. But unless I find a way to keep my links and the PDF file sizes comparable to what I was getting with Acrobat 8 Pro, it looks like I'm going to stay with Acrobat 8. -
Creating XML from JDBC resultset
Can anyone give me a pointer as the best way to create XML from a JDBC resultset. I have told that XSU cannot be used as it is vendor specific and ties us to Oracle (yawn, yawn).
Any ideas welcomed.import javax.xml.parsers.*;
import org.w3.dom.*;
import javax.xml.dom.*;
import javax.xml.dom.source.*;
import javax.xml.dom.stream.*;
import java.sql.*;
public class CreateXML{
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.newDocument();
Element root=doc.createElement("root_element");
// coonect to database
//get resultset metadata rsmd
while(rs.next()){
Element row=doc.createElement("row");
for(int j=1;j<=rsmd.getColumnCount();j++){
String colName=rsmd.getCoulmName(j);
String colValue=rs.getString(j);
Element e=doc.createElement(colName);
e.appendChild(doc.createTextNode(colValue));
row.appendChild(e);
root.appendChild(row);
doc.appendChild(root);
//You can now use XSLT to generate xml file thus:
TransformerFactory tmf=TransformerFactory.newInstance();
Transformer tf=tmf.newTransformer();
DOMSource source=new DOMSource(doc);
StreamResult result=new StreamResult("name of file for output");
tf.transform(source,result);
// of course exceptions will have to be caught in this code. -
Can not construct xml from relative xpath expression: //FormVar
In version 7.0, it was possible to access Form Variables with the (valid) XPath Expression "//FormVariable".
In 7.2.2, using this XPath Expression leads to a stalled action, with message: "can not construct xml from relative xpath expression: //FormVar". (see full stack trace below)
What's wrong? How can I fix this?
Use of relative expression is very very useful during the development phase!
Best Regards,
com.adobe.workflow.WorkflowRuntimeException: can not construct xml from relative xpath expression: //FormVar
at com.adobe.workflow.pat.service.PATExecutionContextImpl.createNodesForXPathExpression(PATE xecutionContextImpl.java:854)
at com.adobe.workflow.pat.service.PATExecutionContextImpl.setProcessDataValue(PATExecutionCo ntextImpl.java:707)
at com.adobe.workflow.pat.service.PATExecutionContextImpl.setProcessDataWithExpression(PATEx ecutionContextImpl.java:429)
at com.adobe.workflow.qpac.set_value.SetValueService.execute(SetValueService.java:72)
at com.adobe.workflow.engine.PEUtil.executeAction(PEUtil.java:184)
at com.adobe.workflow.engine.ProcessEngineBMTBean.continueBranchAtAction(ProcessEngineBMTBea n.java:2371)
at com.adobe.workflow.engine.ProcessEngineBMTBean.asyncInvokeProcessCommand(ProcessEngineBMT Bean.java:512)
at sun.reflect.GeneratedMethodAccessor709.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionConta iner.java:683)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionI nterceptor.java:185)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at org.jboss.ejb.plugins.AbstractTxInterceptorBMT.invokeNext(AbstractTxInterceptorBMT.java:1 44)
at org.jboss.ejb.plugins.TxInterceptorBMT.invoke(TxInterceptorBMT.java:62)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstance Interceptor.java:72)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:120)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor. java:122)
at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331 )
at org.jboss.ejb.Container.invoke(Container.java:723)
at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:359)
at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:83)
at $Proxy285.asyncInvokeProcessCommand(Unknown Source)
at com.adobe.workflow.engine.ProcessCommandControllerBean.onMessage(ProcessCommandController Bean.java:127)
at sun.reflect.GeneratedMethodAccessor641.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(MessageDrivenContainer.j ava:458)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionI nterceptor.java:185)
at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterc eptor.java:62)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:315)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:148)
at org.jboss.ejb.plugins.RunAsSecurityInterceptor.invoke(RunAsSecurityInterceptor.java:90)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at org.jboss.ejb.MessageDrivenContainer.internalInvoke(MessageDrivenContainer.java:372)
at org.jboss.ejb.Container.invoke(Container.java:723)
at org.jboss.ejb.plugins.jms.JMSContSorry, i just read my own message in the discussion forum and
discovered all spaces for formating the XML tags where gone.
It should look like this:
[-----xml_type---]
<doc>
__<role>
____actor
____<first>
______john
____</first>
____<last>
______bond
____</last>
__</role>
__<role>
____actor
____<first>
______james
______</first>
____<last>
______smith
____</last>
__</role>
</doc>
semantic:
There are two actors: "john bond" and "james smith"
Querying for "john bond" succeedes which is correct
Querying for "james smith" succeedes which is correct
Querying for "james bond" fails which is correct
Querying for "john smith" succeedes which is an ERROR!
contains(xdata, 'actor INPATH(//role[./first = "john" and ./last
= "smith"])' (= 100 ---> ERROR!)
bye,
feri -
Adobe v9 on W7 and office 2007. cannot create PDF from MS word using Adobe. But can from Excel, PPT and other MS office apps. Reinslalled Adobe, updated Office, and Adobe no help! Also I can create a pdf from the MS Word and it is using the Adobe 9. So one would think that's good. No it isn't when you need to combine different files to one big PDF document. Any suggetions? Thank you
Yes, I’m saying that I can in WORD use “Save As ADOBE pdf” but cannot in ADOBE create a pdf file from a WORD (.doc or .docx) document. While I can from other MS Office apps like Excel and PowerPoint.
I understand I can use “work around” and save doc in WORD as pdf then compile all files needed (xml, ppt, pdf) in the ADOBE v9. to one big pdf document. But that is not the point of this post.
Jarda @ PC+NET Solutions
Mobile 613-532-7023
Office 613-385-1268
<http://www.pcplusnet.net/> www.pcplusnet.net -
Generating xml from diff tables in a db
hi,
i need to write a oracle procedure, which when called generates xml doc (building xml from different tables in database.). i got the DTDs . but i still dont understand how can the data be pulled from diff tables and put in the one xml? can anyone give me rough idea.. i know that i have to use xmlquery and xml_save packages... but still not much clear..
i m working on oracle 8i database. any help is appreciated.. thanks.Any feedback to the above questions would be greatly appreciated!
-
FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.
Hi,
I have one multi record block in which i want to fetch values
(more then one record) from another table using select statement
IN KEY NEXT ITEM.I am getting following error.
ORA-01422: exact fetch returns more than requested number of rows
Thanks in advance.In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
However, you can replace the explicit cursor with implicit one like
go_block('non_db_block_name');
first_record();
FOR v_tab IN (SELECT *
FROM tab
WHERE col_name = :variable)
LOOP
:non_db_block_name.field1 := v_tab.col1;
:non_db_block_name.field2 := v_tab.col2;
next_record();
END LOOP;
Maybe you are looking for
-
How can I copy music from iPad mini to iPad mini using home sharing??
How can I copy music from iPad mini to iPad mini using home sharing??
-
How do I make Firefox the browser but not make it the default browser?
I want to use Firefox as the browser on some sites but not all. I don't want to make either Firefox or Internet Explorer as a default browser but use each on certaion web sites such as Google or MSN.
-
Pdf is stored in a oracle table
hi I have stored pdf files in oracle table , how do we get this and store as a .pdf file .How to find pdf files please help me.
-
How do I save an incoming audio message to my iphone 3gs
How do I save an incoming audio message to my iphone 3GS?
-
IMovie to iDVD: Does it go DV- H.264- MPEG-2 now ???
I use a DV camcorder and after importing and editing in iMovie I want to make a DVD. When exporting to the media browser - using "large" - this is what the help viewer says: "Large: Always 960 by 540 pixels (widescreen). No large size is rendered if