[code]
private Vector vector = null;
NodeSetXPath() {
vector = new Vector();
}
public synchronized Vector evaluate(InputStream stream, String expression) {
try {
NodeList lstNode = eval(stream, expression);
for (int j = 0; j < lstNode.getLength(); ++j) {
vector.add(lstNode.item(j).getTextContent());
}
} catch (Exception e) {
System.err.println("Impossible d'afficher le flux RSS." + e.getMessage());
System.exit(0);
}
return vector;
}
private synchronized NodeList eval(InputStream stream, String expression) {
NodeList list = null;
try {
//création de la source
InputSource source = new InputSource(stream);
//création du XPath
XPathFactory fabrique = XPathFactory.newInstance();
XPath xpath = fabrique.newXPath();
//évaluation de l'expression XPath
XPathExpression exp = xpath.compile(expression);
list = (NodeList) exp.evaluate(source, XPathConstants.NODESET);
} catch (XPathExpressionException xpee) {
xpee.printStackTrace();
}
return list;
}
[/code]
J'arrive a parser un fichier rss 2.0 mais pas un fichier 1.0
NodeSetXPath xpath = new NodeSetXPath();
xpath.evaluate(in, "rss/channel/item/title");
Comment faire???