File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XPath " Watch "XPath " New topic


kamiya sei

Joined: Dec 12, 2012
Posts: 25
Hi all .

I have a small application called class "XPath&XQuery".

and here is my code. Because it was too long so I just quoted part of the code, so there are questions I will add later

public static void Parse() {

Document doc = new Builder().build(new File("books.xml"));

Nodes students=XQueryUtil.xquery(doc, "@*");

for (int i = 0; i < students.size(); i++) {
Node book = students.get(i);

String name = book.getValue();

System.out.println("book name is " + name);

public static void main(String[] args) {

When I run it . 'attribute node' doesn't display??
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
Nodes students=XQueryUtil.xquery(doc, "@*");

By the look of it, you seem to want to find the attributes attached to the root element.

If you mean to get the attributes attached to the root element and that either you don't know the root element's name or that you just want to make it more flexible without every time commit yourself to a concrete root element's name, you can do this.
I agree. Here's the link:
subject: XPath
Similar Threads
Using Xpath in java
Parsing XML file using Xpath in jdk1.4
XPath expression constrained by a predicate doesn't work (//element[@attribute="value"])
help!Urgent,my assignment.....
How to detect EOF when using