Xpath.valueof
I'm working my way through Steve Muench's excellent book 'Building Oracle XML Applications' and I have come unstuck at Example 5.11. Test and Extract and Retrieve an Xpath Expression value.
Initially the XPATH package would not compile as it complained that the wrong type or numver of variables was present. Now for some reason it compiles okay. All the XPATH.<Functions> work with the exception of XPATH.VALUEOF which returns nothing
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "XMLBOOK.XPATH", line 122
ORA-06512: at "XMLBOOK.XPATH", line 128
ORA-06512: at line 13
I'm using a locally hosted 10g installation. Does anyone have any idea of what I need to do to fix this.
Best Regards
Chris Rose
In trying to get back to where I was I have tried recompiling the Xpath Package and body as listed below but it will not compile as it comes back with these errors. I have religiously followed all the installation instructions but I get stuck at this point.
Compilation errors for PACKAGE BODY SYS.XPATH
Error: PLS-00306: wrong number or types of arguments in call to 'VALUEOF'
Line: 118
Text: RETURN normalizeWS(xslprocessor.valueOf(node,xpath));
Error: PL/SQL: Statement ignored
Line: 118
Text: RETURN normalizeWS(xslprocessor.valueOf(node,xpath));
Error: PLS-00306: wrong number or types of arguments in call to 'VALUEOF'
Line: 120
Text: RETURN xslprocessor.valueOf(node,xpath);
Error: PL/SQL: Statement ignored
Line: 120
Text: RETURN xslprocessor.valueOf(node,xpath);
Error: PLS-00323: subprogram or cursor 'VALUEOF' is declared in a package specification and must be defined in the package body
Line: 17
Text: WHILE (INSTR(result,' ') > 0) LOOP
CREATE OR REPLACE PACKAGE xml AS
-- Set HTTP proxy server in case you reference documents
-- or DTDs outside a corporate firewall
PROCEDURE setHttpProxy(machinename VARCHAR2,
port VARCHAR2 := '80');
-- Parse and return an XML document
FUNCTION parse(xml VARCHAR2) RETURN xmldom.DOMDocument;
FUNCTION parse(xml CLOB) RETURN xmldom.DOMDocument;
FUNCTION parse(xml BFILE) RETURN xmldom.DOMDocument;
-- Parse and return an XML Document by URL
FUNCTION parseURL(url VARCHAR2) RETURN xmldom.DOMDocument;
-- Free the memory used by an XML document
PROCEDURE freeDocument(doc xmldom.DOMDocument);
END;
CREATE OR REPLACE PACKAGE BODY xml AS
parse_error EXCEPTION;
PRAGMA EXCEPTION_INIT(parse_error,-20100);
http_proxy_host VARCHAR2(200);
http_proxy_port VARCHAR2(5) := '80';
PROCEDURE setHttpProxy(machinename VARCHAR2, port VARCHAR2 := '80') IS
BEGIN
http_proxy_host := machinename;
http_proxy_port := port;
END;
-- Set HTTP Proxy for Java programs in the current session.
PROCEDURE setProxy IS
BEGIN
IF http_proxy_host IS NOT NULL THEN
http_util.setProxy(http_proxy_host,http_proxy_port);
END IF;
END;
-- Parse functions parse an XML document and return a handle to
-- the in-memory DOM Document representation of the parsed XML.
-- Call freeDocument( ) when you're done using the document returned
-- by the function.
FUNCTION parse(xml VARCHAR2) RETURN xmldom.DOMDocument IS
retDoc xmldom.DOMDocument;
parser xmlparser.Parser;
BEGIN
IF xml IS NULL THEN RETURN NULL; END IF;
setProxy;
parser := xmlparser.newParser;
xmlparser.parseBuffer(parser,xml);
retDoc := xmlparser.getDocument(parser);
xmlparser.freeParser(parser);
RETURN retDoc;
EXCEPTION
WHEN parse_error THEN
xmlparser.freeParser(parser);
RETURN retdoc;
END;
FUNCTION parse(xml BFILE) RETURN xmldom.DOMDocument IS
retDoc xmldom.DOMDocument;
parser xmlparser.Parser;
b BFILE := xml;
c CLOB;
BEGIN
IF xml IS NULL THEN RETURN NULL; END IF;
setProxy;
parser := xmlparser.newParser;
dbms_lob.createtemporary(c,cache=>FALSE);
dbms_lob.fileOpen(b);
dbms_lob.loadFromFile(dest_lob => c,
src_lob => b,
amount => dbms_lob.getLength(b));
dbms_lob.fileClose(b);
xmlparser.parseCLOB(parser,c);
retDoc := xmlparser.getDocument(parser);
dbms_lob.freetemporary(c);
xmlparser.freeParser(parser);
RETURN retDoc;
EXCEPTION
WHEN parse_error THEN
dbms_lob.freetemporary(c);
xmlparser.freeParser(parser);
RETURN retdoc;
END;
FUNCTION parse(xml CLOB) RETURN xmldom.DOMDocument IS
retDoc xmldom.DOMDocument;
parser xmlparser.Parser;
BEGIN
IF xml IS NULL THEN RETURN NULL; END IF;
setProxy;
parser := xmlparser.newParser;
xmlparser.parseCLOB(parser,xml);
retDoc := xmlparser.getDocument(parser);
xmlparser.freeParser(parser);
RETURN retDoc;
EXCEPTION
WHEN parse_error THEN
xmlparser.freeParser(parser);
RETURN retdoc;
END;
FUNCTION parseURL(url VARCHAR2) RETURN xmldom.DOMDocument IS
xmldoc xmldom.DOMDocument;
BEGIN
IF url IS NULL THEN RETURN NULL; END IF;
setProxy;
RETURN xmlparser.parse(url);
END;
-- Free the Java objects associated with an in-memory DOM tree
PROCEDURE freeDocument(doc xmldom.DOMDocument) IS
BEGIN
xmldom.freeDocument(doc);
END;
END;
Similar Messages
-
XPath valueOf fails if value 4k
Create an XML document where the TEXT in
SrvcEquipData value="TEXT" is greater than 4k ...
DECLARE
l_clob CLOB;
doc xmldom.domdocument;
l_string VARCHAR2(32767);
PROCEDURE p (i VARCHAR2) IS BEGIN dbms_output.put_line(i); END;
BEGIN
p('begin');
SELECT xmldoc INTO l_clob
FROM xml_documents
WHERE docname = 'KHA_RES_TEST';
p('pre parse');
doc := xml.parse(l_clob);
p('pre xpath valueOf');
l_string := xslprocessor.valueOf(xmldom.makeNode(doc),'//SrvcEquipData/@value');
p('pre print');
p(substr(l_string,1,255));
p('end');
END;
This code returns the following after completing successfully ... Any ideas?
begin
pre parse
pre xpath valueOftry using different loadvars instances for your send loadvars and for your receive loadvars.
-
XPATH + namespaces in 8i not possible?
Hi,
im trying to use the XPATH helper package to search a XML document that uses namespaces but it cant match anything:
<bt1:root xmlns:bt1="http://127.0.0.1">
<bt1:Error>
<test>test value</test>
for example i want 'test' yet when i try to get it using the pl/sql xpath package (in Steve Muench's oracle xml applications book) i get a NULL back.
result := xpath.valueOf (xmldoc, '//bt1:Error/test');
result is always null.
if i remove the NS prefix it works fine.
is it possible to modify this package to work with a NS? or is there another way of doing this?
(the xml i recieve is from an external source and cant be modified btw)
im using Oracle 8.1.7.2 (with the 9i xml xdk)
ThanksI am finding myself asking the same question. I'm trying to use a count() function to find out how many nodes match the XPath pattern I specify. I'm using the PL/SQL API, but since that wraps the Java API, I'm sure that if it doesn't work in Java, it surely won't work in PL/SQL.
It's been over six weeks since you posted your question, and no one from Oracle has troubled to reply. Is all Oracle support as lame as this? -
Getting question marks in html output when XML sourced from a CLOB...
I have noticed a number of other unanswered questions on the
same subject in this forum. Can someone at Oracle shed some
light on this problem?...
I store XML in CLOBS which contain a lot of é ö
characters. When using XSQL to select the XML from the CLOB I
have to apply a stylesheet to the XSQL (myFile.xsql) with
disable-output-escaping ="yes" in order to output well formed
XML.
I then call the XSQL file from inside another stylesheet i.e.
<xsl:variable name="sample" select="document(myFile.xsql)"/>
<xsl:template match="/">
<xsl:for-each select="$sample">
<html>
<body>
<title>
<xsl:value-of select="/page/title"/>
</title>
</body>
</html>
etc...
I use <xsl:for-each select="$sample"> to output the XML I need,
within the HTML. The problem is though if "é" appears in
the /page/title node the output in HTML appears as a question
mark.
Its important to note as well that the stylesheet I apply to
myFile.xsql starts with:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output doctype-system="/myFile.dtd" indent="yes"/>
etc..
and myFile.dtd has <!ENTITY eacute "é"> in order to
validate é in the CLOB.
I don't have this problem when the é character is stored
in a VARCHAR2 column and the VARCHAR2 column is in the same
select statement as the CLOB in the XSQL file. This outputs in
my HTML just fine. What am I missing here?
ShaunI parse the XML doc into a domdocument and then loop through using xpath.valueof to pull the individual values from the nodes and then build a generic insert. It works quite well with a small number of columns. I'm not sure how it would work with a lot of columns. You can get code examples from Steve Muench's book "Developing Oracle XML Applications".
-
XML Parsing error in PL/SQL
Hello,
I have some problem in parsing Mircrosoft OpenXML file using Oracle 10g Release2 XML Parser for PL/SQL.
I use dbms_xmlparser, dbms_xmldom, dbms_xslprocessor packages
OpenXML file use "w:" as namespace, so every element has prefix "w:" like
<w:wordDocument ..>
<w:body..>
<w:p..>
<w:r..>
<w:t..>
My job is to read OpenXML file inside PL/SQL code, parse it, and load it into the corresponding table.
Here is my PL/SQL code.
DECLARE
doc dbms_xmldom.DOMDocument;
node_list dbms_xmldom.DOMNodeList;
l_node dbms_xmldom.DOMNode;
one_element dbms_xmldom.DOMElement;
PROCEDURE p (msg VARCHAR2, nl BOOLEAN := TRUE) IS
BEGIN
dbms_output.put_line (msg);
IF nl THEN dbms_output.put(CHR(10)); END IF;
END:
BEGIN
doc := xml.parse(BFileName('XML_DIR','OpenXMLFile.xml'));
node_list := xpath.selectNodes(doc, '/w:wordDocument/w:body/w:p/w:r/w:t');
FOR j IN 0..dbms_xmldom.getLength(node_list)-1
LOOP
p( xpath.valueOf(dbms_xmldom.item(node_list, j), '.'), nl=>FALSE );
END LOOP;
Here is the error message.
ERROR at line 1:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token in: '/w:wordDocument/w:body/w:p/w:r/w:t
[starts-with(., "!")]'
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 900
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 928
ORA-06512: at "SYSTEM.XPATH", line 173
ORA-06512: at "SYSTEM.XPATH", line 179
ORA-06512: at line 38
I really don't know why I got this error message nor how to solve it. If I remove "w:" manually within open xml file, then parsing works well. I guess XML parser for PL/SQL doesn't recognize ":" or maybe doesn't support namespace?
My question is
1. In oracle 10g release2, XML Parser for PL/SQL can recognize ":" in the element name? or does it support namespace? If not, is there any workaround for solving this problem?
2. How can I make XML Parser recognize ":" in the element name in the xml file or How can I declare namespace in the PL/SQL code so that PL/SQL xml parser can recognize namespace like "w:"?
In fact, I don't use XML DB and what I want to do is just to load XML file into the relational table and some parts of whole XML file will be inserted into the CLOB in the table.
Should I really use XML DB to do the above job?
Any comment or suggestions will be greatly appreciated.This works correctly. I added prefixes to your extract path. (I had to add the xmlns:xsi to your root node also.)
declare
-- Local variables here
doc_in dbms_xmldom.DOMDocument;
aNodeList dbms_xmldom.DOMNodeList;
begin
-- Test statements here
doc_in := dbms_xmldom.newdomdocument(
'<?xml version="1.0" encoding="UTF-8"?>' ||
'<ap:Collection xmlns:ap="http://www.abc.com/ap" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.abc.com/ap template.xsd"> ' ||
'<ap:info>' ||
'<ap:data name="Barbie" age="3">' ||
'</ap:data>' ||
'</ap:info>' ||
'</ap:Collection>');
aNodeList := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(doc_in),
'/ap:Collection/ap:info',
'xmlns:ap="http://www.abc.com/ap"');
dbms_output.put_line('length of aNodeList = '|| dbms_xmldom.getLength(aNodeList) );
end; -
We are currently receiving XML messages from a business partner that goes
through a transformation/parser first to make sure the xml document was
in MISMO form (Mortgage Industry Standard Message Organization). Then the
document is stored in a clob in a table. The document is stored Without
the tags. We are storing these XML messages into a CLOB datatype for
later processing. I want to read the CLOB and then parse out the
individual fields to store into a table. What is the best way to
accomplish this in PL/SQL? Here is one sample record:
<MORTGAGEDATA>
<APPLICATION LoanPurposeType="OTHER">
<LenderCaseIdentifier>3631681</LenderCaseIdentifier>
<LendersBranchIdentifier>2966448</LendersBranchIdentifier>
</APPLICATION>
<PROPERTY PropertyUsageType="Primary">
<Address1>1335 test</Address1>
<City>las cruces</City>
<State>NM</State>
<PostalCode>88001</PostalCode>
</PROPERTY>
<SUBJECTPROPERTY>
<SubjectPropertyEstimatedValueAmount>69000</SubjectPropertyEstimatedValueAmount>
</SUBJECTPROPERTY>
<BORROWERRECONCILEDLIABILITY LiabilityType="HelocSubjectProperty">
<LiabilityUnpaidBalanceAmount>0</LiabilityUnpaidBalanceAmount>
<LiabilityMonthlyPaymentAmount>0</LiabilityMonthlyPaymentAmount>
</BORROWERRECONCILEDLIABILITY>
<BORROWERRECONCILEDLIABILITY LiabilityType="MortgageLoanSubjectProperty">
<LiabilityUnpaidBalanceAmount>0</LiabilityUnpaidBalanceAmount>
</BORROWERRECONCILEDLIABILITY>
<BORROWER>
<FirstName>scooby</FirstName>
<MiddleName/>
<LastName>doo</LastName>
<NameSuffix/>
<MothersMaidenName>velma</MothersMaidenName>
</BORROWER>
</MORTGAGEDATA>
NOTE: I have tried to use DBMS_XMLQUERY and it comes out like this using a
stored procedure called printclob: When I do this the data is put into
one field called xml_app_msg. The problem is how do I reference the
individual fields like FirstName and so on to store in another table? Can
I apply a stylesheet and if so, how?
Or do I create an object type called xml_app_msg with the fields lastname
and so on?
-- The table is raw_xml_msg_tbl and the field with the stored infomation is
xml_app_msg.
set serveroutput on size 50000
declare
queryCtx DBMS_XMLquery.ctxType;
result CLOB;
begin
queryCtx := DBMS_XMLQuery.newContext('select xml_app_msg from raw_xml_msg_tbl where app_id = :APP_ID');
-- DBMS_XMLQuery.clearBindValue(queryCtx);
DBMS_XMLQuery.setBindValue(queryCtx,'APP_ID','LT1001');
-- get the result..!
result := DBMS_XMLQuery.getXML(queryCtx);
-- Now you can use the result to put it in tables/send as messages..
printClobOut(result);
DBMS_XMLQuery.closeContext(queryCtx); -- you must close the query handle..
end;
OUTPUT:
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<XML_APP_MSG><MORTGAGEDATA>
<BORROWER>
<FirstName>Falls</FirstName>
<MiddleName/>
<LastName>Water</LastName>
<NameSuffix/>
<SSN>123-45-6789</SSN>
</BORROWER>
</MORTGAGEDATA>
</XML_APP_MSG>
</ROW>
</ROWSET>
nullI parse the XML doc into a domdocument and then loop through using xpath.valueof to pull the individual values from the nodes and then build a generic insert. It works quite well with a small number of columns. I'm not sure how it would work with a lot of columns. You can get code examples from Steve Muench's book "Developing Oracle XML Applications".
-
Xmlns attribute in 8.1.7
I am trying to process an XML file with the Oracle 8.1.7 PL/SQL XDK. I'm using Steve's helper programs from the XML book. The problem is that the document in question uses XML Schema. My script chokes whenever I attempt anything with this file. After a lot of investigation I have established that it's the xmlns attibute that it doesn't like (see testcase below).
Given that I can't upgrade to 9i just yet is there anything I can do to get this code working?
Cheers In Advance, APC
This doesn't can't find my attribute...
SQL> DECLARE
2 xdoc xmldom.DOMDocument;
3 l_file varchar2(32000) := '<MYROOT xmlnsBOB="http://www.somewhere.co.uk"> '
4 || ' <MYTAG>stuff</MYTAG> '
5 || '</MYROOT>';
6 lv_file_ref varchar2(240);
7 parser xmlparser.Parser;
8 BEGIN
9 parser := xmlparser.newParser;
10 xmlparser.setValidationMode(parser, FALSE);
11 xmlparser.parseBuffer(parser,l_file);
12 xdoc := xmlparser.getDocument(parser);
13 xmlparser.freeParser(parser);
14 lv_file_ref := xpath.valueOf(xdoc, '/MYROOT/MYTAG');
15 dbms_output.put_line('!'||lv_file_ref||'!');
16* END;
PL/SQL procedure successfully completed.
but runs okay if I rename the xmlns attribute...
SQL> DECLARE
2 xdoc xmldom.DOMDocument;
3 l_file varchar2(32000) := '<MYROOT xmlnsBOB="http://www.somewhere.co.uk"> '
4 || ' <MYTAG>stuff</MYTAG> '
5 || '</MYROOT>';
6 lv_file_ref varchar2(240);
7 parser xmlparser.Parser;
8 BEGIN
9 parser := xmlparser.newParser;
10 xmlparser.setValidationMode(parser, FALSE);
11 xmlparser.parseBuffer(parser,l_file);
12 xdoc := xmlparser.getDocument(parser);
13 xmlparser.freeParser(parser);
14 lv_file_ref := xpath.valueOf(xdoc, '/MYROOT/MYTAG');
15 dbms_output.put_line('!'||lv_file_ref||'!');
16* END;
!stuff!
PL/SQL procedure successfully completed.
SQL>I am trying to process an XML file with the Oracle 8.1.7 PL/SQL XDK. I'm using Steve's helper programs from the XML book. The problem is that the document in question uses XML Schema. My script chokes whenever I attempt anything with this file. After a lot of investigation I have established that it's the xmlns attibute that it doesn't like (see testcase below).
Given that I can't upgrade to 9i just yet is there anything I can do to get this code working?
Cheers In Advance, APC
This doesn't can't find my attribute...
SQL> DECLARE
2 xdoc xmldom.DOMDocument;
3 l_file varchar2(32000) := '<MYROOT xmlnsBOB="http://www.somewhere.co.uk"> '
4 || ' <MYTAG>stuff</MYTAG> '
5 || '</MYROOT>';
6 lv_file_ref varchar2(240);
7 parser xmlparser.Parser;
8 BEGIN
9 parser := xmlparser.newParser;
10 xmlparser.setValidationMode(parser, FALSE);
11 xmlparser.parseBuffer(parser,l_file);
12 xdoc := xmlparser.getDocument(parser);
13 xmlparser.freeParser(parser);
14 lv_file_ref := xpath.valueOf(xdoc, '/MYROOT/MYTAG');
15 dbms_output.put_line('!'||lv_file_ref||'!');
16* END;
PL/SQL procedure successfully completed.
but runs okay if I rename the xmlns attribute...
SQL> DECLARE
2 xdoc xmldom.DOMDocument;
3 l_file varchar2(32000) := '<MYROOT xmlnsBOB="http://www.somewhere.co.uk"> '
4 || ' <MYTAG>stuff</MYTAG> '
5 || '</MYROOT>';
6 lv_file_ref varchar2(240);
7 parser xmlparser.Parser;
8 BEGIN
9 parser := xmlparser.newParser;
10 xmlparser.setValidationMode(parser, FALSE);
11 xmlparser.parseBuffer(parser,l_file);
12 xdoc := xmlparser.getDocument(parser);
13 xmlparser.freeParser(parser);
14 lv_file_ref := xpath.valueOf(xdoc, '/MYROOT/MYTAG');
15 dbms_output.put_line('!'||lv_file_ref||'!');
16* END;
!stuff!
PL/SQL procedure successfully completed.
SQL> -
?xml version="1.0"? tag not appearing as first characters in document
Hi,
JSP below successfully creates a XML document but it includes a blank line before the <?xml version="1.0"?> tag.
This causes my PL/SQL to return a "ORA-20100: Error occurred while parsing: PI names starting with 'xml' are
reserved." error when using the XMLPARSER package.
I am outputting the XML to IE5.0 but even if I do a SYSTEM out I get the same blank line before the initial tag.
There are posts on here that confirm the PI error is caused by the tag not being the first characters in the document, but no solution/fix is provided.
Any ideas much appreciated.
JSP Code
<%@ page import="java.sql.*, oracle.jbo.*, oracle.jdeveloper.cm.*, oracle.jdbc.*,oracle.xml.sql.query.*" %>
<%String driver="oracle.jdbc.driver.OracleDriver";
Driver d = new oracle.jdbc.driver.OracleDriver();
String dbURL="jdbc:oracle:thin:@localhost:1521:mydb";
String login="i2k";
String password="fred";
Connection cn = null;
cn = DriverManager.getConnection(dbURL,login,password);
// SQL Statement from URL Parameters
String sql = request.getParameter("sql");
if(sql == null){
sql = "select * from vfi_trans";
// Create SQL-to-XML Handler
OracleXMLQuery q = new OracleXMLQuery(cn, sql);
// Use <TransactionList> as document element for Rowset
q.setRowsetTag("TransactionList");
// Use <Transaction> for each row in the result
q.setRowTag("Transaction");
// set encoding
q.setEncoding("iso-8859-1");
// ensure lower case element names
q.useLowerCaseTagNames();
// Generate XML results and write to output
String xmldoc = q.getXMLString();
out.println(xmldoc.trim());
//System.out.println(xmldoc.indexOf("\n"));
cn.close();%>
PL/SQL
PROCEDURE XML_HANDLER2 IS
-- MODIFICATION HISTORY
-- Person Date Comments
vfiURL VARCHAR2(100);
parser xmlparser.Parser;
vfiXML xmldom.DOMDocument;
transactions xmldom.DOMNodeList;
transactions_found NUMBER;
curNode xmldom.DOMNode;
textChild xmldom.DOMNode;
v_itrans_site vfi_trans.itrans_site%TYPE;
BEGIN
dbms_output.put_line('Integrator 2000 Transactions');
-- This is the URL to browse for an XML-based vfi feed of stories on XML
vfiURL := 'http://10.1.1.111:7070/i2k25_html/ShowQuery.jsp?sql=select%20*%20from%20vfi_trans';
-- Set the machine to use as the HTTP proxy server for URL requests
http_util.setProxy('MYPROXY');
-- Parse the live XML vfi feed from Moreover.com by URL
parser := xmlparser.newParser;
vfiXML := xml.parseURL( vfiURL );
xmlparser.freeParser(parser);
-- Search for all <headline_text> elements in the document we recieve
transactions := xpath.selectNodes(vfiXML,'/TransactionList/ITRANS_ID');
-- Loop over the "hits" and print out the text of the title
FOR j IN 1..xmldom.getLength(transactions) LOOP
-- Get the current <headline_text> node (Note the list is zero-based!)
curNode := xmldom.item(transactions,j-1);
-- The text of the title is the first child (text) node of
-- the <headline_text> element in the list of "hits"
-- textChild := xmldom.getFirstChild(curNode);
v_itrans_site := xpath.valueof(curNode, '.');
dbms_output.put_line('('| |LPAD(j,2)| |') '| | v_itrans_site);
END LOOP;
-- Free the XML document full of vfi stories since we're done with it.
xml.freeDocument(vfiXML);
EXCEPTION
WHEN OTHERS THEN
RAISE;
END; -- Procedure
nullCharles,
I believe that the blank line is caused by the JSP engine when it strips out the '<%@ page import...>' (replace bracket with brace) statement. God (or at least Larry E) forgive me for posting a link at IBM, but this article speaks to your issue:
http://www-106.ibm.com/developerworks/library/j-dynxml.html?dwzone=ibm
Maybe you need to put the <?xml?> tag in the jsp itself and strip it out of your xmldoc before outputting it.
Good luck. -
To get the data from an XML document, what methods shoulf one use - the cdatasection or characterdata method? On using the character data it gives out the following error:
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.ClassCastException
ORA-06512: at "SCOTT.XMLCHARDATACOVER", line 0
ORA-06512: at "SCOTT.XMLDOM", line 824
The piece of code is:
dbms_output.put_line('Yes, it is text: ' | | xmldom.substringData(cd, 1,10));
cd is a 'characterdata type.'Jack,
After I parse it into a DOM, I use xpath.valueof() to get the value such as:
party_rec.ROLE := xpath.valueof(curnode, './/role');
Where party_rec is defined as:
party_rec NGTN_PARTY%ROWTYPE;
You can find more great info like this on my new website. It contains code examples, bug info and lots of other useful information. Go to www.webspedite.com/oracle.
Jason
null -
Example 5-11 in Steve Muench's Oracle-XML book
Hi,
Anyone who studied the book Building Oracle XML Applications by Steve Muench (O'Reilly), could clarify this query. When I tried to execute Example 5-11:Test,Extract and Retrieve an XPath Expression Value (page 132) I get the following error:
PLS-00307: too many declarations of 'SELECTNODES' match this call (complete source code given at the end of this message).
Could you please explain why this error is occurring.
Best wishes,
Balu
Code
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 doc xmldom.DOMDocument;
3 approvers xmldom.DOMNodeList;
4 PROCEDURE p(msg VARCHAR2, nl BOOLEAN := TRUE) IS BEGIN
5 dbms_output.put_line(msg);IF nl THEN dbms_output.put(CHR(10)); END IF;
6 END;
7 FUNCTION yn(b BOOLEAN ) RETURN VARCHAR2 IS
8 BEGIN IF b THEN RETURN 'Yes'; ELSE RETURN 'No'; END IF; END;
9 BEGIN
10 doc := xml.parse(BFileName('XMLFILES','claim77804.xml'));
11
12 p('What is the value of the Policy number for this claim?');
13 p( xpath.valueOf(doc,'/Claim/Policy') );
14
15 p('Does this claim have any settlement payments over $500 approved by JCOX?');
16 p(yn(xpath.test(doc,'//Settlements/Payment[. > 500 and @Approver="JCOX"]')));
17
18 -- Demonstrate Saving and Re-getting the XML document
19 xmldoc.save('claim77804',doc);
20 doc := xmldoc.get('claim77804');
21
22 p('What is XML document fragment contained by the <DamageReport> element?');
23 p(xpath.extract(doc,'/Claim/DamageReport'));
24
25 p('Who approved settlement payments for this claim?');
26 approvers := xpath.selectNodes(doc,'/Claim/Settlements/Payment');
27 FOR j IN 1..xmldom.getLength(approvers) LOOP
28 p(xpath.valueOf(xmldom.item(approvers,j-1),'@Approver'),nl=>FALSE);
29 END LOOP;
30 xml.freeDocument(doc);
31 END;
32
33 /
DECLARE
ERROR at line 1:
ORA-06550: line 26, column 16:
PLS-00307: too many declarations of 'SELECTNODES' match this call
ORA-06550: line 26, column 3:
PL/SQL: Statement ignoredI tried the wayback machine, but unfortunately, it doesn't cache the SWF files either :( I do have a copy of some (ok one) of Steve's old videos (the one that shows how to do a dropdown list in an editable table, back before it was easy to do), but unfortunately, none of the search ones.
John -
Extracting attributes from XML document using plsql
Hello,
I have successfully written a plsql procedure that has been
using Xpath to extract the element values from an XML doument:
i.e.
l_xpath := '/Form_Data/Person_Details/Initials';
l_DomNodeList := xslprocessor.SelectNodes(l_RootNode, l_xpath);
l_DomNode := xmldom.item(l_DomNodeList,0); -- first Element
l_DomNode := xmldom.getfirstchild(l_DomNode);
l_id_number := xmldom.getNodeValue(l_DomNode);
However the data (Initials) I wish to extract is now stored as
attributes within the Person_Details element and I was wondering
how I would go about explicitly extracting the attributes values!
I have not been able to find any examples, although I have been
pointed in the direction of xmldom.getattribute without any
success!
Any help, or code examples greatly appreciated,
- Mark...example:-
xpath.VALUEOF(i_doc,v_PricingPath||'@LockIndicator'); -
I have an XML file to inset into multiple tables.
My file is like
<?xml version="1.0" encoding="ISO-8859-1"?>
<DCDS>
<CDS>
<COD></COD>
<COD_INT></COD_INT>
<ULTIMA_MODIFICA></ULTIMA_MODIFICA>
<TIP></TIP>
<DEN></DEN>
<CLS>
<ID></ID>
<DEN></DEN>
</CLS>
<FAC></FAC>
<OBT>
<![CDATA[
]]>
</OBT>
<PRF>
<![CDATA[
]]>
</PRF>
<OCC>
<![CDATA[
]]>
</OCC>
<ACC>
<![CDATA[
]]>
</ACC>
<CUR>
<ID></ID>
<DEN></DEN>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT>
</SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT>
</SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT></SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT></SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT>
</SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT>
</SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT></SETT> <CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN> </CFMIN>
<CFMAX> </CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN> </CFMIN>
<CFMAX> </CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN> </CFMIN>
<CFMAX> </CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN> </CFMIN>
<CFMAX> </CFMAX>
<TP></TP>
</GRP>
</CUR>
</CDS>
</DCDS>
In some cases, like <GRP> tag, I have to insert multiple rows in a table. I found the valueOf, but it extracts only the first value contained.
payment.amount := xpath.valueOf(curNode,'.');
Some tips?I have an XML file to inset into multiple tables.
My file is like
<?xml version="1.0" encoding="ISO-8859-1"?>
<DCDS>
<CDS>
<COD></COD>
<COD_INT></COD_INT>
<ULTIMA_MODIFICA></ULTIMA_MODIFICA>
<TIP></TIP>
<DEN></DEN>
<CLS>
<ID></ID>
<DEN></DEN>
</CLS>
<FAC></FAC>
<OBT>
<![CDATA[
]]>
</OBT>
<PRF>
<![CDATA[
]]>
</PRF>
<OCC>
<![CDATA[
]]>
</OCC>
<ACC>
<![CDATA[
]]>
</ACC>
<CUR>
<ID></ID>
<DEN></DEN>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT>
</SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT>
</SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT></SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT></SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT>
</SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT>
</SETT>
<CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT></SETT> <CF></CF>
<CFMIN></CFMIN>
<CFMAX></CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN> </CFMIN>
<CFMAX> </CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN> </CFMIN>
<CFMAX> </CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN> </CFMIN>
<CFMAX> </CFMAX>
<TP></TP>
</GRP>
<GRP>
<ID></ID>
<DESCAMBITO></DESCAMBITO>
<SETT> </SETT>
<CF></CF>
<CFMIN> </CFMIN>
<CFMAX> </CFMAX>
<TP></TP>
</GRP>
</CUR>
</CDS>
</DCDS>
In some cases, like <GRP> tag, I have to insert multiple rows in a table. I found the valueOf, but it extracts only the first value contained.
payment.amount := xpath.valueOf(curNode,'.');
Some tips? -
Is there any way of finding out the namespace prefix if there is one, from a DOMParser instance or a XMLDocument instance?
I have a DOMParser instance and I don't know whether there is a namespace specification in it. If there is, I need to know what it is so I can update my XPath expressions to use the appropriate prefix.
I have tried the XMLDocument.getNamespace function but it doesn't seem to be implemented (or it is depricated).
Any help would be greatly appreciated.You're right on track with the namespaces hunch.
XPath 1.0 does not provide the ability to search on the default namespace.
That is, even if you document looks like this:<foo xmlns="urn:bar"/>you cannot use any compliant XPath 1.0 implementation to find the <foo> element with the pattern /foo, since in XPath 1.0 /foo finds the <foo> element that is the child of the root with a null namespace URI.
In the example above, the namespace uri of the <foo> element is urn:bar, so in particular it's not null.
With XPath 1.0, you need to specifically qualify the foo element with a namespace prefix that is bound to the same namespace URI as your default namespace.
So, your XPath would need to look like /xxx:foo where xxx is an arbitrary namespace prefix associated with the urn:bar namespace URI.
The selectNodes, selectSingleNode, and valueOf methods all have an overloading which takes an instance of the oracle.xml.parser.v2.NSResolver interface as the 2nd argument. This argument is used to resolve what namespace prefixes found in the XPath search string map to.
To implement the NSResolver interface, you need only implement a single method:
String resolveNamespacePrefix(String prefix);
In the example above, this method would return the string "urn:bar" when passed the prefix string "xxx" so that the XPath of /xxx:foo would match the <foo> element with urn:bar namespace uri in the example document above.
Steve Muench
Development Lead, Oracle XSQL Pages Framework
Lead Product Manager for BC4J and Lead XML Evangelist, Oracle Corp
Author, Building Oracle XML Applications
null -
I have an xml structure (see XML at bottom) which i want to traverse using the xpath (PL/SQL) utility.
I have written code that mainly uses xpath.selectNodes(...,...)
I can select the customers easily by using
xpath.selectNodes(...,'//customers_item')
FOR i IN 1..NVL(xmldom.getlength(lov_customers),0) LOOP
END LOOP;
but what I want is to get the products for EACH customer.
What I have inside the FOR LOOP is this
xpath.selectNodes(ip_xml_dom, '//customers_item/products/product');
but this gives me all products for all customers not the current customer.
I know if that if I put the correct sytax in the XPath expression I can get what I want?
I can't work this out, can anyone help
<GetProfileResponse>
<Return>
<site>
<customers>
<customers_item>
<id>1<id>
<products>
<product>
<prodid>100</prodid>
</product>
<product>
<prodid>101</prodid>
</product>
</products>
</customers_item>
<customers_item>
<id>2<id>
<products>
<product>
<prodid>102</prodid>
</product>
<product>
<prodid>103</prodid>
</product>
</products>
</customers_item>
</customers>
</site>
</Return>
</GetProfileResponse>
nullThe following code works fine for me using PLSQL XML Parser 1.0.2 in Oracle8i 8.1.6 and produces the output:
Customer id:1
--> Prod id:100
--> Prod id:101
Customer id:2
--> Prod id:102
--> Prod id:103
SET SERVEROUTPUT ON
DECLARE
xml VARCHAR2(2000) :=
'<GetProfileResponse>
<Return>
<site>
<customers>
<customers_item>
<id>1</id>
<products>
<product>
<prodid>100</prodid>
</product>
<product>
<prodid>101</prodid>
</product>
</products>
</customers_item>
<customers_item>
<id>2</id>
<products>
<product>
<prodid>102</prodid>
</product>
<product>
<prodid>103</prodid>
</product>
</products>
</customers_item>
</customers>
</site>
</Return>
</GetProfileResponse>';
p xmlparser.parser;
d xmldom.DOMDocument;
n xmldom.DOMNode;
nl_outer xmldom.DOMNodeList;
ct_outer NUMBER;
nl_inner xmldom.DOMNodeList;
ct_inner NUMBER;
xpCusts VARCHAR2(80);
xpProds VARCHAR2(80);
BEGIN
xpCusts := '/GetProfileResponse/Return/site/customers/customers_item';
xpProds := './/products/product';
p := xmlparser.newparser();
xmlparser.parseBuffer(p,xml);
d := xmlparser.getDocument(p);
n := xmldom.makeNode(d);
nl_outer := xslprocessor.selectNodes(n,xpCusts);
ct_outer := xmldom.getLength(nl_outer);
FOR i IN 0..ct_outer-1 LOOP
n := xmldom.item(nl_outer,i);
dbms_output.put_line('Customer id:'| |xslprocessor.valueOf(n,'id'));
nl_inner := xslprocessor.selectNodes(n,xpProds);
ct_inner := xmldom.getLength(nl_outer);
FOR j IN 0..ct_inner-1 LOOP
n := xmldom.item(nl_inner,j);
dbms_output.put_line('--> Prod id:'| |xslprocessor.valueOf(n,'prodid'));
END LOOP;
END LOOP;
xmldom.freeDocument(d);
xmlparser.freeparser(p);
END;
/ -
Dbms_xslprocessor.valueOf generates ora-24331
I am using 10.1.0.3.0 Oracle standard database. I am using dbms_xslprocessor to parse document. I get ora-24331.
FOR rec2 IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
l_n := dbms_xmldom.item(l_nl, rec2);
-- Use XPATH syntax to assign values to he elements of the collection.
dbms_xslprocessor.valueOf(l_n,'DATA/RECORD_TYPE[1]/text()',rectype);
dbms_xslprocessor.valueOf(l_n,'DATA/MAIN_ENTRY[1]/text()',mainentry);
dbms_xslprocessor.valueOf(l_n,'DATA/URL[1]/text()',url);
dbms_xslprocessor.valueOf(l_n,'DATA/TITLE[1]/text()',title);
dbms_xslprocessor.valueOf(l_n,'DATA/DESCRIPTION[1]/text()',description);
dbms_xslprocessor.valueOf(l_n,'DATA/SIMILAR-PAGES-URL[1]/text()',similaPageURL);
dbms_xslprocessor.valueOf(l_n,'DATA/MUSE_SESSION_UID[1]/text()',musesessionid);
dbms_xslprocessor.valueOf(l_n,'IDR/TITLE[1]/text()',IDRTITLE);
dbms_xslprocessor.valueOf(l_n,'DATA/MUSE_SESSION_UID[1]/text()',musesessionid);
dbms_xslprocessor.valueOf(l_n,'IDR/IDENTIFIER[1]/text()',idr_Identifier);
dbms_xslprocessor.valueOf(l_n,'IDR/DESCRIPTION[1]/text()',idr_description);
INSERT INTO DOJ_DATA(INSTRUCTION_ID , REFERENCE_ID,RESULT_SET_NAME, RECORD_TYPE,MAIN_ENTRY,URL,
TITLE ,DESCRIPTION,SIMILAR_PAGES_URL,MUSE_SESSION_UID,
RAWDATA,IDR_TITLE ,IDR_IDENTIFIER ,IDR_DESCRIPTION)
VALUES(insructionid,ref_id,result_set_name,rectype,mainentry,url,title,description,similaPageURL,
musesessionid,rawdata,IDRTITLE,idr_Identifier,idr_description);
commit;
END LOOP;
dbms_xmldom.freeDocument(doc);
dbms_xmlparser.freeParser(l_parser);Well, since you are probably trying to return more data than the varchar2 return parameter allows, you need to switch methods for how you are extracting data from the XML.
Three sample methods can be found in the sample at Re: ORA-20100: Error while parsing:Error opening external DTD Urgent
Maybe you are looking for
-
SAP GRC 10.0 ARA - Risk Analysis Job naming
Dear all, Once i trigger a risk analysis in background, a job with a very strange name (serial number) is scheduled at backend. But at Business Client i put a specific naming for hits role. It could be possible to change this backends namings? It is
-
Table TKZU1 and T.code KSAZ
Hi All could anybody let me know what is the relation between table TKZU1 and T.code KSAZ useful answers would be rewarded with points Regards Prasad
-
I downloaded Acrobat Pro, now how do I change a pdf file to word?
-
Requests to change the security question but have not yet found an email
Requests to change the security question but have not yet found an email
-
HP Mini 110-1051TU Laptop Bios Password Reset
Dear Sir I have a HP Mini 110 Notebook, but I can't changed my BIOS Password. After using ESC Key three times on Enter CURRENT Password, one error shown on the post screen. Password check failed Fatal Error...System Halted. CNU938BVPN Please Help...