Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

XPath problem

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i am asked to write a program which is updating a xml file. the update is given by a string like: "/a//b[1]/c!updateCommand()". I have to first identify the xpath which can lead me to the correspond node which is to be updated. I know i should use DOM parser, but i don't know how to get the to be updated node which is 'c' in above example. I am trying to use recursion, but it's still hard. Can anyone give me suggestion?
say we have following test.xml
<a>
<c>
<b/>
<d>
<b/>
<a>
<b/>
</a>
</d>
</c>
<b>
<a>
<c/>
<e/>
<f>
<b/>
</f>
</a>
<d/>
</b>
</a>
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have the Xalan package you can look at an example of using the org.apache.xpath.XPathAPI classs within DOM. In the package it's under src>xalan-j_2_3_1>samples>ApplyXPath.
Here is the code -

Cheers,
Dan
 
fei long
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, i forgot mentioning that i am not allowed to use any package except Xerces. i just need some idea how to deal with "//" and "*" in xpath.
thanks
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!