Xpath parser un rss 1.0

Fermé
samplaid Messages postés 34 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 17 juillet 2008 - 5 mai 2008 à 21:07
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 - 6 mai 2008 à 11:48

   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;
    }



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???

1 réponse

Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
6 mai 2008 à 11:48
ouep bonjour à toi aussi.... pour ta solution c'est ICI

------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."

OoWORAoO
0
Rejoignez-nous