Home » Developer & Programmer » JDeveloper, Java & XML » XML Processing (Oracle 10g)
XML Processing [message #474367] |
Sun, 05 September 2010 23:49  |
depakjan
Messages: 12 Registered: November 2009
|
Junior Member |
|
|
Hi Guys,
i have a table which has a CLOB data type column that holds a XML. i need select the some of the nodes from it.. sample XML looks like this.. there are actually 100 or more nodes totally but i want to select some 4 of them as a coloumn for my select query. please help me out in this guys.
<?xml version="1.0" encoding="UTF-8"?><alert>
<tab0 comment="section in XSL component" name="Initial Information">
<details>
<Priority>0001</Priority>
<DateVRUClaimInitiated>2010-06-29</DateVRUClaimInitiated>
</details>
<contacts comment="grid in XSL component">
many child nodes here
</contacts>
</tab0>
<tab1 comment="section in XSL component" name="Additional Information">
<details comment="list collection in XSL component">
Many child nodes here
</details>
<IPAddresses>
Many child nodes here
</IPAddresses>
<ANIPhones>
Many child nodes here
</ANIPhones>
</tab1>
<tab2 name="Loss Avoidance">
<losstable>
Many child nodes here
</losstable>
<summary>
Many child nodes here
</summary>
<accounts>
Many child nodes here
</accounts>
</tab2>
<tab3 name="R & R">
<narrative>
Many child nodes here
</narrative>
</tab3>
</alert>
|
|
|
|
Re: XML Processing [message #474371 is a reply to message #474368] |
Mon, 06 September 2010 00:29   |
depakjan
Messages: 12 Registered: November 2009
|
Junior Member |
|
|
i have tried these two types both of them fail if i have where condition
select alert_internal_id,x.* from alerts, xmltable ('.' passing XMLTYPE(xml)
columns prio varchar2 (5) path '/alert/tab0/details/Priority',
dt varchar2 (15) path '/alert/type0/details/DateVRUClaimInitiated',
type_comment varchar2 (25) path '/alert/tab0/@comment') x where x.dt is not null;
select alert_internal_id,extractvalue( xmltype(HTML_FILE_KEY),'/alert/tab0/details/DateVRUClaimInitiated')
as check1
from alerts
where extractvalue( xmltype(HTML_FILE_KEY),'/alert/tab0/details/DateVRUClaimInitiated')
is not null;
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00210: expected '<' instead of '['
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 254
ORA-06512: at line 1
[Updated on: Mon, 06 September 2010 00:49] by Moderator Report message to a moderator
|
|
|
|
Re: XML Processing [message #474378 is a reply to message #474375] |
Mon, 06 September 2010 01:07   |
depakjan
Messages: 12 Registered: November 2009
|
Junior Member |
|
|
found this it works if i have less number of rows in the table, any other way ??..
select alert_internal_id,x.* from alerts, xmltable ('.' passing XMLTYPE(xml)
columns prio varchar2 (5) path '/alert/tab0/details/Priority',
dt varchar2 (15) path '/alert/type0/details/DateVRUClaimInitiated',
type_comment varchar2 (25) path '/alert/tab0/@comment') x
where alert_internal_id < 7000 and x.dt is not null;
Query returns rows
select alert_internal_id,x.* from alerts, xmltable ('.' passing XMLTYPE(xml)
columns prio varchar2 (5) path '/alert/tab0/details/Priority',
dt varchar2 (15) path '/alert/type0/details/DateVRUClaimInitiated',
type_comment varchar2 (25) path '/alert/tab0/@comment') x
where alert_internal_id < 8000 and x.dt is not null;
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00210: expected '<' instead of '['
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 254
ORA-06512: at line 1
[Updated on: Mon, 06 September 2010 01:13] by Moderator Report message to a moderator
|
|
|
Re: XML Processing [message #474383 is a reply to message #474378] |
Mon, 06 September 2010 01:29   |
sujeethkannan
Messages: 10 Registered: August 2010 Location: CHENNAI
|
Junior Member |
|
|
Can you try XML parsing using PL/SQL XDK
declare
p xmlparser.parser;
doc xmldom.DOMDocument;
nl xmldom.DOMNodeList;
len1 number;
len2 number;
n xmldom.DOMNode;
e xmldom.DOMElement;
nnm xmldom.DOMNamedNodeMap;
attrname varchar2(100);
attrval varchar2(100);
l_c_lob clob ;
l_v_var varchar2(32000) := '<?xml version="1.0" encoding="utf-8"?>
<EMPDETAILS>
<EMP>
<NUM>7369</NUM>
<SAL>180</SAL>
</EMP>
<EMP>
<NUM>7369</NUM>
<SAL>180</SAL>
</EMP>
<EMP>
<NUM>7369</NUM>
<SAL>180</SAL>
</EMP>
</EMPDETAILS>';
begin
dbms_lob.createtemporary(l_c_lob,TRUE);
dbms_lob.OPEN(l_c_lob,dbms_lob.lob_readwrite);
DBMS_LOB.WRITE (l_c_lob, LENGTH (l_v_var), 1,l_v_var);
-- new parser
p := xmlparser.newParser;
xmlparser.setValidationMode(p, FALSE);
xmlparser.parseClob(p,l_c_lob);
doc := xmlparser.getDocument(p);
nl := xmldom.getElementsByTagName(doc, '*');
len1 := xmldom.getLength(nl);
-- loop through elements
for j in 0..len1-1 loop
n := xmldom.item(nl, j);
e := xmldom.makeElement(n);
attrname := xmldom.getNodeName(n);
attrval:=xmldom.getNodeValue(xmldom.getFirstChild(n));
dbms_output.put_line(attrname||' = '||attrval);
end loop;
EXCEPTION
when OTHERS then
RAISE;
end;
/
Thanks,
Sujeeth kannan
|
|
|
Re: XML Processing [message #474384 is a reply to message #474383] |
Mon, 06 September 2010 01:40   |
 |
Michel Cadot
Messages: 68418 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
1/
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version, with 4 decimals.
2/
Quote:EXCEPTION when OTHERS then RAISE;
This is one of the most STUPID thing I ever read in PL/SQL code.
Regards
Michel
[Updated on: Mon, 06 September 2010 01:40] Report message to a moderator
|
|
|
Re: XML Processing [message #474387 is a reply to message #474383] |
Mon, 06 September 2010 01:49   |
sujeethkannan
Messages: 10 Registered: August 2010 Location: CHENNAI
|
Junior Member |
|
|
If its works for you can handle exception.
when xmldom.INDEX_SIZE_ERR then
raise_application_error(-20120, 'Index Size error');
when xmldom.DOMSTRING_SIZE_ERR then
raise_application_error(-20120, 'String Size error');
when xmldom.HIERARCHY_REQUEST_ERR then
raise_application_error(-20120, 'Hierarchy request error');
when xmldom.WRONG_DOCUMENT_ERR then
raise_application_error(-20120, 'Wrong doc error');
when xmldom.INVALID_CHARACTER_ERR then
raise_application_error(-20120, 'Invalid Char error');
when xmldom.NO_DATA_ALLOWED_ERR then
raise_application_error(-20120, 'Nod data allowed error');
when xmldom.NO_MODIFICATION_ALLOWED_ERR then
raise_application_error(-20120, 'No mod allowed error');
when xmldom.NOT_FOUND_ERR then
raise_application_error(-20120, 'Not found error');
when xmldom.NOT_SUPPORTED_ERR then
raise_application_error(-20120, 'Not supported error');
when xmldom.INUSE_ATTRIBUTE_ERR then
raise_application_error(-20120, 'In use attr error');
|
|
|
|
Re: XML Processing [message #474389 is a reply to message #474387] |
Mon, 06 September 2010 02:10  |
 |
Michel Cadot
Messages: 68418 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
sujeethkannan wrote on Mon, 06 September 2010 08:49If its works for you can handle exception.
when xmldom.INDEX_SIZE_ERR then
raise_application_error(-20120, 'Index Size error');
when xmldom.DOMSTRING_SIZE_ERR then
raise_application_error(-20120, 'String Size error');
when xmldom.HIERARCHY_REQUEST_ERR then
raise_application_error(-20120, 'Hierarchy request error');
when xmldom.WRONG_DOCUMENT_ERR then
raise_application_error(-20120, 'Wrong doc error');
when xmldom.INVALID_CHARACTER_ERR then
raise_application_error(-20120, 'Invalid Char error');
when xmldom.NO_DATA_ALLOWED_ERR then
raise_application_error(-20120, 'Nod data allowed error');
when xmldom.NO_MODIFICATION_ALLOWED_ERR then
raise_application_error(-20120, 'No mod allowed error');
when xmldom.NOT_FOUND_ERR then
raise_application_error(-20120, 'Not found error');
when xmldom.NOT_SUPPORTED_ERR then
raise_application_error(-20120, 'Not supported error');
when xmldom.INUSE_ATTRIBUTE_ERR then
raise_application_error(-20120, 'In use attr error');
And what does this add to the original exception except it hides where it comes from and the complementary information it gives?
If you have nothing to do with an exception then let it go, it is stupid to trap it.
Regards
Michel
[Updated on: Mon, 06 September 2010 13:38] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat Mar 25 16:22:57 CDT 2023
|