• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Update using XPath

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Bill
 
Rohit Kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wann to update xml.

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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic