保留混合内容标记内的标记之间的空白

时间:2015-01-20 04:24:56

标签: sql oracle

我们在Oracle Database 12c中使用XML DB。我们在标记之间保留空格有问题。请注意,我们已在数据库中注册了我们的架构,该架构定义了哪些标签是混合内容类型。我认为我们已经正确地完成了这项工作,因为插入不符合模式的XML会引发异常。

例如:

with
input as (
  select xmltype(
     '<content> <inline>hello</inline>  <inline>world</inline> </content>') 
  as xml_doc
  from dual)
select xmlserialize(document xml_doc no indent)
  from input

请注意,以上只是一个示例,我们正确设置了xmlns和其他根属性以引用已注册的模式。

将输出:

'<content><inline>hello</inline><inline>world</inline></content>'

我们期望输出为:

'<content> <inline>hello</inline>  <inline>world</inline> </content>'

这是Oracle的错误还是我们做错了什么? Oracle不应删除<inline>之间的空格,因为它们的父<content>是混合内容类型。

编辑:

  • 使用xmlserialize中的“no indent”,以便在XML中不引入额外的空格。此外,任何XML操作(XQuery)都会导致删除标记之间的空格。

  • xml:space =“preserve”不是一个选项,因为XML可以缩进。不应保留缩进的空格。

1 个答案:

答案 0 :(得分:1)

删除no indent会在oracle 11g中提供预期的输出,如下所示

with
input as (
  select xmltype(
     '<content> <inline>hello</inline>  <inline>world</inline> </content>') 
  as xml_doc
  from dual)
select xmlserialize(document xml_doc )
  from input

我希望这也适用于oracle 12c

相关问题