Solved

ORA-31011: XML parsing failed

Posted on 2008-10-08
20
3,602 Views
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;

begin

-- new parser
   p := xmlparser.newParser;

-- set some characteristics
dbms_output.put_line('step-1');
   xmlparser.setValidationMode(p, FALSE);
dbms_output.put_line('step-2'||dir||'/'||errfile);
-- xmlparser.setErrorLog(p, dir||'/'||errfile);
dbms_output.put_line('step-3');
   xmlparser.setPreserveWhiteSpace(p, TRUE);
dbms_output.put_line('step-4');
   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);
dbms_output.put_line('step-6');
-- get document
   xmldoc := xmlparser.getDocument(p);
dbms_output.put_line('step-7');
-- parse xsl file
   dbms_output.put_line('Parsing XSL document '|| dir || '/'|| xslfile);
   xmlparser.parse(p,dir || '/'|| xslfile);
dbms_output.put_line('step-8');
-- 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: ' ||
                         xmldom.getQualifiedName(xslelem));
   dbms_output.put_line('Local Name: ' ||
                         xmldom.getLocalName(xslelem));
   dbms_output.put_line('Namespace: ' || nspace);
   dbms_output.put_line('Expanded Name: ' ||
                         xmldom.getExpandedName(xslelem));

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

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

0
Comment
Question by:rajsan1
  • 11
  • 9
20 Comments
 
LVL 27

Expert Comment

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

But somehow I don't see them :(
0
 

Author Comment

by:rajsan1
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

0
 
LVL 27

Expert Comment

by:BigRat
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)?


0
 

Author Comment

by:rajsan1
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..
0
 
LVL 27

Expert Comment

by:BigRat
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.
0
 

Author Comment

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

Expert Comment

by:BigRat
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?
0
 

Author Comment

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

Expert Comment

by:BigRat
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.
0
 

Author Comment

by:rajsan1
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..

Thanks
Raj
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 27

Expert Comment

by:BigRat
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.
0
 

Author Comment

by:rajsan1
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.
0
 
LVL 27

Expert Comment

by:BigRat
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.
0
 

Author Comment

by:rajsan1
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
0
 
LVL 27

Expert Comment

by:BigRat
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)
0
 

Author Comment

by:rajsan1
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
0
 
LVL 27

Expert Comment

by:BigRat
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.
0
 

Author Comment

by:rajsan1
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.
0
 
LVL 27

Accepted Solution

by:
BigRat earned 500 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:\...\...\...).
0
 
LVL 27

Expert Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now