Is it posssible to do update using XPath? Please let me know, and if possible a sample expression for xpath update.
Even a link would help.
Thnaks.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
Update of what?
My crystal ball is in the shop for the 10000 vision checkup so you will have to explain what you are trying to do. If you are a beginner with XML you really should complete a general tutorial.
Do you already know how to parse an input XML document into a Java DOM? If not, start with that.
I have a xml instance, and I wann to update a element's value. I am using "javax.xml.xpath.XPath". I have seen many xPath expressions, but haven't seen any to update xml instance. All are just to retrive.
I have sufficient knoledge of xml, and DOM and parsing and all. But I want to update xml using xPath.
Thnaks.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
XPath is used to select parts of an XML document; it has no facilities for updating. But since it returns DOM objects (Elements, if memory serves, or maybe Nodes) you can then use DOM methods for altering the document.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
It turns out there is a new extension to XQuery called the XQuery Update Facility 1.0 that is supposed to let you find nodes using xquery/xpath and then change them. This spec just became a W3C recommendation in June so good luck finding an implementation. I found some indication that the SAXON toolkit is going to (already has?) support for this spec. Anybody use it??
If you can locate DOM Nodes using XPath you can then use standard DOM methods to change/add to them. What have you tried?
Bill [ July 10, 2008: Message edited by: William Brogden ]
Rohit Kumar
Ranch Hand
Joined: Sep 20, 2007
Posts: 53
posted
0
yes I could update it using DOM after retriving. But i have a big xml file which i have to update regularly. So i was looking to update it directly throug some query.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
I know of no magic technology that will let you "update" an XML document in situ or without parsing it.
XPath requires a DOM in memory to work with, it is also substantially slower than directly manipulating the DOM with standard methods.
IF your "update" to the XML document simply involves plugging new values into existing hierarchy structure. SAX style parsing while writing a complete new document that will replace the old will be the fastest and most memory efficient.