Hallo,
fange ganz frisch damit an, folgendes Schnipselchen geht, aber zeigt nichts an, warum?
die zugehörige book.xml sieht so aus:
Danke schon im voraus!
fange ganz frisch damit an, folgendes Schnipselchen geht, aber zeigt nichts an, warum?
Code:
package xpath;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.xml.sax.InputSource;
public class xpath
{
/**
* Creates a new instance of xpath
*/
public xpath()
{
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
String expression = "/book";
InputSource iSource = null;
try
{
iSource = new InputSource("book.xml");
}
catch(Exception e)
{
e.printStackTrace(System.out);
}
XPath xpath = XPathFactory.newInstance().newXPath();
try
{
String output = xpath.evaluate(expression, iSource);
System.out.println("output: " + output);
}
catch(XPathExpressionException e)
{
e.printStackTrace(System.out);
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
die zugehörige book.xml sieht so aus:
Code:
<bookstore>
<book>
<title id='1'>XPath Tutorial</title>
<author>Mamun Zaman</author>
<year>2007</year>
<price>00.99</price>
</book>
<book>
<title id='2'>AJAX Tutorial</title>
<author>Charles</author>
<year>2007</year>
<price>03.45</price>
</book>
</bookstore>
Danke schon im voraus!