oracle pl/sql:将 xmltype 转换为节点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1834066/
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
pl/sql: converting xmltype to node
提问by FrustratedWithFormsDesigner
I am trying to put together an XML document from several pieces. To get the data, I had several queries whose results were XMLTypes.
我试图将几个部分的 XML 文档放在一起。为了获取数据,我有几个查询的结果是 XMLTypes。
I found a function named getNodeFromFragment
in the xmldom package that looked like it could take these XMLTypes and return a DOMNode that contained them, but it doesn't seem to work.
我发现getNodeFromFragment
在 xmldom 包中命名的函数看起来可以接受这些 XMLTypes 并返回包含它们的 DOMNode,但它似乎不起作用。
Simple example here:
简单的例子在这里:
set serveroutput on;
declare
node xmldom.DOMNode;
node2 xmldom.DOMNode;
doc_node xmldom.DOMNode;
doc xmldom.DOMDocument;
el xmldom.DOMElement;
buf varchar2(1000);
begin
doc := xmldom.newDOMDocument;
el := xmldom.createElement(doc => doc, tagName => 'test');
node := xmldom.makeNode(elem => el);
xmldom.writeToBuffer(node, buf);
dbms_output.put_line('buffer: '||buf);
node := dbms_xmldom.getNodeFromFragment(XMLType('<outer><inner>soemthing</inner><inner>somethingelse</inner></outer>'));
xmldom.writeToBuffer(node, buf);
dbms_output.put_line('buffer: '||buf);
end;
/
Printing the <test/>
element works fine, but when I try to print the fragment as a node, nothing is output.
打印<test/>
元素工作正常,但是当我尝试将片段打印为节点时,没有输出任何内容。
Any tips on getNodeFromFragment?
关于 getNodeFromFragment 的任何提示?
回答by Vincent Malgrat
Hi FrustratedWithFormsDesigner,
嗨,FrustratedWithFormsDesigner,
the following will create a DOMnode object from an XMLType:
下面将从 XMLType 创建一个 DOMnode 对象:
node := dbms_xmldom.makenode(dbms_xmldom.newDOMDocument(XMLType(
'<outer><inner>soemthing</inner><inner>somethingelse</inner></outer>')));
This will output:
这将输出:
buffer: <outer>
<inner>soemthing</inner>
<inner>somethingelse</inner>
</outer>