• 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

XPATH question

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im trying to use xpath to obtain certain nodes from a document. The following however does not produce the result which Im looking for. I only know one element in this case dataset and one attribute @name so I need to do it this way. The xpath query produces the right result in a xml editor so Im just confused why I cant this to work. Thank you for your time.

NodeList childNodeList = XPathAPI.selectNodeList(document,"dataset//*[@name='AA']");


<?xml version="1.0" encoding="ISO-8859-1" ?>
<dbdata>
<dataset>
<recordset name="AA" primarykey="AID" sql="SELECT * FROM TEAM" recordname="CC">
<whereClause name="BID" type="String"/>
<col type="int">A</col>
<col type="String">B</col>
</recordset>
</dataset>
</dbdata>
 
Marshal
Posts: 28177
95
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
Assuming that "document" is your document and not its root node, then it doesn't have a child element named "dataset". It has one child, namely the root ("dbdata") element.
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont understand though why the query returns the right result though when I test it in a xpath editor
 
Paul Clapham
Marshal
Posts: 28177
95
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
Probably in the editor you point at the root node and then execute the XPath expression. Or maybe the editor defaults the context node to be the root node instead of the document. You would have to ask the makers of the editor that question.

I suggest that if you change the first parameter of selectNodeList to be the root node and not the document, you will get the answer you expect. Or if you change your XPath expression to be relative to the document and not relative to the root node.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic