• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

issue in deleting block of elements from xml

 
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

/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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic