Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Irritating XMLDOM issue
Hi,
Straightforward question: is there a way of getting a nodelist from an XML document by providing an XPATH query, whereby the nodelist contains handles onto the XML document rather than copies of the nodes?
More detail:
I have an XML document in the form of a dbms_xmldom.DOMDocument object
and am writing a PL/SQL query that enables one to change the values of
attributes across the document by specifying (1) the elements to edit,
(2) the attribute to edit and (3) the new value of the attribute.
I would like to specify (1) using an XPATH query: build a node list of matching elements and then use the API to edit the elements. This would be nice as the XPATH query offers a lot of flexibility.
The only relevant function appears to be "selectNodes()", used as follows:
DocElement := dbms_xmldom.getDocumentElement(Doc); ElementToMatch := 'fooElementName[@barAttributeName=''someVal'']'; NodeList := dbms_XSLPROCESSOR.selectNodes(DocElemAsNode, ElementToMatch)
Now we have a node list that we can manipulate. Brilliant?! Well no. selectNodes appears to give us a copy of the nodes, not handles into the document. So the document is not updated when we do say:
dbms_xmldom.setNodeValue(Node,NewAttrVal)
(where Node is some attribute of an element in NodeList).
I've got a solution working whereby I use "getChildrenByTagName" to build my nodelist:
NodeList := dbms_xmldom.getChildrenByTagName(DocElement, TagName);
This works fine, but is very limited as you have to provide the tagName and do lots of fiddling through the query to check that you are manipulating only those nodes that you wish to. It lacks the elegance, simplicity and flexibility of XPATH.
For reference, here is some documentation of XMLDOM:
http://www.lc.leidenuniv.nl/awcourse/oracle/appdev.920/a96612/d_xmldo5.htm#1025440
and here is some sample code for manipulating nodes:
http://saturn.uab.es/appdev.92 0/a96620/xdb08pls.htm
(search for Example 8-1 Creating and Manipulating a DOM Document)
Many thanks,
JonT Received on Thu Jul 28 2005 - 06:53:42 CDT
![]() |
![]() |