如何xml编码Oracle中的UTF8字符?

时间:2022-04-27 19:32:06

I'm using dbms_xmlgen to help generate my XML file. However it is not encoding my chr(50093) value. When I save output to a file and view the file using IE9, I get the following message from IE9

我正在使用dbms_xmlgen来帮助生成我的XML文件。但是它没有编码我的chr(50093)值。当我将输出保存到文件并使用IE9查看文件时,我从IE9收到以下消息

An invalid character was found in text content. 
Error processing resource 'file:c/temp/XML_analysis/xml_aaa.xml'.

D

Here's my sample work:

这是我的样本工作:

 set serveroutput on;
 declare 
 cursor error_item is
 with error_row as
 (select 'D' || chr(50093) || 'a' as lname from dual)
  select lname from error_row;

 line1 varchar2(100) :=  '<?xml version="1.0" encoding="UTF-8" ?>';
 line2 varchar2(100) := '<word>';
 line3 varchar2(100);
 line4 varchar2(100) := '</word>';

 begin

 open error_item;
 fetch error_item into line3;
 close error_item;
 line3 := dbms_xmlgen.convert(line3);
 dbms_output.put_line(line1);
 dbms_output.put_line(line2);
 dbms_output.put_line(line3);
 dbms_output.put_line(line4);

 end;

I've consulted this Orafaq.com site.

我已经咨询了这个Orafaq.com网站。

Questions:

  1. Why won't dbms_xmlgen.convert encode chr(50093)?

    为什么dbms_xmlgen.convert不会编码chr(50093)?

  2. Where can I learn more about how use Oracle methods to xml encode UTF8 character sets?

    在哪里可以了解更多关于如何使用Oracle方法对UTF8字符集进行xml编码?

1 个解决方案

#1


0  

Here's one way to encode your characters.

这是编码角色的一种方法。

  1. Reference sites such as FileFormat.info
  2. 参考站点,如FileFormat.info

  3. Determine your decimal encoding value. In this case, chr(50093), the Latin small letter I acute, has the decimal encoding value of 237.
  4. 确定您的十进制编码值。在这种情况下,chr(50093),拉丁文小写字母I acute,其十进制编码值为237。

  5. Prepend 237 with the &# characters and append with a ;. In Oracle, you can do this with replace() as in replace('string with characters',chr(50093),'&#237;'
  6. 使用&#字符前置237并附加;;在Oracle中,你可以使用replace()替换('string with characters',chr(50093),'í'

In this case, replace your line3 assignment statement with

在这种情况下,请将line3赋值语句替换为

line3 := replace(line3,chr(50093),'&#237;');

line3:= replace(line3,chr(50093),'í');

You should be able to read the output in an XML reader.

您应该能够在XML阅读器中读取输出。

#1


0  

Here's one way to encode your characters.

这是编码角色的一种方法。

  1. Reference sites such as FileFormat.info
  2. 参考站点,如FileFormat.info

  3. Determine your decimal encoding value. In this case, chr(50093), the Latin small letter I acute, has the decimal encoding value of 237.
  4. 确定您的十进制编码值。在这种情况下,chr(50093),拉丁文小写字母I acute,其十进制编码值为237。

  5. Prepend 237 with the &# characters and append with a ;. In Oracle, you can do this with replace() as in replace('string with characters',chr(50093),'&#237;'
  6. 使用&#字符前置237并附加;;在Oracle中,你可以使用replace()替换('string with characters',chr(50093),'í'

In this case, replace your line3 assignment statement with

在这种情况下,请将line3赋值语句替换为

line3 := replace(line3,chr(50093),'&#237;');

line3:= replace(line3,chr(50093),'í');

You should be able to read the output in an XML reader.

您应该能够在XML阅读器中读取输出。