📄 nodesetxpath.java
字号:
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.sax.*;
import javax.xml.xpath.*;
import javax.xml.namespace.*;
import java.io.*;
import java.net.*;
public class NodeSetXPath{
public static NodeList evaluer(InputStream stream, String expression){
NodeList liste = null;
try{
//cr閍tion de la source
InputSource source = new InputSource(stream);
//cr閍tion du XPath
XPathFactory fabrique = XPathFactory.newInstance();
XPath xpath = fabrique.newXPath();
//関aluation de l'expression XPath
XPathExpression exp = xpath.compile(expression);
liste = (NodeList)exp.evaluate(source,XPathConstants.NODESET);
}catch(XPathExpressionException xpee){
xpee.printStackTrace();
}
return liste;
}
public static void main(String[] args){
try{
URL url = new URL("http://blog.developpez.com/xmlsrv/rss2.php?blog=1");
String expression = "//item/title";
System.out.println("Articles disponibles sur le blog de developpez.com");
NodeList liste = evaluer(url.openStream(),expression);
if(liste != null){
for(int i=0; i<liste.getLength(); i++){
Node node = liste.item(i);
System.out.println(node.getTextContent());
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -