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

XSL/XSLT/XPATH XML Discussion :

Debutant Libxml2 et C recherche de données dans XML


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Membre confirmé Avatar de Mika2008
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    176
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 176
    Par défaut Debutant Libxml2 et C recherche de données dans XML
    Bonjour,

    voila j’aimerais rechercher des données dans un fichier XML, Pour n'en garder que certain.

    j'ai regarder des codes d'emple de libxml2, mais ils ne sont pas trés clair.

    et je n'est rien trouvé sur comment rechercher une information d'une balise dans un xml.
    quelqu'un peut m'aiguiller svp ?

    merci @ vous.

  2. #2
    Membre confirmé Avatar de Mika2008
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    176
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 176
    Par défaut
    Par exemple ce code :

    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
    #include <libxml/parser.h>
    #include <libxml/xpath.h>
     
    xmlDocPtr
    getdoc (char *docname) {
    	xmlDocPtr doc;
    	doc = xmlParseFile(docname);
     
    	if (doc == NULL ) {
    		fprintf(stderr,"Document not parsed successfully. \n");
    		return NULL;
    	}
     
    	return doc;
    }
     
    xmlXPathObjectPtr
    getnodeset (xmlDocPtr doc, xmlChar *xpath){
     
    	xmlXPathContextPtr context;
    	xmlXPathObjectPtr result;
     
    	context = xmlXPathNewContext(doc);
    	if (context == NULL) {
    		printf("Error in xmlXPathNewContext\n");
    		return NULL;
    	}
    	result = xmlXPathEvalExpression(xpath, context);
    	xmlXPathFreeContext(context);
    	if (result == NULL) {
    		printf("Error in xmlXPathEvalExpression\n");
    		return NULL;
    	}
    	if(xmlXPathNodeSetIsEmpty(result->nodesetval)){
    		xmlXPathFreeObject(result);
                    printf("No result\n");
    		return NULL;
    	}
    	return result;
    }
    int
    main(int argc, char **argv) {
     
    	char *docname;
    	xmlDocPtr doc;
    xmlChar *xpath = (xmlChar*) "//feed//entry//id";
    	xmlNodeSetPtr nodeset;
    	xmlXPathObjectPtr result;
    	int i;
    	xmlChar *keyword;
     
    	if (argc <= 1) {
    		printf("Usage: %s docname\n", argv[0]);
    		return(0);
    	}
     
    	docname = argv[1];
    	doc = getdoc(docname);
    	result = getnodeset (doc, xpath);
    	if (result) {
    		nodeset = result->nodesetval;
    		for (i=0; i < nodeset->nodeNr; i++) {
    			keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
    		printf("keyword: %s\n", keyword);
    		xmlFree(keyword);
    		}
    		xmlXPathFreeObject (result);
    	}
    	xmlFreeDoc(doc);
    	xmlCleanupParser();
    	return (1);
    }
    je travaille sur ce fichier XML :
    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
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    <?xml version='1.0' encoding='UTF-8'?>
    <feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/&quot;DEYEQX87fyp7ImA9Wx9UF00.&quot;'>
    	<id>tag:youtube.com,2008:videos</id>
    	<updated>2011-02-14T17:55:00.107Z</updated>
    	<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
    	<title>YouTube Videos matching query: Ronald Jenkees</title>
    	<logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo>
    	<link rel='alternate' type='text/html' href='http://www.youtube.com'/>
    	<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?v=2'/>
    	<link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/batch?v=2'/>
    	<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?q=Ronald+Jenkees&amp;start-index=1&amp;max-results=2&amp;v=2'/>
    	<link rel='service' type='application/atomsvc+xml' href='http://gdata.youtube.com/feeds/api/videos?alt=atom-service&amp;v=2'/>
    	<link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?q=Ronald+Jenkees&amp;start-index=3&amp;max-results=2&amp;v=2'/>
    	<author>
    		<name>YouTube</name>
    		<uri>http://www.youtube.com/</uri>
    	</author>
    	<generator version='2.0' uri='http://gdata.youtube.com/'>YouTube data API</generator>
    	<openSearch:totalResults>2715</openSearch:totalResults>
    	<openSearch:startIndex>1</openSearch:startIndex>
    	<openSearch:itemsPerPage>2</openSearch:itemsPerPage>
    	<entry gd:etag='W/&quot;D0ANQX47eCp7ImA9Wx9UFkQ.&quot;'>
    		<id>tag:youtube.com,2008:video:smE-uIljiGo</id>
    		<published>2008-03-06T18:36:43.000Z</published>
    		<updated>2011-02-14T15:03:10.000Z</updated>
    		<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Music' label='Music'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='ronald'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='jenkees'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='unsigned'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='motif'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='XS'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='XS8'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='keyboard'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='guitar'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='jam'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='beat'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='fl'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='studio'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='fruityloops'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='hip-hop'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='solo'/>
    		<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='instrumental'/>
    		<title>Ronald Jenkees - Guitar Sound</title>
    		<content type='application/x-shockwave-flash' src='http://www.youtube.com/v/smE-uIljiGo?f=videos&amp;app=youtube_gdata'/>
    		<link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=smE-uIljiGo&amp;feature=youtube_gdata'/>
    		<link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/smE-uIljiGo/responses?v=2'/>
    		<link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/smE-uIljiGo/related?v=2'/>
    		<link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=smE-uIljiGo'/>
    		<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/smE-uIljiGo?v=2'/>
    		<author>
    			<name>ronaldjenkees</name>
    			<uri>http://gdata.youtube.com/feeds/api/users/ronaldjenkees</uri>
    			</author>
    			<yt:accessControl action='comment' permission='allowed'/>
    			<yt:accessControl action='commentVote' permission='allowed'/>
    			<yt:accessControl action='videoRespond' permission='moderated'/>
    			<yt:accessControl action='rate' permission='allowed'/>
    			<yt:accessControl action='embed' permission='allowed'/>
    			<yt:accessControl action='list' permission='allowed'/>
    			<yt:accessControl action='syndicate' permission='allowed'/>
    			<gd:comments>
    				<gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/smE-uIljiGo/comments?v=2' countHint='28562'/>
    				</gd:comments>
    				<media:group>
    					<media:category label='Music' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Music</media:category>
    					<media:content url='http://www.youtube.com/v/smE-uIljiGo?f=videos&amp;app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='255' yt:format='5'/>
    					<media:content url='rtsp://v2.cache1.c.youtube.com/CiILENy73wIaGQlqiGOJuD5hshMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='255' yt:format='1'/>
    					<media:content url='rtsp://v1.cache5.c.youtube.com/CiILENy73wIaGQlqiGOJuD5hshMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='255' yt:format='6'/>
    					<media:credit role='uploader' scheme='urn:youtube' yt:type='partner'>ronaldjenkees</media:credit>
    					<media:description type='plain'>download the MP3: www.ronaldjenkees.com **this tune is on my new CD, Disorganized Fun. I named it Guitar Sound. just havin some fun with a guitar sound (Hard Ramp AS1&amp;2) on the Motif XS8. Some have asked about the "low notes" that come out when I hit those two keys up top - those are guitar effects built in the patch and for whatever reason, Yamaha put those effects on the high keys. I made the background beat using FL Studio. I start the beat by hitting the space-bar on my computer keyboard before I play on the synth. PS. I've read some reviews of this vid as if I'm trying to be a "keytar" player (apparently not a desirable thing, but how can you not like Edgar Winter's "Frankenstein") and that I should just play a real guitar. LOL @ some of those same people who probably play guitar hero (nothing against it but hopefully you see my point)! The irony! The point is, folks, if you find a fun/inspiring sound to jam with, by all means, you should JAM WITH IT! I don't care if you find a $3.00 plastic trumpet. Don't worry about the technicalities and what people say. In the long run it's about the fun that YOU have making music. Thanks for watching!!!</media:description>
    					<media:keywords>ronald, jenkees, unsigned, motif, XS, XS8, keyboard, guitar, jam, beat, fl, studio, fruityloops, hip-hop, solo, instrumental</media:keywords>
    					<media:player url='http://www.youtube.com/watch?v=smE-uIljiGo&amp;feature=youtube_gdata_player'/>
    					<media:thumbnail url='http://i.ytimg.com/vi/smE-uIljiGo/default.jpg' height='90' width='120' time='00:02:07.500' yt:name='default'/>
    					<media:thumbnail url='http://i.ytimg.com/vi/smE-uIljiGo/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/>
    					<media:thumbnail url='http://i.ytimg.com/vi/smE-uIljiGo/1.jpg' height='90' width='120' time='00:01:03.750' yt:name='start'/>
    					<media:thumbnail url='http://i.ytimg.com/vi/smE-uIljiGo/2.jpg' height='90' width='120' time='00:02:07.500' yt:name='middle'/>
    					<media:thumbnail url='http://i.ytimg.com/vi/smE-uIljiGo/3.jpg' height='90' width='120' time='00:03:11.250' yt:name='end'/>
    					<media:title type='plain'>Ronald Jenkees - Guitar Sound</media:title>
    					<yt:duration seconds='255'/>
    					<yt:uploaded>2008-03-06T18:36:43.000Z</yt:uploaded>
    					<yt:videoid>smE-uIljiGo</yt:videoid>
    					</media:group>
    	<yt:statistics favoriteCount='52741' viewCount='7247365'/>
    	</entry>
    	<entry gd:etag='W/&quot;DkMBRn47eCp7ImA9Wx9UFkQ.&quot;'>
    						<id>tag:youtube.com,2008:video:0O2aH4XLbto</id>
    						<published>2008-08-05T21:56:54.000Z</published>
    						<updated>2011-02-14T14:40:57.000Z</updated>
    						<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
    						<category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Music' label='Music'/>
    						<title>Ronald Jenkees - Throwing Fire</title>
    						<content type='application/x-shockwave-flash' src='http://www.youtube.com/v/0O2aH4XLbto?f=videos&amp;app=youtube_gdata'/>
    						<link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=0O2aH4XLbto&amp;feature=youtube_gdata'/>
    						<link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/0O2aH4XLbto/responses?v=2'/>
    						<link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/0O2aH4XLbto/related?v=2'/>
    						<link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=0O2aH4XLbto'/>
    						<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/0O2aH4XLbto?v=2'/>
    						<author>
    							<name>ronaldjenkees</name>
    							<uri>http://gdata.youtube.com/feeds/api/users/ronaldjenkees</uri>
    							</author>
    							<yt:accessControl action='comment' permission='allowed'/>
    							<yt:accessControl action='commentVote' permission='allowed'/>
    							<yt:accessControl action='videoRespond' permission='moderated'/>
    							<yt:accessControl action='rate' permission='allowed'/>
    							<yt:accessControl action='embed' permission='allowed'/>
    							<yt:accessControl action='list' permission='allowed'/>
    							<yt:accessControl action='syndicate' permission='allowed'/>
    							<gd:comments>
    								<gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/0O2aH4XLbto/comments?v=2' countHint='28675'/>
    								</gd:comments>
    								<media:group>
    									<media:category label='Music' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Music</media:category>
    									<media:content url='http://www.youtube.com/v/0O2aH4XLbto?f=videos&amp;app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='190' yt:format='5'/>
    									<media:content url='rtsp://v4.cache2.c.youtube.com/CiILENy73wIaGQnabsuFH5rt0BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='190' yt:format='1'/>
    									<media:content url='rtsp://v2.cache1.c.youtube.com/CiILENy73wIaGQnabsuFH5rt0BMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='190' yt:format='6'/>
    									<media:credit role='uploader' scheme='urn:youtube' yt:type='partner'>ronaldjenkees</media:credit>
    									<media:description type='plain'>Throwing Fire is on my 2nd CD, Disorganized Fun: www.ronaldjenkees.com SUPER FUN TIME WITH THIS JAM!!!! Thanks a lot for watching! Hope you liked it. Kindof a rough cut, but it's always fun. This video is dedicated to the band Papa Roach for letting me check out their studio and giving me a place to stay in LA. Those are some hard-working rockers and good guys. I got cold chills listening to the songs they're working on for their new album. I think it's coming out really soon. My friend Sam gave me the hat I'm wearing in this vid. It's made of 100% recycled material. Can't beat that. Here's their site: www.livity.org I'm using FL Studio software to make the beat in the background and a Korg Triton Le keyboard on top, Motif XS8 on bottom.</media:description>
    									<media:keywords/>
    									<media:player url='http://www.youtube.com/watch?v=0O2aH4XLbto&amp;feature=youtube_gdata_player'/>
    									<media:thumbnail url='http://i.ytimg.com/vi/0O2aH4XLbto/default.jpg' height='90' width='120' time='00:01:35' yt:name='default'/>
    									<media:thumbnail url='http://i.ytimg.com/vi/0O2aH4XLbto/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/>
    									<media:thumbnail url='http://i.ytimg.com/vi/0O2aH4XLbto/1.jpg' height='90' width='120' time='00:00:47.500' yt:name='start'/>
    									<media:thumbnail url='http://i.ytimg.com/vi/0O2aH4XLbto/2.jpg' height='90' width='120' time='00:01:35' yt:name='middle'/>
    									<media:thumbnail url='http://i.ytimg.com/vi/0O2aH4XLbto/3.jpg' height='90' width='120' time='00:02:22.500' yt:name='end'/>
    									<media:title type='plain'>Ronald Jenkees - Throwing Fire</media:title>
    									<yt:duration seconds='190'/>
    									<yt:uploaded>2008-08-05T21:56:54.000Z</yt:uploaded>
    									<yt:videoid>0O2aH4XLbto</yt:videoid>
    									</media:group>
    									<yt:statistics favoriteCount='52285' viewCount='6488178'/>
    </entry>
    </feed>
    en théorie dans le code C je lui demande de m'afficher le contenue de la balise //feed//entry//id
    xmlChar *xpath = (xmlChar*) "//feed//entry//id";

    quand ke lance le programme il met me no result ?
    alors qu'il aurait du m'afficher :
    tag:youtube.com,2008:video:smE-uIljiGo
    ce que contient la balise //feed/entry/if

    qu'en pensez vous svp ?

  3. #3
    Rédacteur

    Avatar de Erwy
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2003
    Messages
    4 967
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 967
    Par défaut
    je ne connais pas bien cette bibliotheque mais, le problème vient sans doute que tu utilises un namespace (non préfixé pour tout arrangé).

    xmlns='http://www.w3.org/2005/Atom'
    Et il faudrait le passer en paramètre à ta fonction

    Pour ce que j'ai trouvé sur le web essaye quelque chose comme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     getnodeset (doc, xpath,'http://www.w3.org/2005/Atom')

  4. #4
    Membre confirmé Avatar de Mika2008
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    176
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 176
    Par défaut
    merci de ta réponse, mais ce le ne fonctionne pas :




    dans mon code je met ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    xmlChar *xpath = (xmlChar*) "http://www.w3.org/2005/Atom";
    ce qui me donne comme résultat :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    XPath error : Invalid expression
    http://www.w3.org/2005/Atom
         ^
    XPath error : Invalid expression
    http://www.w3.org/2005/Atom
         ^
    Error in xmlXPathEvalExpression

  5. #5
    Membre confirmé Avatar de Mika2008
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    176
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 176
    Par défaut
    j'ai trouvé ce petit article :

    http://xmlsoft.org/namespaces.html

    mais c'est pas trés claire?

  6. #6
    Membre confirmé Avatar de Mika2008
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    176
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 176
    Par défaut
    j'ai trouvé un début de réponse ici :

    urns out, as I found out from here, it is not really a failure of libXml, it's a problem because libXml correctly follows the XML/XPATH specifications.

    The solutions proposed by R Bourdeau are correct, however, if you have control of the xml document you are parsing.

    The context for the XPATH query is independent of the namespace qualifiers in the xml document. The default namespace forces all child tags into a namespace; they don't require qualification in the document but must be qualified in the xpath query. Fortunately, you registered the namespace as new with libXml, so cateof's solution should work.

    xmlXPathRegisterNs(context, BAD_CAST "new", BAD_CAST "http://www.example.com/new"

    xmlChar *xpath = (xmlChar*) "/new:book/new:section1";
    I'm inlining the xml here for visibility:

    <?xml version="1.0" encoding="UTF-8"?>
    <book xmlns="http://www.example.com/new">
    <section1>Sec_1</section1>
    <section2>Sec_2</section2>
    </book>

    par contre les balises comme ceci je n'arrive pas à extraire la donnée, le programme ne trouve pas cette balise :


    par exemple si je tape cette recherche :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    xmlChar *xpath_id_video= (xmlChar*) "/feed:feed/feed:entry/feed:media/feed:group/feed:yt/feed:videoid";

    je continue à chercher

  7. #7
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 585
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 585
    Par défaut
    Ce serait plutôt :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    /feed:feed/feed:entry/feed:media/feed:group/yt:videoid
    Et bien sûr il faut register yt de la même manière que tu as déjà registered feed.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  8. #8
    Membre confirmé Avatar de Mika2008
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    176
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 176
    Par défaut
    merci, voici la réponse final a mon problème :



    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
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <libxml/parser.h>
    #include <libxml/xpath.h>
    #include <libxml/xpathInternals.h>
    #include <Eina.h>
    #include "constante.h"
    #include "url_utils.h"
    #include <stdio.h>
    #include <curl/curl.h>
     
    xmlDocPtr
    getdoc (char *docname) {
    	xmlDocPtr doc;
    	doc = xmlParseFile(docname);
     
    	if (doc == NULL ) {
    		fprintf(stderr,"Document not parsed successfully. \n");
    		return NULL;
    	}else
    		printf("Document parsed successfully. \n");	
     
     
    	return doc;
    }
     
    xmlXPathObjectPtr
    getnodeset (xmlDocPtr doc, xmlChar *xpath){
     
    	xmlXPathContextPtr context;
    	xmlXPathObjectPtr result;
     
    	context = xmlXPathNewContext(doc);
     
     
    	xmlXPathRegisterNs(context,  BAD_CAST "feed", BAD_CAST "http://www.w3.org/2005/Atom");
    	xmlXPathRegisterNs(context,  BAD_CAST "media", BAD_CAST "http://search.yahoo.com/mrss/");
    	xmlXPathRegisterNs(context,  BAD_CAST "yt", BAD_CAST "http://gdata.youtube.com/schemas/2007");
     
    	if (context == NULL) {
    		printf("Error in xmlXPathNewContext\n");
    		return NULL;
    	}
    	result = xmlXPathEvalExpression(xpath, context);
    	xmlXPathFreeContext(context);
    	if (result == NULL) {
    		printf("Error in xmlXPathEvalExpression\n");
    		return NULL;
    	}
    	if(xmlXPathNodeSetIsEmpty(result->nodesetval)){
    		xmlXPathFreeObject(result);
                    printf("No result\n");
    		return NULL;
    	}
    	return result;
    }
     
    Eina_List *
    result_data_flux(char *docname, xmlChar *xpath )
    {
     
    	xmlDocPtr doc;
    	xmlNodeSetPtr nodeset;
    	xmlXPathObjectPtr result;
    	int i;	 
    	xmlChar *keyword;
    	Eina_List *list = NULL;
     
    	doc = getdoc(docname);
    	result = getnodeset (doc, xpath);
    		eina_init();
     
    	if (result) {
    		nodeset = result->nodesetval;
    		for (i=0; i < nodeset->nodeNr; i++) {
    			keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
    			//printf("keyword: %s\n", keyword);
    			list = eina_list_append(list, keyword);  
     
    		}
    		xmlXPathFreeObject (result);
    	}
    	else
    		printf("Result is NULL\n");
     
    	xmlFreeDoc(doc);
     
    	return list;
    }
     
    void
    afficheEListe_xmlchar(Eina_List *lt)
    {
    	Eina_List  *l = NULL;
    	xmlChar *data;
    	eina_init();
     
      EINA_LIST_FOREACH(lt, l, data)
    	printf("argument : %s\n", data); //Contenu de l'adresse data !
     
      //Libére notre list
      lt = eina_list_free(lt);
    }
     
    Eina_List *find_lt_author(char *docname)
    {	
    	Eina_List  *lt_author_name = NULL;
     
    	xmlChar *xpath_autheur_name = (xmlChar*) "/feed:feed/feed:entry/feed:author/feed:name";
     
    	lt_author_name =  result_data_flux(docname,xpath_autheur_name);
     
    	xmlCleanupParser();
     
    	return lt_author_name;
     
     
    }
     
    Eina_List * find_lt_video_id(char *docname)
    {
    		Eina_List  *lt_video_title = NULL;
     
    	xmlChar *xpath_id_video= (xmlChar*) "/feed:feed/feed:entry/media:group/yt:videoid";  
     
    	lt_video_title =  result_data_flux(docname,xpath_id_video);
     
    	xmlCleanupParser();
     
    	return lt_video_title;
    }
     
     
    Eina_List * find_lt_video_title(char *docname)
    {
    		Eina_List  *lt_video_title = NULL;
     
    		xmlChar *xpath_video_title = (xmlChar*) "/feed:feed/feed:entry/feed:title";
     
    	lt_video_title =  result_data_flux(docname,xpath_video_title);
     
    	xmlCleanupParser();
     
    	return lt_video_title;
    }
     
     
     
    xmlDocPtr
    get_xml_doc_from_memory (char *buffer)
    {
        xmlDocPtr doc = NULL;
     
        if (!buffer)
            return NULL;
     
        doc = xmlReadMemory (buffer, strlen (buffer), NULL, NULL,
                             XML_PARSE_RECOVER |
                             XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
        return doc;
    }
     
     
     
    Eina_List *
    lt_data_video(const char *recherche)
    {
     
    	eina_init();
    	Eina_List *lt_author_name = NULL, *lt_video_title = NULL, *lt_video_id = NULL;
    	Eina_List  *lt_video = NULL;
     
    	//récupartion du flux en mémoire
    	//utilisation de url_utils.	
    //char *url = "http://gdata.youtube.com/feeds/api/videos?q=ronald+jenkins&orderby=published&start-index=11&max-results=10&v=2";
     
    	///////////////////////////////////////////////////
    	///////////////////////////////////////////////////
     
     
     
    	///////////////////////////////////////////////////
    	///////////////////////////////////////////////////
     
     
     
     
    printf("recherche = %s\n",recherche);
      CURL *curl;
      CURLcode res;
     
      curl = curl_easy_init();
     
      if(curl) {
     
        curl_easy_setopt(curl, CURLOPT_URL, recherche);
     
        FILE * fp = fopen("./liste.xml", "w"); 
    	curl_easy_setopt(curl,  CURLOPT_WRITEDATA, fp); 
    	curl_easy_setopt(curl,  CURLOPT_WRITEFUNCTION, fwrite);
    	curl_easy_perform(curl);
    	fclose(fp);
    	curl_easy_cleanup(curl);
    	}
        else {
        res = curl_easy_perform(curl);
     
        /* always cleanup */ 
        curl_easy_cleanup(curl);
    	}
     
     
      char *doc = "liste.xml";
     
     
     
    		//fin utilisation du 
     
    lt_author_name =  find_lt_author(doc);
    lt_video_title = find_lt_video_id(doc);
    lt_video_id = find_lt_video_title(doc);
     
     
    	xmlChar *data_author, *data_video_title,* data_video_id;
    	struct cf_video *o_video;
    	eina_init();
    	int i =0;
     
    	for (i=0;i< eina_list_count(lt_video_title);i++)
    	{
    	o_video = (struct cf_video*)malloc(sizeof(struct cf_video));	
     
    		data_author = eina_list_data_get(lt_author_name);
    		data_video_title = eina_list_data_get(lt_video_title);
    		data_video_id = eina_list_data_get(lt_video_id);
     
     
    		o_video->video_title =  data_video_title;
    		o_video->video_id  =  data_video_id;
    		o_video->author_name  =  data_author;
    		//printf("%d , author_name : %s, video_title : %s, video_id : %s\n",i,o_video->author_name,o_video->video_title, o_video->video_id); //Contenu de l'adresse data !
    		lt_video = eina_list_append(lt_video, o_video);
     
     
     
    		//permet de passer a la donnée suivante
    		lt_video_id = eina_list_next (lt_video_id);
    		lt_author_name = eina_list_next (lt_author_name);
    		lt_video_title = eina_list_next (lt_video_title);
     
     
    	}
     
     
    	return lt_video;
    }

Discussions similaires

  1. Rechercher des données dans un autre workbook
    Par Azounet1529 dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 23/07/2007, 09h26
  2. recherche de donnée dans deux tables
    Par donny dans le forum Langage SQL
    Réponses: 3
    Dernier message: 21/06/2007, 21h41
  3. recherche de données dans feuil excel
    Par tigdub1gal dans le forum Excel
    Réponses: 3
    Dernier message: 24/05/2007, 18h58
  4. recherche de donnée dans 2 colonnes
    Par zeloutre dans le forum Access
    Réponses: 10
    Dernier message: 05/03/2007, 13h08
  5. Recherche de Donnée dans une base
    Par Poisson59 dans le forum MS SQL Server
    Réponses: 10
    Dernier message: 19/09/2006, 12h40

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