Hello,
I need some help with this. Until now i know how to add in XML from JSP but i have never try before to edit an XML file. More specific, i would like to decrease <number>...</number> tag any time submit button is pressed.
thank you
14 replies to this topic
#1
Posted 16 May 2011 - 11:47 AM
|
|
|
#2
Posted 16 May 2011 - 01:36 PM
You should be able to do setTextContent(..) on the node your evaluate method returns, see Change a particular node in XML : DOM Edit « XML « Java
#3
Posted 16 May 2011 - 01:38 PM
Is possible to do it at the same Manager class, or i have to create new class?
Edit: The element that i want to change is an integer type, and my goal is each time corresponding item has been selected, its quantity decrease by 1. There is any other method instead of getTextContent()?
Edit: The element that i want to change is an integer type, and my goal is each time corresponding item has been selected, its quantity decrease by 1. There is any other method instead of getTextContent()?
#4
Posted 16 May 2011 - 01:56 PM
Not really something useful: Node (Java 2 Platform SE 5.0)
Just do
And going to bed now.
Just do
int currentValue = Integer.parseInt( node.getTextContent() ); node.setTextContent(currentValue -1);
And going to bed now.
#5
Posted 16 May 2011 - 02:02 PM
Very helpfull thank you.
Just to see if i become good student
to compile the quantity of current item
Just to see if i become good student
to compile the quantity of current item
//shop/category/items[name=='getName()']/quantityright???
#6
Posted 16 May 2011 - 11:36 PM
If you're xml looks like:
...possible other tags before <shop> <category> <items> <name> <quantity>yes.
#7
Posted 17 May 2011 - 01:30 AM
EDIT
Now the problem is not those methods, but
Now the problem is not those methods, but
.setTextContent(int-1);says cannot applied to (int). Tried
.setTextContent((int-1).toString());but says int cannot be dereferenced.
#8
Posted 17 May 2011 - 01:57 AM
I think that's because int has no toString method (every class that doesn't begin with a capital letter has no methods - primitive class in Java)
Just do +""
Just do +""
.setTextContent((int-1) +"");
#9
Posted 17 May 2011 - 02:10 AM
I tried
Integer.toString(int-1)and is working :). Page is working fine if i have for example
shop/category/items[name='APPLES']/quantityeach time apples added to the cart XML decreased by one, but how i will achieve to do it for all items?
for(int i=0; i<purchase.size(); i++){
Purchase dlPurchase = (Purchase) purchase.get(i);
.
.
shop/category/items[name='"+dlPurchase.getName()+"']/quantity
.....
}Tried the above but nothing happen
#10
Posted 17 May 2011 - 02:49 AM
It is never get in the for loop..:S strange
#11
Posted 17 May 2011 - 02:50 AM
Then it's simple, purchase is empty :P
#12
Posted 17 May 2011 - 03:29 AM
ohh im so stupid... i had clearAll() before decrease() grr :s
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









