我已根据给定的输入参数“Table_Name”创建了用于生成XML文件的存储过程。
存储过程是:
create or replace
PROCEDURE Export_In_XML11JUNE
(
V_TABLE_NAME1 IN varchar2,
v_FLAG OUT NUMBER
)
AS
BEGIN
----- Export table data
DECLARE
v_file UTL_FILE.file_type;
qryCtx DBMS_XMLGEN.ctxHandle;
result CLOB;
v_FILENAME varchar2(50);
xt_data xmltype;
v_ctx dbms_xmlgen.ctxHandle;
rc_data sys_refcursor;
V_TABLE_NAME varchar2(50);
cnt number :=0;
BEGIN
V_TABLE_NAME :=trim(UPPER(V_TABLE_NAME1));
v_file := UTL_FILE.fopen('MYXML',V_TABLE_NAME ||'.xml', 'W');
OPEN rc_data FOR
'select * FROM '||V_TABLE_NAME||' ORDER BY 1' ;
v_ctx := dbms_xmlgen.newContext (rc_data);
DBMS_XMLGEN.USEITEMTAGSFORCOLL (v_ctx);
DBMS_XMLGEN.SETNULLHANDLING(v_ctx, 1);
DBMS_XMLGEN.setrowsettag(v_ctx,'root');
DBMS_XMLGEN.setrowtag(v_ctx,V_TABLE_NAME );
result:= DBMS_XMLGEN.getXML(v_ctx);
result := REPLACE( result, '<?xml version="1.0"?>','<?xml version="1.0" encoding="UTF-8" standalone ="yes"?>');
-- DBMS_XMLGEN.RESTARTQUERY (v_ctx);
-- xt_data := dbms_xmlgen.getXMLType (v_ctx);
dbms_xslprocessor.clob2file( result, 'MYXML', ''||V_TABLE_NAME||'.xml',871);
dbms_xmlgen.closeContext (v_ctx);
v_FLAG := 1;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
dbms_xmlgen.closeContext (v_ctx);
v_FLAG := 0;
END ;
END Export_In_XML11JUNE;
并以此格式返回XML:
<?xml version="1.0" encoding="UTF-8" standalone ="yes"?>
<root xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">
<AGNCY>
<AGENCYID>0000</AGENCYID>
<NAME>ABC</NAME>
<MARKDELETED>0</MARKDELETED>
</AGNCY>
<AGNCY>
....
....
我需要XML out put
<?xml version="1.0" encoding="UTF-8" standalone ="yes"?>
<root xsi:noNamespaceSchemaLocation="c:\data\Agency.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">
<AGNCY>
<AGENCYID>0000</AGENCYID>
<NAME>Caltrans</NAME>
<MARKDELETED>0</MARKDELETED>
</AGNCY>
<AGNCY>
....
....
....
我想要root标签中的xsi:noNamespaceSchemaLocation =“c:\ data \ table_Name.xsd”行。
此处table_Name
是存储过程的输入参数。
我试过但没找到任何解决方案。请指导我。