如何在 Oracle DB 中禁用 XML DTD 验证?

发布于 2024-07-15 02:52:01 字数 389 浏览 6 评论 0原文

我在查询的选择部分中使用以下语句:

extract(XMLTYPE(doc.payload),'/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/DOCUMENTID')

如果 doc.payload 包含 XML 而没有 DTD 声明,则效果很好,但会引发当存在 DTD 声明时出现错误,因为 Oracle 尝试验证文档但找不到 DTD

如何禁用此查询的 XML 验证? 我不想在这件事上影响我的会话设置或全局系统设置。

I am using following statement in select portion of the query:

extract(XMLTYPE(doc.payload),'/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/DOCUMENTID')

it works well if the doc.payload contains XML without DTD declaration, but raises an error when DTD declaration is present as Oracle tries to validate the document but cannot find the DTD.

How to disable the XML validation for this query? I don't want to affect my session setting nor global system setting in this matter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷离° 2024-07-22 02:52:01

您可以在创建 XMLTYPE 时关闭验证,构造函数签名如下所示:

XMLType(
   xmlData IN varchar2,
   schema IN varchar2 := NULL,
   validated IN number := 0,
   wellformed IN number := 0)

因此您可以像这样禁用验证:

   extract(XMLTYPE(doc.payload, NULL, 1, 1),
'/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/DOCUMENTID')

但是,如果您有外部 DTD 引用,这对您没有帮助。 它仍然会尝试加载它。 是否无法将 DTD 文件上传到 XMLDB 存储库? 这将是最简单的解决方案。 如果没有,就没有“好的”解决方案,您必须在创建 XMLTYPE 之前删除 DTD 引用:

   extract(XMLTYPE(REGEXP_REPLACE(doc.payload, '<!DOCTYPE[^<]*>', '')),
'/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/DOCUMENTID')

You can turn off validation when you create an XMLTYPE, constructor signature looks like this:

XMLType(
   xmlData IN varchar2,
   schema IN varchar2 := NULL,
   validated IN number := 0,
   wellformed IN number := 0)

So you can disable validation like this:

   extract(XMLTYPE(doc.payload, NULL, 1, 1),
'/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/DOCUMENTID')

This will not help you though, if you have an external DTD reference. It'd still try to load it. Is it not possible to upload the DTD file into the XMLDB repository? That would be the simplest solution. If not, there is no 'nice' solution, you have to get rid of the DTD reference before creating the XMLTYPE:

   extract(XMLTYPE(REGEXP_REPLACE(doc.payload, '<!DOCTYPE[^<]*>', '')),
'/SHOW_SHIPMENT_005/DATAAREA/SHOW_SHIPMENT/SHIPMENT/SHIPITEM/DOCUMNTREF/DOCUMENTID')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文