• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ludovik Lax
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 ?
 
Paul Clapham
Sheriff
Pie
Posts: 20735
30
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
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
Pie
Posts: 20735
30
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
Pie
Posts: 20735
30
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic