This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic