从oracle clob解析xml时发生错误字符转义

从oracle clob解析xml时发生错误字符转义,xml,oracle,Xml,Oracle,我有这样一个简单的表: MyTable ( id number(10), configuration CLOB) 在windows上运行的oracle 11g(11.2.0.1.0)中 下面是我的代码: declare vconfiguration clob; vxml xmltype; vstring varchar(255); begin select configuration into vconfiguration from mytable where id=1;

我有这样一个简单的表:

MyTable ( id number(10), configuration CLOB)
在windows上运行的oracle 11g(11.2.0.1.0)中

下面是我的代码:

declare
vconfiguration clob;

vxml xmltype;
vstring varchar(255);
begin
    select configuration into vconfiguration from mytable where id=1;

    vxml := xmltype(vconfiguration);

    dbms_output.put_line(vconfiguration);

    vstring := vxml.extract('/SmtpConfiguration/From/text()','xmlns="http://www.blabla.com/Drivers/Smtp"').getStringVal();
    dbms_output.put_line('From=' || vstring);
end;
以下是输出:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SmtpConfiguration
xmlns="http://www.blabla.com/Drivers/Smtp">

<From>"sender1@company.com"</From>
    <MultiRecipients>TO</MultiRecipients>

<ServerAddress>smtp_server1</ServerAddress>
    <ServerPort>25</ServerPort>

<UseAuthentication>false</UseAuthentication>

<UseSSL>false</UseSSL>
</SmtpConfiguration>

From=&quot;sender1@company.com&quot;

"sender1@company.com"
到
smtp_服务器1
25
假的
假的
From=”sender1@company.com"
我想做的是像
插入另一个表(from)值(vstring)

如何使用正确的“而不是”来获取From标记的值?

您可以改用:

SQL函数
extractValue
XMLType
方法
getStringVal()
对实体编码的处理不同。函数
extractValue
取消对任何编码实体的扫描;方法
getStringVal()
返回实体编码完整的数据

因此,您可以不调用extract,而是执行此操作,这需要一个查询,因为它不是PL/SQL本机识别的函数:

select extractValue(vxml, '/SmtpConfiguration/From/text()',
  'xmlns="http://www.blabla.com/Drivers/Smtp"')
into vstring
from dual;
dbms_output.put_line('From=' || vstring);
这就产生了输出:

From="sender1@company.com"
你也可以用它

声明
vconfiguration clob;
vxml-xmltype;
vstring varchar(255);
开始
vconfiguration:='
"sender1@company.com"
到
smtp_服务器1
25
假的
假的
';
vxml:=xmltype(vconfiguration);
DBMS_OUTPUT.put_line(vconfiguration);
vstring:=
DBMS_XMLGEN.CONVERT(
vxml.EXTRACT(“/SmtpConfiguration/From/text()”,“xmlns=”http://www.blabla.com/Drivers/Smtp“')。getStringVal()
,DBMS_XMLGEN.ENTITY_DECODE);
DBMS_OUTPUT.put_line('From='|| vstring);
结束;
declare
  vconfiguration clob;

  vxml           xmltype;
  vstring        varchar (255);
begin

  vconfiguration := '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <SmtpConfiguration
    xmlns="http://www.blabla.com/Drivers/Smtp">
    <From>"sender1@company.com"</From>
        <MultiRecipients>TO</MultiRecipients>
    <ServerAddress>smtp_server1</ServerAddress>
        <ServerPort>25</ServerPort>
    <UseAuthentication>false</UseAuthentication>
    <UseSSL>false</UseSSL>
    </SmtpConfiguration>';

  vxml := xmltype (vconfiguration);
  DBMS_OUTPUT.put_line (vconfiguration);

  vstring :=
    DBMS_XMLGEN.CONVERT (
      vxml.EXTRACT ('/SmtpConfiguration/From/text()','xmlns="http://www.blabla.com/Drivers/Smtp"').getStringVal ()
     ,DBMS_XMLGEN.ENTITY_DECODE);
  DBMS_OUTPUT.put_line ('From=' || vstring);
end;