By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,483 Members | 1,045 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,483 IT Pros & Developers. It's quick & easy.

Error parsing xml files - Help urgently needed.

P: 2
Hello,

I am running Oracle 10g R2 in our office. I created the following procedure. It is suppose to access an xml file ( family.xml). The procedure is compiled and when I try to run it, i get the following error.

SQL> execute domsample('c:\','song.xml','error.txt')
BEGIN domsample('c:\','song.xml','error.txt

*
ERROR at line 1:
ORA-31001: Invalid resource handle or path
ORA-06512: at "SYS.XDBURITYPE", line 11
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line
ORA-29280: invalid directory path
ORA-29280: invalid directory path
ORA-29280: invalid directory path
ORA-06512: at "XDB.DBMS_XMLPARSER", line 11
ORA-06512: at "BRREG.DOMSAMPLE", line 81
ORA-06512: at line 1



Source Code:
============

create or replace procedure domsample(dir varchar2, inpfile varchar2,
errfile varchar2) is
p DBMS_XMLPARSER.parser;
doc dbms_xmldom.DOMDocument;

-- prints elements in a document
procedure printElements(doc xmldom.DOMDocument) is
nl xmldom.DOMNodeList;
len number;
n dbms_xmldom.DOMNode;

begin
-- get all elements
nl := dbms_xmldom.getElementsByTagName(doc, '*');
len := dbms_xmldom.getLength(nl);

-- loop through elements
for i in 0..len-1 loop
n := dbms_xmldom.item(nl, i);
dbms_output.put(dbms_xmldom.getNodeName(n) || ' ');
end loop;

dbms_output.put_line('');
end printElements;

-- prints the attributes of each element in a document
procedure printElementAttributes(doc dbms_xmldom.DOMDocument) is
nl dbms_xmldom.DOMNodeList;
len1 number;
len2 number;
n dbms_xmldom.DOMNode;
e dbms_xmldom.DOMElement;
nnm dbms_xmldom.DOMNamedNodeMap;
attrname varchar2(100);
attrval varchar2(100);

begin

-- get all elements
nl := dbms_xmldom.getElementsByTagName(doc, '*');
len1 := dbms_xmldom.getLength(nl);

-- loop through elements
for j in 0..len1-1 loop
n := dbms_xmldom.item(nl, j);
e := dbms_xmldom.makeElement(n);
dbms_output.put_line(dbms_xmldom.getTagName(e) || ':');

-- get all attributes of element
nnm := dbms_xmldom.getAttributes(n);

if (dbms_xmldom.isNull(nnm) = FALSE) then
len2 := dbms_xmldom.getLength(nnm);

-- loop through attributes
for i in 0..len2-1 loop
n := dbms_xmldom.item(nnm, i);
attrname := dbms_xmldom.getNodeName(n);
attrval := dbms_xmldom.getNodeValue(n);
dbms_output.put(' ' || attrname || ' = ' || attrval);
end loop;
dbms_output.put_line('');
end if;
end loop;

end printElementAttributes;

begin

-- new parser
p := DBMS_XMLPARSER.newParser;

-- set some characteristics
DBMS_XMLPARSER.setValidationMode(p, FALSE);
DBMS_XMLPARSER.setErrorLog(p, dir || '/' || errfile);
DBMS_XMLPARSER.setBaseDir(p, dir);

-- parse input file
DBMS_XMLPARSER.parse(p, dir || inpfile);

-- get document
doc := DBMS_XMLPARSER.getDocument(p);

-- Print document elements
dbms_output.put('The elements are: ');
printElements(doc);

-- Print document element attributes
dbms_output.put_line('The attributes of each element are: ');
printElementAttributes(doc);

-- deal with exceptions
exception when others then null;

end domsample;


Family.xml
==========
<?xml version="1.0"?>
<!DOCTYPE SONG SYSTEM "c:\song.dtd">
<SONG>
<TITLE>Hot Cop</TITLE>
<COMPOSER>Jacques Morali</COMPOSER>
<COMPOSER>Henri Belolo</COMPOSER>
<COMPOSER>Victor Willis</COMPOSER>
<PRODUCER>Jacques Morali</PRODUCER>
<PUBLISHER>PolyGram Records</PUBLISHER>
<LENGTH>6:20</LENGTH>
<YEAR>1978</YEAR>
<ARTIST>Village People</ARTIST>
</SONG>

family.dtd
-----------

<!ELEMENT SONG (TITLE, COMPOSER+, PRODUCER*, PUBLISHER*,
LENGTH?, YEAR?, ARTIST+)>

<!ELEMENT TITLE (#PCDATA)>

<!ELEMENT COMPOSER (#PCDATA)>
<!ELEMENT PRODUCER (#PCDATA)>
<!ELEMENT PUBLISHER (#PCDATA)>
<!ELEMENT LENGTH (#PCDATA)>
<!-- This should be a four digit year like "1999",
not a two-digit year like "99" -->
<!ELEMENT YEAR (#PCDATA)>

<!ELEMENT ARTIST (#PCDATA)>



Help is needed urgently. Please solve my problem.


Thanks,

Venkat
Jun 22 '07 #1
Share this Question
Share on Google+
1 Reply


debasisdas
Expert 5K+
P: 8,127
Since this question was in Article section Moved to Oracle Forum.
Jun 22 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.