Oracle:如何使用 XMLElement() 在特定命名空间中创建元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/437670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle: How to create an element in a specific namespace with XMLElement()
提问by avernet
In Oracle, you can use the XMLElement()function to create an element, as in:
在 Oracle 中,您可以使用XMLElement()函数来创建元素,如下所示:
XMLElement('name', 'John')
But how to create an element in a specific namespace? For instance, how to create the following element:
但是如何在特定的命名空间中创建元素呢?例如,如何创建以下元素:
<my:name xmlns:my="http://www.example.com/my">John</my:name>
采纳答案by avernet
Instead of XMLElement()
use:
而不是XMLElement()
使用:
XMLType('<my:name xmlns:my="http://www.example.com/my">John</my:name>')
Yes, it is that simple.
是的,就是这么简单。
回答by Craig
You can also use XMLAttribute:
您还可以使用 XMLAttribute:
select xmlelement("my:name",
xmlattributes('http://www.example.com/my' as "xmlns:my"),
'John'
)
from dual
Will return:
将返回:
<my:name xmlns:my="http://www.example.com/my">John</my:name>
You can also check that Oracle recognizes this as a namespace (other than you are not getting a namespace prefix "my" is not declarederror):
您还可以检查 Oracle 是否将其识别为命名空间(除了您没有获得命名空间前缀“my”未声明错误):
select xmlelement("my:name",
xmlattributes('http://www.example.com/my' as "xmlns:my"),
'John'
).getnamespace()
from dual
Will return:
将返回:
http://www.example.com/my