CREATE OR REPLACE FUNCTION idAttributeOfDocElements(xmldoc in CLOB)
return varchar2
is
theXmlDoc xmldom.DOMDocument;
n1 xmldom.DOMNodeList;
len1 number(10);
len2 number(10);
v1 xmldom.DOMNode;
n2 xmldom.DOMNodeList;
attn xmldom.DOMNode;
vretuval varchar2(1000):='';
XMLParseError EXCEPTION;
PRAGMA EXCEPTION_INIT( XMLParseError, -20100 );
-- Local parse function keeps code cleaner. Return NULL if parse fails
FUNCTION parse(xml CLOB) RETURN xmldom.DOMDocument IS
retDoc xmldom.DOMDocument;
parser xmlparser.Parser;
BEGIN
parser := xmlparser.newParser;
xmlparser.ParseCLOB(parser,xml);
retDoc := xmlparser.getDocument(parser);
xmlparser.freeParser(parser);
RETURN retdoc;
EXCEPTION
--If the parse fails, we''ll jump here.
WHEN XMLParseError THEN
xmlparser.freeParser(parser);
dbms_output.put_line('errors');
RETURN retdoc;
END;BEGIN
-- Parse the xml document passed in the CLOB argument
theXmlDoc := parse(xmldoc);
-- If the XML document returned is not NULL...
IF NOT xmldom.IsNull(theXmlDoc) THEN
-- Get the outermost enclosing element (aka "Document Element")
--theDocElt := xmldom.getDocumentElement(theXmlDoc);
-- Get the value of the document element's "id" attribute
n1:= xmldom.getElementsByTagName(theXmlDoc, 'doc');
len1 := xmldom.getLength(n1);
dbms_output.put_line('节点的数量:'||len1);
--获得<HB></HB>节点的数量
for i in 0 .. len1 - 1 loop
--获得节点
v1 := xmldom.item(n1, i);
--获得该节点下所有的子节点
n2 := xmldom.getChildNodes(v1);
--获得子节点的数量
len2 := xmldom.getLength(n2);
dbms_output.put_line('第-------------< '|| (i+1)|| ' >---------节点');
for j in 0..len2-1 loop
--dbms_output.put_line(len2);
attn:=xmldom.item(n2,j);
dbms_output.put_line(xmldom.getNodeValue(xmldom.getFirstChild(attn.id))||':'||xmldom.getNodeValue(xmldom.getFirstChild(attn))); end loop;
end loop;
-- Free the memory used by the parsed XML document
xmldom.freeDocument(theXmlDoc); RETURN vretuval;
ELSE
RETURN vretuval;
END IF;
END;
代码不是我写的,求大神说一下怎么去获取节点属性的值
return varchar2
is
theXmlDoc xmldom.DOMDocument;
n1 xmldom.DOMNodeList;
len1 number(10);
len2 number(10);
v1 xmldom.DOMNode;
n2 xmldom.DOMNodeList;
attn xmldom.DOMNode;
vretuval varchar2(1000):='';
XMLParseError EXCEPTION;
PRAGMA EXCEPTION_INIT( XMLParseError, -20100 );
-- Local parse function keeps code cleaner. Return NULL if parse fails
FUNCTION parse(xml CLOB) RETURN xmldom.DOMDocument IS
retDoc xmldom.DOMDocument;
parser xmlparser.Parser;
BEGIN
parser := xmlparser.newParser;
xmlparser.ParseCLOB(parser,xml);
retDoc := xmlparser.getDocument(parser);
xmlparser.freeParser(parser);
RETURN retdoc;
EXCEPTION
--If the parse fails, we''ll jump here.
WHEN XMLParseError THEN
xmlparser.freeParser(parser);
dbms_output.put_line('errors');
RETURN retdoc;
END;BEGIN
-- Parse the xml document passed in the CLOB argument
theXmlDoc := parse(xmldoc);
-- If the XML document returned is not NULL...
IF NOT xmldom.IsNull(theXmlDoc) THEN
-- Get the outermost enclosing element (aka "Document Element")
--theDocElt := xmldom.getDocumentElement(theXmlDoc);
-- Get the value of the document element's "id" attribute
n1:= xmldom.getElementsByTagName(theXmlDoc, 'doc');
len1 := xmldom.getLength(n1);
dbms_output.put_line('节点的数量:'||len1);
--获得<HB></HB>节点的数量
for i in 0 .. len1 - 1 loop
--获得节点
v1 := xmldom.item(n1, i);
--获得该节点下所有的子节点
n2 := xmldom.getChildNodes(v1);
--获得子节点的数量
len2 := xmldom.getLength(n2);
dbms_output.put_line('第-------------< '|| (i+1)|| ' >---------节点');
for j in 0..len2-1 loop
--dbms_output.put_line(len2);
attn:=xmldom.item(n2,j);
dbms_output.put_line(xmldom.getNodeValue(xmldom.getFirstChild(attn.id))||':'||xmldom.getNodeValue(xmldom.getFirstChild(attn))); end loop;
end loop;
-- Free the memory used by the parsed XML document
xmldom.freeDocument(theXmlDoc); RETURN vretuval;
ELSE
RETURN vretuval;
END IF;
END;
代码不是我写的,求大神说一下怎么去获取节点属性的值
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货