示例Test.xml,内容如下
1 2 3 4 5 6 7 8 9 10 |
|
=============================================================
xml decode
使用xml decode方法将xml文件解析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
=============================================================
xml encode
FUNCTION encode_root_staff (p_obj IN OUT staff ) RETURN DBMS_XMLDOM.DOMDocument IS l_response_node DBMS_XMLDOM.DOMNode ; l_element DBMS_XMLDOM.DOMElement ; l_node DBMS_XMLDOM.DOMNode ; l_fcall_tmp DBMS_XMLDOM.DOMNode ; BEGIN XmlResponse.response_doc := DBMS_XMLDOM.newDOMDocument (); l_response_node := encode_staff (p_obj ,‘staff‘); l_element := DBMS_XMLDOM.makeElement (l_response_node ); l_node := DBMS_XMLDOM.makeNode (XmlResponse.response_doc ); l_fcall_tmp := DBMS_XMLDOM.appendChild (l_node , l_response_node ); DBMS_XMLDOM.setAttribute (l_element , ‘xmlns:ns2‘, ‘http://edb.att.com/cci/v2.0‘) ; DBMS_XMLDOM.setAttribute (l_element , ‘xmlns:ns1‘, ‘http://cio.att.com/CommonHeader/v2‘) ; RETURN XmlResponse.response_doc ; END; FUNCTION encode_staff (p_obj IN OUT staff , p_tag IN VARCHAR2 ) RETURN DBMS_XMLDOM.DOMNode IS l_element DBMS_XMLDOM.DOMElement ; l_node DBMS_XMLDOM.DOMNode ; l_fcall_tmp DBMS_XMLDOM.DOMNode ; BEGIN l_element := DBMS_XMLDOM.createElement (XmlResponse.response_doc ,p_tag ); l_node := DBMS_XMLDOM.makeNode (l_element ); IF p_obj IS NOT NULL THEN BEGIN IF p_obj .member.count >0 THEN for i in 1..p_obj .member.count loop BEGIN l_fcall_tmp := DBMS_XMLDOM.appendChild (l_node ,encode_member(p_obj .member,‘member‘)); END; end loop; END IF; END; END IF; RETURN l_node ; END; FUNCTION encode_member (p_obj IN OUT member , p_tag IN VARCHAR2 ) RETURN DBMS_XMLDOM.DOMNode IS l_element DBMS_XMLDOM.DOMElement ; l_node DBMS_XMLDOM.DOMNode ; l_fcall_tmp_1 DBMS_XMLDOM.DOMNode ; l_fcall_tmp DBMS_XMLDOM.DOMNode ; BEGIN l_element := DBMS_XMLDOM.createElement (XmlResponse.response_doc ,p_tag ); l_node := DBMS_XMLDOM.makeNode (l_element ); IF p_obj IS NOT NULL THEN BEGIN IF p_obj .name IS NOT NULL THEN BEGIN l_fcall_tmp := DBMS_XMLDOM.appendChild (l_node ,encode_string(p_obj .name,‘name‘)); END; END IF; IF p_obj .eno IS NOT NULL THEN BEGIN l_fcall_tmp := DBMS_XMLDOM.appendChild (l_node ,encode_string(p_obj .eno,‘eno‘)); END; END IF; END; END IF; RETURN l_node ; END; FUNCTION encode_string (p_obj IN VARCHAR2 , p_tag IN VARCHAR2 ) RETURN DBMS_XMLDOM.DOMNode IS l_node4 DBMS_XMLDOM.DOMNode ; l_fcall_tmp_1 DBMS_XMLDOM.DOMNode ; l_fcall_tmp DBMS_XMLDOM.DOMNode ; BEGIN l_node4 := DBMS_XMLDOM. makeNode (DBMS_XMLDOM.createElement (XmlResponse.response_doc , p_tag )); IF p_obj IS NOT NULL THEN BEGIN l_fcall_tmp := DBMS_XMLDOM.appendChild (l_node4 , DBMS_XMLDOM. makeNode (DBMS_XMLDOM. createTextNode (XmlResponse. response_doc , p_obj ))); END; ELSE BEGIN l_fcall_tmp_1 := DBMS_XMLDOM.appendChild (l_node4 , DBMS_XMLDOM. makeNode (DBMS_XMLDOM. createTextNode (XmlResponse. response_doc , ‘ ‘))); END; END IF; RETURN l_node4 ; END;