Improve company productivity with a Business Account.Sign Up


ORA-31011: XML parsing failed

Posted on 2008-10-08
Medium Priority
Last Modified: 2013-11-18
Hi All,
Thanks in advance for help me in this solution.
Sample xslt code in merging two xml files are working on 9i but not on 10g. Can you help me on this..
Here is code..
********************PLSQL code**************
-- XML Parser for PL/SQL Example 5: PL/SQL -- xslsample.sql
-- This file demonstates a simple use of XSL-T transformation capabilities.
-- The XML and XSL files that are given to the application are parsed,
-- the transformation specified is applied and the transformed document is
-- written to a specified result file.
-- It shows you how to set the parser options.

set serveroutput on;
create or replace procedure xslsample(dir varchar2, xmlfile varchar2,
                                      xslfile varchar2, resfile varchar2,
                                      errfile varchar2) is
p xmlparser.Parser;
xmldoc xmldom.DOMDocument;
xmldocnode xmldom.DOMNode;
proc xslprocessor.Processor;
ss xslprocessor.Stylesheet;
xsldoc xmldom.DOMDocument;
docfrag xmldom.DOMDocumentFragment;
docfragnode xmldom.DOMNode;
xslelem xmldom.DOMElement;
nspace varchar2(50);
xslcmds xmldom.DOMNodeList;


-- new parser
   p := xmlparser.newParser;

-- set some characteristics
   xmlparser.setValidationMode(p, FALSE);
-- xmlparser.setErrorLog(p, dir||'/'||errfile);
   xmlparser.setPreserveWhiteSpace(p, TRUE);
   xmlparser.setBaseDir(p, dir);
dbms_output.put_line('step-5' ||dir);
-- parse xml file
   dbms_output.put_line('Parsing XML document ' || dir || '/'|| xmlfile);
   xmlparser.parse(p,dir || '/'|| xmlfile);
-- get document
   xmldoc := xmlparser.getDocument(p);
-- parse xsl file
   dbms_output.put_line('Parsing XSL document '|| dir || '/'|| xslfile);
   xmlparser.parse(p,dir || '/'|| xslfile);
-- get document
   xsldoc := xmlparser.getDocument(p);

   xslelem := xmldom.getDocumentElement(xsldoc);
   nspace := xmldom.getNamespace(xslelem);

