Building XML from relational data
I need to create XML documents from relational data that conforms to an XML schema document. We need to store and query the XML documents we create.
Therefore, we have decided to store the XML using the object model rather than as a CLOB
i.e. register the schema with the XML DB which in turn creates the tables and object types that represent the schema.
What is the best way build the XML document from the relational data ??
Can I pass the relational data to the default constructors of the object types created by the schema registration ?? (and then create an XML document from the top level object instance using SYS_XMLGEN)
Or should I build the xml from strings using XMLELEMENT,XMLFOREST built-in's when retrieving the data from the relational tables ?? OR use the XMLDOM package to build the document ??
Would appreciate any advice on the best approach.
There are basically two ways to join your document fragments with SQLX:
1/. With xmlForest
e.g. SELECT XMLELEMENT ( "Emp",XMLForest(e.employee_id, e.lname, e.salary)) AS "result"
FROM employees e WHERE employee_id > 1500 ;
result
<Emp>
< employee_id >1769</ employee_id >
< lname >Smith</ lname >
< salary >200000</ salary >
</Emp>
2/. With nested invocations of xmlElement
e.g. SELECT XMLELEMENT("Emp", XMLELEMENT("name", e.fname ||' '|| e.lname),
XMLELEMENT ( "hiredate", e.hire)) AS "result"
FROM employees e WHERE employee_id > 200 ;
result
<Emp>
<name>John Smith</name>
<hiredate>2000-05-24</hiredate>
</Emp>
<Emp>
<name>Mary Martin</name>
<hiredate>1996-02-01</hiredate>
</Emp>
Similar Messages
-
How to generate XML from relational data : PL/SQL or Java
I'm new to Oracle XML and would appreciate some advice. I've been asked to generate XML documents from data stored in relational tables. The XML documents must be validated against a DTD. We will probably want to store the XML in the database.
I've seen a PL/SQL based approach as follows :
1.Mimic the structure of the DTD using SQL object types 2.Assign the relational data to the object type using PL/SQL as required
3.Use the SYS_XMLGEN package to render the required XML documents from the SQL objects
However, creating the object types seems to be quite time consuming (step 1 above) for anything other than the simplest of XML documents.
I've also seen that there is the Java based approach, namely :
1. Use the XML generator to build Java classes based on a DTD.
2. Use these classes to build the required XML
On the face of it, the Java based approach seems simpler. However, I'm not that familiar with Java.
Which is the best way to proceed ? Is the PL/SQL based approach worth pursuing or should I bite the bullet and brush up my Java ?
Is it possible to use a combination of PL/SQL and Java to populate the dtd generated java classes (step 2 of the Java approach) to reduce my learning curve ?
Thanks in advanceTo help answer your questions:
1) Now, in 9iR2, you can use SQL/XML as another choice.
2) You can also use XSU to generate the XML and use XSLT to transform it to a desired format instead of using object views if possible.
3) XDK provide Class generator support to populate XML data to Java classes. -
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 -
Revision: 21287
Revision: 21287
Author: [email protected]
Date: 2011-05-23 07:37:28 -0700 (Mon, 23 May 2011)
Log Message:
Merge changes to qa-regress build.xml from changelist 20641 on branches/4.0.0_fixes to branches/4.x.
Modified Paths:
blazeds/branches/4.x/qa/apps/qa-regress/build.xmlI chroot into workdir. uncommented en_US.UTF-8 in /etc/locale.gen, run locale-gen and now get this inside the chroot.
[root@dArch2 releng]# chroot work/x86_64/root-image/
[root@dArch2 /]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
this looks alright to me. Any more suggestions?
It's the first time I use a custom-repo and I set it up only for this purpose. So yes, it's up to date and can be used outside the chroot. Also a different package I put from AUR into my custom-repo installs fine and doesn't give this error.
How else could I test the custom-repo? -
Hi,
I would like to know how to include DOC TYPE reference node, when building XML from Java.
Thanks !!SetDocType is available only in JDOM parser. I would like to know is it prossible without that.
Thanks !! -
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 -
Hi All
We have 11.1.1.7 ojdeploy to compile our app.
We notice in the log that not all jars are used in classpath arguments when we explicitly set them up for compilation.
eg:
<path id="classpath">
<pathelement location="../../Oracle/Middleware/oracle_common/modules/oracle.adf.share_11.1.1/commons-el.jar"/>
<pathelement location="../../Oracle/Middleware/oracle_common/modules/oracle.adf.share_11.1.1/jsp-el-api.jar"/>
<pathelement location="../../Oracle/Middleware/oracle_common/modules/oracle.adf.share_11.1.1/oracle-el.jar"/>
<pathelement location="interface/public_html/WEB-INF/lib/a.jar"/>
<pathelement location="interface/public_html/WEB-INF/lib/b.jar"/>
<pathelement location="interface/public_html/WEB-INF/lib/c.jar"/>
<pathelement location="interface/public_html/WEB-INF/lib/d.jar"/>
</path>
Log Output -
[ora:ojdeploy] /path/to/Oracle/Middleware/jdk160_24/bin/javac
[ora:ojdeploy] -g
[ora:ojdeploy] -Xlint:all
[ora:ojdeploy] -Xlint:-cast
[ora:ojdeploy] -Xlint:-empty
[ora:ojdeploy] -Xlint:-fallthrough
[ora:ojdeploy] -Xlint:-path
[ora:ojdeploy] -Xlint:-serial
[ora:ojdeploy] -Xlint:-unchecked
[ora:ojdeploy] -source 1.6
[ora:ojdeploy] -target 1.6
[ora:ojdeploy] -verbose
[ora:ojdeploy] -encoding Cp1252
[ora:ojdeploy] -classpath
[ora:ojdeploy] /path/to/Oracle/Middleware/jdk160_24/jre/lib/resources.jar:
[ora:ojdeploy] /path/to/Oracle/Middleware/jdk160_24/jre/lib/rt.jar:
[ora:ojdeploy] /path/to/Oracle/Middleware/jdk160_24/jre/lib/jsse.jar:
[ora:ojdeploy] /path/to/interface/public_html/WEB-INF/lib/a.jar"/>
[ora:ojdeploy] /path/to/interface/public_html/WEB-INF/lib/c.jar"/>
1- Is it because it depends on how jpr or jws are configured ?
2- How can we automatically generate a build file of the application from command-line (as opposed to using Jdev IDE to click to generate a build.xml) ?The first warning is happening because you're stating drivers for input devices without need. You haven't disabled hotplug so evdev gets used instead of kbd. This is normal, and you should change the driver line from kbd to evdev so that whatever options (if any) you've specified for the keyboard get parsed.
The second warning is about you not installing acpid.
The third I have no idea about, but look at the synaptics wiki. None of the (WW) are related to your video card.
And every card that has 2 or more output ports show up as "two cards". You also don't need to specify the pci port in xorg.conf. edit: this is the general case with laptops, might be different for desktops.
When I do lspci -v I get:
00:02.0 VGA compatible controller: Intel Corporation Mobile 945GME Express Integrated Graphics Controller (rev 03) (prog-if 00 [VGA controller])
Subsystem: Micro-Star International Co., Ltd. Device 0110
Flags: bus master, fast devsel, latency 0, IRQ 16
Memory at dfe80000 (32-bit, non-prefetchable) [size=512K]
I/O ports at d0f0 [size=8]
Memory at c0000000 (32-bit, prefetchable) [size=256M]
Memory at dff00000 (32-bit, non-prefetchable) [size=256K]
Expansion ROM at <unassigned> [disabled]
Capabilities: <access denied>
00:02.1 Display controller: Intel Corporation Mobile 945GM/GMS/GME, 943/940GML Express Integrated Graphics Controller (rev 03)
Subsystem: Micro-Star International Co., Ltd. Device 0110
Flags: bus master, fast devsel, latency 0
Memory at dfe00000 (32-bit, non-prefetchable) [size=512K]
Capabilities: <access denied>
And it doesn't matter if it errs in trying to sli up with it self. That's just not a possibility.
Last edited by gog (2009-10-15 23:59:49) -
Running Ant file - build.xml from JDev
hi all
I have created simple BPEL project. I'm using JDev 10.1.3.1.0
& SOA suite 10.1.3.1.0 . If I deploy my BPEL process using deployment utility
of JDev then it gets deployed well on localhost:8888 .
But If I run build.xml Ant file from JDev then it complies properly but it tries to deploy on[b] localhost:9700. If I run same Ant file from Developer prompt then it again BPEL gets deployed properly on localhost:8888.
It means JDev is overwriting some properties values.
Does any one aware of this.?
thanks
/patelHi Patel,
Have a look here:
http://www.it-eye.nl/weblog/2007/02/16/customizing-bpel-process-deployement-with-ant-165-in-jdeveloper/
Maybe it will helpp you out!
Regards,
Tom -
Can ant call a target from my build.xml from another xml file?
can ant have a target something like this:
<target mytarget>
<antcall file="C:\app\build2.xml" targetname="blah">
</target>
Is it possible to call a target in my build.xml that will then look in a file called build2.xml and call a target in that xml file?
Thanks,
TadI looked at the manual and the site and couldn't find anything, you don't have to tell me the exact xml if
it bugs you, all I want to know is if it is possible and if it is what task should I use, I will look up
the attributes and how to do it.Now this really takes the biscuit.
I gave you a very specific link to the document that tells you which task to use and which arguments to set. Did you check that link? If so, what else do you want? If not, why not? -
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> -
Grabbing xml from raw data post to my webserver
Trying to figure out how to catch xml being posted to my webserver. The client's instructions are:
The HTTP and HTTPS delivery method performs a text/plain mime binary data post to the supplier's webserver. Suppliers must develop a catch web page. This page will receive the binary post.
This is an xml document that I must capture and write to disk. I'm intending to use a java servlet to grab this data but java is new to me. It looks like HttpServletRequest is what I'm looking for. Anyone with any pointers?
thanks,
destinOkay, 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 -
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. -
Generating xml from oracle-data
In our company we have to export customer-data to xml using a predefined format (which we cannot change).
This xml will subsequently be used to import the data into another system.
I'm not that familiar with XML. Most of the work can be done using dbms_xmlgen which is pretty simple and straightforward to use
There is one type of element I cannot place correctly in the specification
The use of foreign keys. For instance
A employee has a foreign key to a bussiness unit that should be written down in the xml
when using "normal" dbms_xmlgen the tag would be like
<bussinessunit>"bisut100"</bussinessunit>
But the specification specifies the following format
<bussinessunit bussinesunitId="bisut100"/>
Any idea how to get this using dbms_xmlgen?
Or if not possible with dbms_xmlgen how could this easily be achieved?Thanks for the reply and the challenge is more to generate the closing tag exactly like in the specification
The following is a snippet of what is required
-<employee>
<id>2</id>
<empno>102105<empno>
-<name>
<firstname>Tom</firstname>
<lastname>Hanks</lastname>
</name>
<bussinessunit bussinesunitId="bisut100"/>
<employee>
-<employee>
<id>3</id>
I wonder how to achieve the line
<bussinessunit bussinesunitId="bisut100"/>
I tried using
DBMS_XMLGEN.setNullHandling(qryCtx, DBMS_XMLGEN.EMPTY_TAG);
and then the construction
qryCtx := DBMS_XMLGEN.newContext(
' select id, custom0 bussinessunit , company_id "@bussinessunitId", lname
from tpt_employees t
where rownum < 2
and custom0 is null');
Unfortunately, the resulting xml-line
<BUSSINESSUNIT bussinessunitId = "1" <BUSSINESSUNIT/>
is not the xml I had hoped for (it's not valid as well) -
Here's my scenario:
I have multiple PL/SQL stored functions that return REF CURSORs. Each REF CURSOR contains information to build a portion of an XML document. I want to assemble these XML "fragments" into a DOM object, then apply a stylesheet to the entire object before saving it to a table.
All of this will be done in Java, and I need to make it efficient (in terms of speed and memory) since the XML document may grow to be very large. What is the best way to go about doing this?
Right now, I'm able to call getXMLDOM() which returns a complete XML document for each fragment, but what should I do with it now? Does anyone have any suggestions on what my next step should be?SetDocType is available only in JDOM parser. I would like to know is it prossible without that.
Thanks !! -
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!
Maybe you are looking for
-
How do I open a password protected excel file created on a PC in numbers 09, on a MacBook Air? I get a message that the "file is encrypted and can't be opened"
-
HP Laserjet p3005x - jamming during all duplex print jobs
We have recently aquired a used HP Laserjet p3005x printer that jams under the print cartridge during every duplex print job. The message in the printer log is Event 13.05.00 "Fuser output - Paper late jam"
-
I'm not very good with computers and am new to macs, my jvc camcorder won't import video to imovie. I plugged it in with the included USB cord that worked fine on my PC but it doesn't recongnize it when I plug it into my ibook G4 what do I have to do
-
User exit & badi for delivery block
Hello All, Based on some criteria i want to block the sales order when creating a sales order via abap program. Can anybody can tell me the user exit name or badi name? Thanks in advance! point will be award. regards, Alex M
-
Ledger Assignment to Company code
Where do we assign Non-Leading ledgers to company code