How do I Generate Valid XML from pl/sql [message #156791] |
Fri, 27 January 2006 16:26 |
mangoMan
Messages: 1 Registered: January 2006
|
Junior Member |
|
|
Hi,
A new-bee here. I want to know how to generate a valid xml document. I have a schema which by the way includes two other schemas. This is the code I am using but I don't know how to make sure that I insert the child nodes in the right sequence. Any sample code that you guys can provide would be greatly appreciated.
FUNCTION GenerateOrderXML(
o_ErrorCode OUT NUMBER,
o_ErrorText OUT VARCHAR2,
i_AccountID IN document.documentid%TYPE,
i_OrderName IN VARCHAR2) RETURN XMLType
IS
v_Doc XMLDOM.DOMDocument;
v_MainNode XMLDOM.DOMNode;
v_RootElmt XMLDOM.DOMElement;
v_RootNode XMLDOM.DOMNode;
v_TmpCLOB CLOB := ' ';
CURSOR CURSOR_SERVOBJ
IS
SELECT XMLTAG, XMLVALUE FROM SERVICEOBJECT
WHERE SERVICEOBJECT.ID < 500
ORDER BY SEQUENCE;
-- Create xml root element
v_Doc := XMLDOM.newDOMDocument;
v_MainNode := XMLDOM.makeNode(v_Doc);
v_RootElmt := XMLDOM.createElement(v_Doc, 'OrderRequest');
v_RootNode := XMLDOM.appendChild(v_MainNode, XMLDOM.makeNode(v_RootElmt));
-- Add OrderName, OrderType
AddChild(v_Doc, v_RootNode, 'orderName', i_OrderName);
AddChild(v_Doc, v_RootNode, 'orderType', 'NA');
-- Add all attributes
FOR v_NameValue IN CURSOR_SERVOBJ
LOOP
AddChild(v_Doc, v_RootNode, v_NameValue.XMLTAG, v_NameValue.XMLVALUE);
END LOOP;
-- XMLDOM.writeToBuffer(v_Doc, v_Buffer);
XMLDOM.writeToClob(v_Doc, v_TmpCLOB);
o_ErrorCode := 0;
RETURN XMLType.createXML(v_TmpClob);
END;
|
|
|