-- print out some information about the stylesheet
   dbms_output.put_line('XSL Root element information');
   dbms_output.put_line('Qualified Name: ' ||
   dbms_output.put_line('Local Name: ' ||
   dbms_output.put_line('Namespace: ' || nspace);
   dbms_output.put_line('Expanded Name: ' ||

   xslcmds := xmldom.getChildrenByTagName(xslelem, '*', nspace);
   dbms_output.put_line('A total of ' || xmldom.getLength(xslcmds) ||
                        ' XSL instructions were found in the stylesheet');
-- make stylesheet
   ss := xslprocessor.newStylesheet(xsldoc, dir || '/'|| xslfile);

-- process xsl
   proc := xslprocessor.newProcessor;
   xslprocessor.showWarnings(proc, true);
-- xslprocessor.setErrorLog(proc, dir || '/'|| errfile);

   dbms_output.put_line('Processing XSL stylesheet');
   docfrag := xslprocessor.processXSL(proc, ss, xmldoc);
   docfragnode := xmldom.makeNode(docfrag);
   dbms_output.put_line('Writing transformed document');
  xmldom.writeToFile(docfragnode, dir || '/'|| resfile);

-- deal with exceptions

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');

   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');

end xslsample;
show errors;
I have attached two xml files and one xsl file

Question by:rajsan1
  • 11
  • 9
LVL 27

Expert Comment

ID: 22678463
>>I have attached two xml files and one xsl file

But somehow I don't see them :(

Author Comment

ID: 22678702
Oops!.. I have attached and also added the code..
I used to this script to run...
execute xslsample('/opt/timpact/Connector/Vendors/Perceptive/incoming', '152.xml', 'ptv_stage.xsl','family.out', 'errors.txt');

Open in new window

LVL 27

Expert Comment

ID: 22678953
the 152.xml is OK, but since I don't have the DTD it might not validate against it.
patvist.xml is also OK
The xslt seems OK also.

Now I don't have the relevant Oracle systems, but I do get an error on

      <xsl:variable name="patVisitLD" select="document('patVisitLookup.xml')"/>

in the XSLT, since it can't find the document. Before I start fiddling around with paths and such can you verify that this is not the problem (differences in file store paths between the two versions)?

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.


Author Comment

ID: 22679237
Thanks for the information. Yes the problems is with the external file in 10g but it works on 9i

Sorry I forgot to attache the dtd file..
LVL 27

Expert Comment

ID: 22679293
You might try changing the filename of the external file in the XSL to an absolute name, so that the system can find it.

I don't think that your DTD will show that the XML is invalid. I don't think that's the problem. Even if it is, you can simply comment out the DTD declaration, as I did when I tested the XML.

Author Comment

ID: 22679405
Is it working for you on 10g?
LVL 27

Expert Comment

ID: 22679435
As I said before I do not have an Oracle system on which I can try it out.

Did you follow up the path idea?

Author Comment

ID: 22679455
yes, I did the code works fine on 9i but not on 10g
LVL 27

Expert Comment

ID: 22679697
Hmm, one last idea. Can you post the files ziped up instead of copying them into the thread. There may be an encoding problem in the first file which in 10g is checked.

Author Comment

ID: 22679851
Thanks for your quick response.. And thanks for helping me..

The system is not allowing to attach the files...Is it possible to send me your email address.

Anyway I have attached the files. Let me know if you received the files..

LVL 27

Expert Comment

ID: 22679995
My e-mail address is in my E-E profile. Unfortunately it is now quite late here and I shall be going home soon, so send them and I'll have a look tomorrow.

Author Comment

ID: 22685432
I have sent attachment through your email. Could you please look into the code and let me know where I need to change. Thanks for help me on this.
LVL 27

Expert Comment

ID: 22686085
OK, I have received your zip file, unpacked the data and examined the files in detail. They do not contain any illegal characters which would have made a parsing error.

I did try to validate the XML data against the DTD, but the DTD file starts with an XML header and that goes wrong with the Microsoft parser. It just might be the case that the 10g version by default does a validation via the DTD which it can't compile, since it has an XML header. Try looking for an option to turn off validation on parse in 10g.

Author Comment

ID: 22688759
The code is working fine when I commented external file in the xslt on 10g.

I turn off the validation again i get same error...for accessing external file...

ERROR at line 1:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 392
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 418
ORA-06512: at "PCONNECT.XSLSAMPLE", line 70
ORA-06512: at line 1
LVL 27

Expert Comment

ID: 22702113
Which either imples it can't find the file or that something in the file is wrong. I have tested the file, so I believe it is the first case. What you could do is to deliberately make a syntax error in that external file and see if the parser reports exactly that error.

PS:Is the Oracle error message complete? It hasn't given a source text reference (usally a LXxxx message)

Author Comment

ID: 22702991
I have changed the external file... here is error message I got it
ERROR at line 1:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00261: invalid URL ÿÿÿÿÿÿdh
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 161
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 187
ORA-06512: at "SYSTEM.XSLSAMPLE", line 78
ORA-06512: at line 1
LVL 27

Expert Comment

ID: 22703304
So it definitely seems to be the content of the patVisitLookup.xml file.
I have checked this file and I can find nothing wrong with it.

However, the document function must return a node set and *perhaps* the <?xml...?> line at the front of the file may be causing the error. Try removing it.

Author Comment

ID: 22703408
Somehow I think... it can't find the file. The documents seems ok.
I get the above error of  the invalid URL. Do you have an idea on how to check on this error? It seems to be unable to find the document whether it is placed on the unix server, NT or database.
LVL 27

Accepted Solution

BigRat earned 1500 total points
ID: 22703627
According to the W3C model, the XSL file has a document base and the included file should use the document base of the "parent" to make up the path name. I'd suggest that you write out the FULL path name (eg: c:\...\...\...).
LVL 27

Expert Comment

ID: 22884621
I'm sorry I don't understand what you want me to do?

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question