在Oracle XDB中转义控制字符 [英] Escaping control characters in Oracle XDB

查看:116
本文介绍了在Oracle XDB中转义控制字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Oracle XDB完全陌生,特别是使用它来从数据库表生成XML输出,并且正在开发从9i(Oracle9i企业版9.2.0.5.0版-生产版)迁移到9i版的应用程序. 11g(Oracle数据库11g企业版11.2.0.2.0版-64位生产).这是一个小的测试用例,它说明了我遇到的问题:

I'm completely new to Oracle's XDB, in particular using it to generate XML output from a database table, and am working on an application which is moving from 9i (Oracle9i Enterprise Edition Release 9.2.0.5.0 - Production) to 11g (Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production). Here's a small test case which illustrates the problem I'm having:

select xmlelement("test", test) from (select 'a' test from dual);

这行得通,并给了我

<test>a</test>

但是在11g中,如果我将'a'替换为无效字符(例如U + 0013),则会出现以下错误:

However in 11g, if I swap 'a' for an invalid character, such as U+0013 I get the following error:

ORA-31061: XDB error: special char to escaped char conversion failed.

在9i以下,同一件事可以成功运行,没有错误.

Under 9i the same thing works successfully, with no error.

显然,理想的答案是进行适当的验证,以防止控制字符进入我要转换为XML的简单字符数据中,但不幸的是,这超出了我的工作范围.

Obviously the ideal answer is to have some validation in place to prevent control characters getting into the simple character data that I'm trying to convert into XML, but unfortunately that's outside the scope of what I'm doing.

这是其他任何人都经历过的吗?如果是,我可以对我的XML生成脚本进行简单的更改吗?还是需要进行其他某种清理?或者只是在极少数情况下手动解决该问题(对于我的需求而言,这是一个非常合理的选择).

Is this something anyone else has experienced, and if so, is there a simple change I can make to my XML generating script, or do I need to do some other kind of cleansing? Or just manually fix the problem on the rare occasions that it happens (which would be a perfectly reasonable option for my needs).

推荐答案

U + 0013不是XML的有效Unicode代码点.参见例如 XML中的有效字符.所以11g正确地引发了异常.

U+0013 is not a valid unicode codepoint for XML. See e.g. Valid characters in XML. So 11g correctly raises an exception.

SQL> select xmlelement("test", unistr('a\0013b')) from dual;
ERROR:
ORA-31061: XDB error: special char to escaped char conversion failed.

no rows selected

SQL> select xmlelement("test", unistr('a\00aeb')) from dual;

XMLELEMENT("TEST",UNISTR('A\00AEB'))
--------------------------------------------------------------------------------
<test>a®b</test>

SQL> 

不知道为什么它将在9i中通过(我没有可用的功能),但这可能只是因为Oracle的实现已发展为更加符合标准和/或标准已经发展.

No idea why this will pass in 9i (I don't have that available), but that's probably simply because Oracle's implementation has evolved to be more standard conforming and/or the standard has evolved.

您的修正是正确的.

这篇关于在Oracle XDB中转义控制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