Forum Stats

  • 3,759,061 Users
  • 2,251,495 Discussions
  • 7,870,477 Comments

Discussions

Retain whitespace between tags within mixed-content tags

2843402
2843402 Member Posts: 2
edited Jan 21, 2015 5:45AM in SQL & PL/SQL

We are using XML DB in Oracle Database 12c. We have a problem retaining whitespaces between tags. Note that we have already registered our schema in the database that defines which tags are mixed-content type. I think we have done this properly since inserting XMLs not conforming to the schema will raise an exception.

For example:

<span class="kwd">with</span><span class="pln"> input </span><span class="kwd">as</span><span class="pln"> </span><span class="pun">(</span><span class="pln"> </span><span class="kwd">select</span><span class="pln"> xmltype</span><span class="pun">(</span><span class="pln"> </span><span class="str">'<content> <inline>hello</inline> <inline>world</inline> </content>'</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">as</span><span class="pln"> xml_doc </span><span class="kwd">from</span><span class="pln"> dual</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">select</span><span class="pln"> xmlserialize</span><span class="pun">(</span><span class="pln">document xml_doc no indent</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> input</span>

Note that the above is an example only, we properly set xmlns and other root attributes properly to refer to registered schemas.

Will output:

<span class="str">'<content><inline>hello</inline><inline>world</inline></content>'</span>

Whereas we expected the output to be:

<span class="str">'<content> <inline>hello</inline> <inline>world</inline> </content>'</span>

Is this an Oracle bug or are we doing something wrong? Oracle should not remove the whitespaces between <inline> since their parent <content> is of mixed content-type.

Note:

  • "no indent" in xmlserialize is used so that no additional whitespace is introduced in the XML. And besides, any XML operation (XQuery) results to removal of whitespaces between tags.
  • xml:space="preserve" is not an option since XML may be indented. Indentation whitespaces should not be preserved.
Tagged:

Answers

This discussion has been closed.