我正在编写PL / SQL程序,用于从Internet下载XML文件,解析它们并在Oracle数据库中存储值。我有一个大型XML文件,其中包含大量较小XML的链接。大约有6253个文件需要解析。我有函数,它将XML文件下载到CLOB并将数据保存到XmlType中。该值返回到程序中并进一步处理。这是功能:
create or replace function get_xml_by_url
( v_url VARCHAR2
)
RETURN XMLType
AS
req SYS.UTL_HTTP.REQ;
resp SYS.UTL_HTTP.RESP;
xmlClob CLOB;
x XmlType;
l_offset number := 1;
value VARCHAR2(3999); -- URL to post to
BEGIN
BEGIN
UTL_HTTP.SET_PROXY('http://10.1.250.233:8080');
req := UTL_HTTP.BEGIN_REQUEST (url=> v_url, method => 'GET');
UTL_HTTP.SET_HEADER(req, 'User-Agent', 'Mozilla/4.0');
UTL_HTTP.SET_HEADER
( r => req
, name => 'Content-Type'
, value => 'text/xml;charset=UTF-8'
);
resp := UTL_HTTP.GET_RESPONSE(req);
DBMS_LOB.CREATETEMPORARY(xmlClob, true);
-- Loading first line
UTL_HTTP.READ_LINE(resp,value,false);
DBMS_LOB.WRITE(xmlClob,length(value),l_offset,value);
l_offset := l_offset + length(value);
-- Loading and adjusting second line
UTL_HTTP.READ_LINE(resp,value,true);
value := rtrim(value,'xmlns="http://seznam.gov.cz/ovm/datafile/seznamovm/v1">')||'>';
DBMS_LOB.WRITE(xmlClob, length(value), l_offset,value);
l_offset := l_offset + length(value);
-- Filling CLOB
LOOP
UTL_HTTP.READ_LINE(resp,value,false);
DBMS_LOB.WRITE(xmlClob,length(value),l_offset,value);
l_offset := l_offset + length(value);
END LOOP;
EXCEPTION
when UTL_HTTP.END_OF_BODY
then
UTL_HTTP.END_RESPONSE(resp);
when others
then
utl_http.end_response(resp);
END;
x := XMLType.createXML(xmlClob);
DBMS_LOB.FREETEMPORARY(xmlClob);
RETURN x;
END;
我在所有6.253 XMl文件的循环中调用此函数,并且每次出现错误,但每次都在不同的文件中,并且当我再次运行脚本时只针对一个引发错误的XML文件,它运行良好。我认为这个问题与记忆有关,但我不知道它为什么会发生这种情况
我收到了以下错误:
Error report:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00249: invalid external ID declaration
Error at line 1
ORA-06512: in "SYS.XMLTYPE", line 5
ORA-06512: in "GET_XML_BY_URL", line 47
ORA-06512: in line 29
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
GET_XML_BY_URL是给出描述的功能的名称。有没有人有这样的问题呢? 最好的问候,Michal