IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Format d'échange (XML, JSON...) Java Discussion :

parser un fichier de type rss 1.0 [XPATH]


Sujet :

Format d'échange (XML, JSON...) Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Inscrit en
    Février 2006
    Messages
    220
    Détails du profil
    Informations forums :
    Inscription : Février 2006
    Messages : 220
    Par défaut parser un fichier de type rss 1.0
    Bonjour,

    Je n'arrive pas a parser un fichier de type rss1.0 pour un fichier rss 2.0, y a pas de problème. Si je fait test("rss/channel/item/title") pour un fichier rss2.0 ca marche mais j'ai aucun résultat si je fais test("rdf:RDF/channel/item/title")

    Merci de votre aide

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    	public static void test(InputStream in, String expression)
    			throws ParserConfigurationException, XPathExpressionException,
    			org.xml.sax.SAXException, java.io.IOException {
     
    		DocumentBuilder parser = DocumentBuilderFactory.newInstance()
    				.newDocumentBuilder();
    		Document doc = parser.parse(in);
     
    		XPath xpath = XPathFactory.newInstance().newXPath();
     
    		NodeList nodes = (NodeList) xpath.evaluate(expression, doc,
    				XPathConstants.NODESET);
     
    		for (int i = 0; i < nodes.getLength(); i++) {
    			System.out.println((nodes.item(i).getTextContent()));
    		}
    	}
    Le fichier rss 1.0 à parser :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
     
    <?xml version="1.0"?>
     
    <rdf:RDF 
      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns="http://purl.org/rss/1.0/"
    >
     
      <channel rdf:about="http://www.xml.com/xml/news.rss">
        <title>XML.com</title>
        <link>http://xml.com/pub</link>
        <description>
          XML.com features a rich mix of information and services 
          for the XML community.
        </description>
     
        <image rdf:resource="http://xml.com/universal/images/xml_tiny
    .gif" />
     
        <items>
          <rdf:Seq>
            <rdf:li resource="http://xml.com/pub/2000/08/09/xslt/xslt
    .html" />
            <rdf:li resource="http://xml.com/pub/2000/08/09/rdfdb/ind
    ex.html" />
          </rdf:Seq>
        </items>
     
        <textinput rdf:resource="http://search.xml.com" />
     
      </channel>
     
      <image rdf:about="http://xml.com/universal/images/xml_tiny.gif"
    >
        <title>XML.com</title>
        <link>http://www.xml.com</link>
        <url>http://xml.com/universal/images/xml_tiny.gif</url>
      </image>
     
     
      <item rdf:about="http://xml.com/pub/2000/08/09/xslt/xslt.html">
        <title>Processing Inclusions with XSLT</title>
        <link>http://xml.com/pub/2000/08/09/xslt/xslt.html</link>
        <description>
         Processing document inclusions with general XML tools can be
     
         problematic. This article proposes a way of preserving inclu
    sion 
         information through SAX-based processing.
        </description>
      </item>
     
      <item rdf:about="http://xml.com/pub/2000/08/09/rdfdb/index.html
    ">
     
        <title>Putting RDF to Work</title>
        <link>http://xml.com/pub/2000/08/09/rdfdb/index.html</link>
        <description>
         Tool and API support for the Resource Description Framework 
         is slowly coming of age. Edd Dumbill takes a look at RDFDB, 
         one of the most exciting new RDF toolkits.
        </description>
      </item>
     
      <textinput rdf:about="http://search.xml.com">
        <title>Search XML.com</title>
     
        <description>Search XML.com's XML collection</description>
        <name>s</name>
        <link>http://search.xml.com</link>
      </textinput>
     
    </rdf:RDF>

  2. #2
    Membre éclairé
    Inscrit en
    Février 2006
    Messages
    220
    Détails du profil
    Informations forums :
    Inscription : Février 2006
    Messages : 220
    Par défaut
    solution test("//item/title");

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Parser un fichier de type xml
    Par dafpp dans le forum Langage
    Réponses: 7
    Dernier message: 07/02/2012, 14h15
  2. Parser un fichier en une structure de type arbre
    Par franquis dans le forum Langage
    Réponses: 2
    Dernier message: 17/01/2012, 00h52
  3. Regexp pour parser un fichier de type hosts
    Par witch dans le forum Langage
    Réponses: 6
    Dernier message: 21/05/2011, 22h58
  4. Parser un flux XML (type fichier de log) en java
    Par zorglubpok dans le forum Format d'échange (XML, JSON...)
    Réponses: 5
    Dernier message: 28/09/2009, 18h24
  5. Parser un fichier de configuration de type ini
    Par arnaudperfect dans le forum Débuter
    Réponses: 7
    Dernier message: 17/03/2008, 14h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo