wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes issue in deleting block of elements from xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "issue in deleting block of elements from xml" Watch "issue in deleting block of elements from xml" New topic
Author

issue in deleting block of elements from xml

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 979
    
    2
Hi All,

I facing one problem in deleting block of elements from xml.

below is my sample xml,


in the above xml i need to delete entire block starting from



below is the xpath which i am trying,

/Query/first/second/row[@className='abcd']/third[key='attrID']/value"

but the isue is : this xpath will delete only one one element from that block as i am pointing to that element only using this xpath.

i could use id in xpath path where clause but this id is not constant it can change.

is there any other way to achieve what i want?

also i was thing if i can get parent of parent of the xpath which i used then i would be able to delete, but i am no sure if it possible to get partent of parent?

Please let me know if any other information is required.

Thanks,
Punit
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
/Query/first/second/row[@className='abcd']/third[key='attrID']/value"

You use or conceive this path for a reason. What is that? If you want to show a sample to illustrate the need, the sample must reflect the differential aspect of the problem. You have className everywhere same abcd, you have attrID the same in each block. What are their characteristics that make them appropriate for the differentiation of different blocks?
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 979
    
    2
Hi tsuji,

so the classname can be same same for many blocks, so i can not make xpath based on classname only, i will need to put some more conditions, which i did in my posted xpath.

and the reason i used attrID is that this attrID would be unique for that block which i want to delete.

this xpath will give me a element from the block which i want to delete and using this is can delete that element, but the problem is i need to delete the entire block not this element only.

/Query/first/second/row[@className='abcd']/third[key='attrID']/value"

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
Then you should write the sample with AttrIDxyz for one AttrIDabc for the other etc so that the sample serves its purpose...

In any case, try this.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 979
    
    2
Hi tsuji,

thanks for your reply.

so as per your xpath :
/Query/first/second/row[@className='abcd' and third/key='attrID']


it will delete the block of third, all elements inside element, below elements?


correct?

however in my case i need to delete the entire <row classname"abcd" id="2"> element block.

This entire block,



so should i add this to my xpath :


/Query/first/second/row[@className='abcd' and row/third/key='attrID']


my apologies : i should try this by my own, but i am facing issues with my machine, and will need to complete some task tomorrow in my office, hence wanted to make sure.

Thanks again
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
it will delete the block of third, all elements inside element, below elements?

No, it will select the container element row (<row classname"abcd" id="2">) itself or to that effect the entire block (or subtree). Whether eventually it be deleted or not, it is up to you.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 979
    
    2
yup here i meant select actually, but eventually i am deleting

anyways thanks allot

by the way, do you know a quick reference where i can learn about making more complex xpaths?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: issue in deleting block of elements from xml
 
Similar Threads
Disable an h:dataTable element in a specific row
Is transaction possible when one query is dependent on previous query result?
Struts validation not happening
JSF Vs Struts (Portlets perspective)
Page section does not update after call of a4j:support in IE 9