|
>Home>Learn XQuery> XQuery Tips and Tricks>Avoiding Minimized Tag Format
Print
Can I instruct XQuery to not use the minimized XML tag format?
My XQuery is this:
<root><tag></tag></root>
And the result is this:
<root><tag/></root>
How can I force the XQuery processor to stop using the minimized tag format for empty elements?
From an XML InfoSet point of view, there is no difference between
<tag/> and
<tag></ tag >, which is why the serialization specifications for XQuery 1.0 and XSLT 2.0 don't say anything about minimized tags when generating XML.
The only case in which the serialization specifications address the minimized XML tag format is when XHTML is used as the output method (to maintain compatibility with HTML browser behavior). Using DataDirect XQuery, you can change your XQuery as follows to avoid minimized XML tags:
declare option ddtek:serialize "method=xhtml";
<root><tag></tag></root>
The XQuery processor will serialize the result of that XQuery as follows:
<root><tag></tag></root>
Switching to the XHTML output method is a viable work-around when using any compliant XQuery processor. That said, using the XHTML output method can cause other, undesired side effects, so DataDirect XQuery allows you to specifically turn off the minimized tag format in result serialization using the propietary "empty-element-tags" option:
declare option ddtek:serialize "method=xml,{http://www.datadirect.com/xquery}empty-element-tags=no";
<root><tag></tag></root>
The result in this case is what you would expect:
<root><tag></tag></root>
Next Question!
How can I load XML data into my relational database?
|