0
. Hello,
I need to import an XML file to an oracle table. There are several examples on the internet, but none of them worked for me. In general, I’m having the error:
LPX-00210: expected '<' instead of '�'
ORA-06512: at "SYSTEM.LOAD_XML", line 16
Follows procedures:
XML example
<?xml version="1.0" encoding="UTF-8"?>
<funcionarios>
<funcionario>
<CodUsu>PRV120</CodUsu>
<NomFunci>TESTE DA SILVA</NomFunci>
<DataPosse>01/01/2001</DataPosse>
<CodGerencia>67</CodGerencia>
< --MUITO MAIS INFORMAÇÃO ... -->
</funcionario>
<funcionario>
<CodUsu>PRV121</CodUsu>
<NomFunci>TESTE DA SILVA1</NomFunci>
<DataPosse>01/12/2001</DataPosse>
<CodGerencia>67</CodGerencia>
< --MUITO MAIS INFORMAÇÃO ... -->
</funcionario>
<funcionario>
<CodUsu>PRV122</CodUsu>
<NomFunci>TESTE DA SILVA2</NomFunci>
<DataPosse>28/06/2001</DataPosse>
<CodGerencia>67</CodGerencia>
< --MUITO MAIS INFORMAÇÃO ... -->
</funcionario>
</funcionarios>
Table that will Store the XML to be read
CREATE TABLE INFO_XML
(ID NUMBER,
DATA_ALTERACAO DATE,
CONTEUDO XMLTYPE)
Importing XML into the INFO_XML table
CREATE OR REPLACE PROCEDURE load_xml ( p_id IN NUMBER,
p_filename IN VARCHAR2) AS
l_bfile BFILE := BFILENAME( 'XML_FILE', p_filename);
targetfile BFILE;
l_clob CLOB;
BEGIN
targetfile := l_bfile;
DBMS_LOB.createtemporary (l_clob, TRUE);
DBMS_LOB.fileopen(targetfile, DBMS_LOB.file_readonly);
DBMS_LOB.loadfromfile(l_clob, targetfile, DBMS_LOB.getlength(targetfile));
DBMS_LOB.fileclose(targetfile);
INSERT INTO INFO_XML (id, data_atualizacao, conteudo)
VALUES (p_id, sysdate, XMLTYPE.createXML(l_clob));
DBMS_LOB.freetemporary (l_clob);
END;
--Where XML_FILE is my directory created in ORACLE indicating the physical path of . xml
Call from Procedure load_xml
BEGIN
load_xml(p_id=>1, p_filename => 'Teste.xml');
END;
And then the mistake I mentioned:
Error
ORA-31061: XDB error: XML event error
ORA-19202: Error occurred in XML processing
In line 1 of orastream:
LPX-00210: expected '<' instead of '�'
ORA-06512: at "SYSTEM.LOAD_XML", line 16
ORA-06512: at line 2
It’s been a week since I’ve been able to progress with this task, and if anyone has any ideas, they’re welcome. After this storage, still comes the extractvalue part of the xmltype column of the table by inserting the tags strings in another table, but I find it unnecessary to post here and I could not even complete this first part.
Thank you, Abs.
Tried to open this file with another program that reads xml ?
– Motta
I tried yes Motta, I changed the whole trial and it worked. I found several errors during the construction, but it worked. I will post here the result so that, who knows, someone can use. Thank you!!
– user3701081