Oracle UpdateXML() 更改 XML 结构?
当我调用 UpdateXML()
时,我发现空节点正在转换为简写 XML。有没有办法防止 UpdateXML()
出现这种行为,也许是一个标志、设置或备用 XPath 表达式来告诉它保留原始结构?
/* Example 1 */
SELECT UpdateXML(xmlData, '/TEST/VALUE/text()', 'hello') as "Example 1"
FROM (SELECT XMLType('<TEST><VALUE>hi</VALUE></TEST>') as xmlData
FROM DUAL);
Example 1
---------
<TEST><VALUE>hello</VALUE></TEST>
/* Example 2 */
SELECT UpdateXML(xmlData, '/TEST/VALUE/text()', 'hello') as "Example 2"
FROM (SELECT XMLType('<TEST><VALUE></VALUE></TEST>') as xmlData
FROM DUAL);
Example 2
---------
<TEST><VALUE/></TEST>
我想看到的是:
/* Desired Output, vs. Example 2 */
SELECT UpdateXML(xmlData, '/TEST/VALUE/text()', 'hello') as "Desired Output"
FROM (SELECT XMLType('<TEST><VALUE></VALUE></TEST>') as xmlData
FROM DUAL);
Desired Output
--------------
<TEST><VALUE></VALUE></TEST>
When I call UpdateXML()
I find that empty nodes are being converted to shorthand XML. Is there a way to prevent UpdateXML()
from behaving this way, perhaps a flag or setting or alternate XPath expression to tell it to preserve the original structure?
/* Example 1 */
SELECT UpdateXML(xmlData, '/TEST/VALUE/text()', 'hello') as "Example 1"
FROM (SELECT XMLType('<TEST><VALUE>hi</VALUE></TEST>') as xmlData
FROM DUAL);
Example 1
---------
<TEST><VALUE>hello</VALUE></TEST>
/* Example 2 */
SELECT UpdateXML(xmlData, '/TEST/VALUE/text()', 'hello') as "Example 2"
FROM (SELECT XMLType('<TEST><VALUE></VALUE></TEST>') as xmlData
FROM DUAL);
Example 2
---------
<TEST><VALUE/></TEST>
What I would like to see:
/* Desired Output, vs. Example 2 */
SELECT UpdateXML(xmlData, '/TEST/VALUE/text()', 'hello') as "Desired Output"
FROM (SELECT XMLType('<TEST><VALUE></VALUE></TEST>') as xmlData
FROM DUAL);
Desired Output
--------------
<TEST><VALUE></VALUE></TEST>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以通过用临时值替换空文本,更新所有其他文本,然后用 null 替换临时值来避免该问题。
我不明白 XPath,可能有更好的方法来做到这一点,但这似乎有效:
I think you can avoid the problem by replacing empty text with a temporary value, updating all the other text, and then replacing the temporary value with a null.
I don't understand XPath, there's probably a much better way to do this, but this seems to work: