Chinese characters in export xml [message #266820] |
Tue, 11 September 2007 13:10 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
ranjeethballal
Messages: 4 Registered: September 2007 Location: Pune
|
Junior Member |
|
|
I have database containg chinese characters, while I import the data to the xml I am getting the follwing error.
-- Create DOMDocument handle for the created xml tag
xmlDoc := dbms_xmldom.newDOMDocument(xmlData);
rootNode := dbms_xmldom.item(dbms_xmldom.getElementsByTagName(xmlDoc,
'*'),
0);
-- Query for getting added tags.
xmlContext := dbms_xmlgen.newContext('SELECT CMID AS SOURCECUSTOMERID, NAME AS NAME,
KEYWORD AS KEYWORD, PGCTID AS SOURCECUSTTYPEID, DISABLED AS DELETED FROM CUSTMASTER ORDER BY CMID ASC');
--Rename the rootnode
dbms_xmlgen.setRowsetTag(xmlContext, ROOT_TAG);
--Rename the childnodes
dbms_xmlgen.setRowTag(xmlContext, SUB_NODE);
v_xml := dbms_xmlgen.getXML(xmlContext);
dbms_xmlgen.closeContext(xmlContext);
--If no rows are returned by the query,insert a blank node
IF v_xml IS NULL THEN
v_xml := '' || '<' || ROOT_TAG || '/>' || '';
END IF;
xmlData := XMLType(v_xml);
-- Create DOMDocument handle
tempXmlDoc := dbms_xmldom.newDOMDocument(xmlData);
--Get the first node of the document
tempRootNode := dbms_xmldom.item(dbms_xmldom.getElementsByTagName(tempXmlDoc,
'*'),
0);
--Append the recevied node to the original document
rootNode := dbms_xmldom.appendChild(rootNode, tempRootNode);
DBMS_OUTPUT.put_line('<?xml version="1.0" encoding="UTF-8"?>');
dbms_xmldom.writeToClob(xmlDoc, v_xml);
PKG_EXPORT_TEST.SP_PUTLINE(v_xml);
The PUTLINE procedure is as below
/**********************************************************************/
PROCEDURE SP_PUTLINE(i_Text IN CLOB) IS
cnumLineSize CONSTANT NUMBER := 255; -- Maximum size of DBMS_OUTPUT string
lstrLeft CLOB; --VARCHAR2(32767);
lstrRight CLOB; --VARCHAR2(32767);
lnumPos NUMBER;
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
IF LENGTH(i_Text) <= cnumLineSize THEN
-- Line short enough to go to PUT_LINE
DBMS_OUTPUT.PUT_LINE(i_Text);
ELSE
-- Parse till we get character '>' and put it to a line
lstrLeft := SUBSTR(i_Text, 1, INSTR(i_Text, '>'));
lstrRight := SUBSTR(i_Text, INSTR(i_Text, '>') + 1);
-- lstrLeft is small enough to send to put_line...
DBMS_OUTPUT.PUT_LINE(lstrLeft);
-- ...but lstrRight may not be. Make a recursive call to deal with it
IF (LENGTH(lstrRight) <= cnumLineSize) THEN
DBMS_OUTPUT.PUT_LINE(lstrRight);
ELSE
SP_PUTLINE(lstrRight);
END IF;
END IF;
END;
But I am getting error while I have chinese data during this PUTLINE procedure.
Upd-mod: Add 'code' tags. Please use them in future.
[Updated on: Thu, 13 September 2007 00:09] by Moderator Report message to a moderator
|
|
|
|
|
Re: Chinese characters in export xml [message #267609 is a reply to message #267360] |
Thu, 13 September 2007 20:08 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) |
![](/forum/images/custom_avatars/67467.jpg) |
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
But what if the XML stuff is longer than 255 characters? It will break dbms_output. You need to do both or use 'utl_file' or 'text_io' to do the output.
David
|
|
|