I am trying to read a xml from plsql procedure using the xmlparser package, i am getting this error
ORA-31020: The operation is not allowed, Reason: Not supported ORA-06512: at "XDB.DBMS_XMLPARSER", line 395 ORA-06512: at "SYS.DOMSAMPLE", line 75 ORA-06512: at line 2
DOMSAMPLE
is my procedure name, and no statements are there at line number 75, and next line contains p := xmlparser.newParser
.
Can somebody please help me in resolving this problem. Or suggest a simple way to read xml in plsql.
You have provided scant few details about what you are actually doing, so I'm afraid I can only guess.
I cannot reproduce the error message you have, but I have only tried a few things. Perhaps you're calling the Oracle XML APIs incorrectly? Perhaps there's something odd about the XML document you're attempting to parse? I'm afraid I have no idea, since you haven't given us the source of your
DOMSAMPLE
procedure nor the XML document you're attempting to parse.I cannot believe line 75 of your procedure is a blank line. Is this line 75 of the procedure, or line 75 of the file that contains the procedure?
Here's an example using
DBMS_XMLPARSER
andDBMS_XMLDOM
. It merely reads out the name of the root element of the XML string given:When I run this it gives me the output
Tag name is thisIsATest
.As for simpler ways to read XML, there's one in a question I answered earlier. I don't know whether that will help you, because I know very little about what you're trying to achieve.
Finally, please don't create objects in the
SYS
schema.EDIT: in your comment, you mention that you're using
dbms_xmlparser.parse
instead ofdbms_xmlparser.parseBuffer
. I had a play withdbms_xmlparser.parse
and hit the same 'invalid resource handle or path name' error several times before finally finding something that worked. Below is what I managed to get working; there may well be a better solution to what you want than this.Before you can do any file I/O with Oracle, and that appears to include using
dbms_xmlparser.parse
, you must first create an Oracle 'directory'. Directories in Oracle correspond to directories on the filesystem. Note that this is the filesystem on the machine on which the Oracle database runs. If the XML file isn't on the same filesystem (e.g. the Oracle database is on a server and your XML file is on your development PC), you won't be able to usedbms_xmlparser.parse
, unless you first transfer this file to a directory on the database server's filesystem.I'll start by creating a Oracle directory corresponding to a directory on my filesystem:
I'm using Linux here. If you're using Windows, feel free to reverse the direction of the slashes.
Before we go any further, let's take a quick look at the XML file we'll read in:
In SQL*Plus,
host
sends the rest of the line to the shell, orcmd.exe
on Windows. On Windows you'd also usetype
instead ofcat
.Finally, here's a PL/SQL block that reads this XML file:
The only difference between this block and the one further up is that the line that called
dbms_xmlparser.parseBuffer
has been replaced with two lines. The first of these two lines callsdbms_xmlparser.setBaseDir
to set a base directory for the parser, and the second callsdbms_xmlparser.parse
using a filename relative to this directory.EDIT 2: Your code, which wasn't working quite as you had hoped, and which you edited into my answer, is as follows:
This apparently was returning all the values as null, as suggested by the last of the three comments.
To quote a previous answer of mine on a similar question:
So, try replacing the line
with