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

XpathAPI utility class of Crimson parser.

 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the crimson's xpath utility (XpathAPI) fully compatible to the xPath standards.I have tried some xpaths on a dom , but did not get expected results.I have following strict Xpath rults , this made me feel that this api mught not be following xPath strictly.

XML under consideration:
<?xml version="1.0" encoding="UTF-8"?>
<father age="70">
<son>
<age>29</age>
</son>
<son name="Kumar">
<age>22</age>
</son>
</father>

and Xpath /father/son[1]/@name/text() should return Kumar but I am getting nothing.
Why is that so ?
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rahul,

It seems like XPATH is wrong. Try this " /father/son[2]/@name ". Let me know if this didn't work.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Prabhu venkatachalam:
It seems like XPATH is wrong. Try this " /father/son[2]/@name ". Let me know if this didn't work.



Yes Prabhu , this is working and returning me Kumar.
My xpath was worng.

/text() is not supposed to be used with attributes (only to be used with elements.).

Thanks,
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are correct. text() XPATH function should be use with element to findout its text value.

Thanks!
 
Politics n. Poly "many" + ticks "blood sucking insects". 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