Home » Developer & Programmer » Forms » Chinese characters in export xml
Chinese characters in export xml [message #266820] Tue, 11 September 2007 13:10 Go to next message
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 #267303 is a reply to message #266820] Thu, 13 September 2007 00:19 Go to previous messageGo to next message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
Why are you parsing for '>'? Don't you want 255 or less in each string irrespective of its contents?

Try this routine for outputting long lines.
   PROCEDURE my_pl (
      p_line_in   in   varchar2,
      p_magic     in   number default 80) IS
      i   pls_integer := length (p_line_in);
      j   pls_integer := 1;
   BEGIN
      WHILE j <= i
      LOOP
         dbms_output.put_line (substr (p_line_in, j, p_magic) );
         j  := j + p_magic;
      END LOOP;
   END my_pl;

David
Re: Chinese characters in export xml [message #267360 is a reply to message #267303] Thu, 13 September 2007 01:54 Go to previous messageGo to next message
ranjeethballal
Messages: 4
Registered: September 2007
Location: Pune
Junior Member
As I am creating a Xml file based on this output, I am paring for '>'. If I parse for 255 characters the xml nodes will be broken.
Re: Chinese characters in export xml [message #267609 is a reply to message #267360] Thu, 13 September 2007 20:08 Go to previous message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT 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
Previous Topic: Concurrent program unable to pick parameter from DB
Next Topic: Chinese Character Support
Goto Forum:
  


Current Time: Sun Dec 04 23:04:56 CST 2016

Total time taken to generate the page: 0.10489 seconds