• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

iterate a doc with sax and change xpath expression at run time  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I d' like to evaluate an xpath expresion for getting the attribute value:



Here , I use attribute:value and get search / replace :




But, how to make the xpath expression to point directly for the value attribute: <property name="userDistrib" value="0007.02"/>

My goal is to modify this value in iterator, so a hardcoded value to replace is not possible ?
 
Sheriff
Posts: 23710
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've typed two possible answers in here and erased both of them, because I can't tell what you are asking. I think you're going to have to explain this:

My goal is to modify this value in iterator, so a hardcoded value to replace is not possible ?


in some different way. Perhaps you could explain what that code is meant to do and what it does instead and why that's wrong.
 
Ludovik Lax
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is getting a modification on xpath , each time an iteration is done:




so i have used this expression , but maybe a better way to set this independant of the order on attribute::value result
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But XPath is going to use a DOM anyway, isn't it? Why are we talking SAX here?

What is GeneratorXpath?

Bill
 
Paul Clapham
Sheriff
Posts: 23710
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Arthur Burma wrote:so i have used this expression , but maybe a better way to set this independant of the order on attribute::value result


Well, assuming we are actually talking about DOM programming here (your code certainly looks like that): you should be getting an Attr node from that XPath expression. So why wouldn't you just use its setValue() method, as per the documentation?

I'm saying that based on the fact that you haven't told us that you are having a problem, or what it is if there is a problem. So I'm just guessing at things to say. So perhaps you could do that. If there are exceptions, show us the stack trace. If some output differs from what you think it should be, show it to us and tell us what the difference is.
 
Ludovik Lax
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To keep things simple I have to clarify , hereis the xml :


Actually I just want to modify the value in property with replacing the string "loader/CSV" by "output/local" for instance... I have some trouble <ith xpath for that because it's not outside an attribute tag;

regards
 
Paul Clapham
Sheriff
Posts: 23710
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So:

(1) Find the attribute.

(2) Extract its value into a String variable.

(3) Get the corrected value into a String variable.

(4) Set the new value of the attribute.

When you're done, don't forget to serialize your DOM. Changing the value in memory and not writing that out to a file can lead you to believe that the value wasn't changed.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!