Précédent   Forum des professionnels en informatique > PHP > Langage > Fonctions
Fonctions Forum d'entraide sur les fonctions PHP. Avant de poster -> FAQ fonctions et Sources diverses
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 03/02/2011, 11h59   #1
Invité de passage
 
Inscription : décembre 2007
Messages : 5
Détails du profil
Informations forums :
Inscription : décembre 2007
Messages : 5
Points : 1
Points : 1
Par défaut [PHP] Comment parser un XML sans racine ?

Salut,
Je suis en train d'écrire un script qui insère les données contenues dans un fichier BibTex dans une base de données MySQL.
Je convertis d'abord le fichier BibTex en XML à l'aide d'un script python trouvé sur le net, puis je parse le XML obtenu grâce à la classe SimpleXMLElement de PHP.

Le problème est que le XML obtenu n'a pas de racine, c'est à dire tous les éléments sont tous directement placés dans l'architecture, sans être placés dans un même élément de DOM.

Je crée donc un nouvel objet SimpleXMLElement à partir du code XML obtenu de la conversion BibTex -> XML:
Code :
1
2
 
$xml = new SimpleXMLElement($this->convertedXML, 0, false, 'bibtex', true);
Voici ensuite le debug de mon script:

$xml->asXML():
Code :
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
 
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE bibtex:file PUBLIC "-//BibTeXML//DTD XML for BibTeX v1.0//EN" "bibtexml.dtd">
<bibtex:file xmlns:bibtex="http://bibtexml.sf.net/">
 
 
<bibtex:entry id="btxdoc">
<bibtex:manual>
<bibtex:author>Oren Patashnik</bibtex:author>
<bibtex:title>BibTeXing</bibtex:title>
<bibtex:address>BibTeX distribution</bibtex:address>
<bibtex:month>February</bibtex:month>
<bibtex:year>1988</bibtex:year>
 
<bibtex:url>ftp://sunsite.unc.edu/pub/packages/TeX/biblio/bibtex/distribs/doc/btxdoc.tex</bibtex:url>
</bibtex:manual>
</bibtex:entry>
 
<bibtex:entry id="Tufte-1997-VEI">
<bibtex:book>
<bibtex:author>Edward R. Tufte</bibtex:author>
<bibtex:title>Visual Explanations: Images and Quantities, Evidence and Narrative</bibtex:title>
<bibtex:publisher>Graphics Press</bibtex:publisher>
<bibtex:address>Box 430, Cheshire, CT 06410, USA</bibtex:address>
<bibtex:pages>156</bibtex:pages>
 
<bibtex:year>1997</bibtex:year>
<bibtex:isbn>0-9613921-2-6</bibtex:isbn>
<bibtex:lccn>P93.5.T846 1997</bibtex:lccn>
<bibtex:mrnumber>B.Tufte.97</bibtex:mrnumber>
<bibtex:bibdate>Thu Aug 07 13:39:07 1997</bibtex:bibdate>
<bibtex:price>US\$45.00</bibtex:price>
<bibtex:acknowledgement>ack-nhfb"(not listed)"</bibtex:acknowledgement>
<bibtex:class>map2</bibtex:class>
<bibtex:keywords>scglib</bibtex:keywords>
 
</bibtex:book>
</bibtex:entry>
 
<bibtex:entry id="robinson">
<bibtex:book>
<bibtex:editor>Robinson, W. F. and Huxtable, C. R. R.</bibtex:editor>
<bibtex:title>Clinicopathologic Principles For Veterinary Medicine</bibtex:title>
<bibtex:publisher>Cambridge University Press</bibtex:publisher>
<bibtex:year>1988</bibtex:year>
<bibtex:address>Cambridge</bibtex:address>
</bibtex:book>
</bibtex:entry>
 
<bibtex:entry id="huffman">
<bibtex:article>
<bibtex:author>Huffman, L. M.</bibtex:author>
<bibtex:title>Processing whey protein for use as a food ingredient</bibtex:title>
<bibtex:journal>Food Technology</bibtex:journal>
<bibtex:year>1996</bibtex:year>
<bibtex:volume>50</bibtex:volume>
<bibtex:number>2</bibtex:number>
<bibtex:pages>49-52</bibtex:pages>
 
</bibtex:article>
</bibtex:entry>
 
<bibtex:entry id="graps">
<bibtex:article>
<bibtex:author>Graps, Amara L.</bibtex:author>
<bibtex:title>An Introduction to Wavelets</bibtex:title>
<bibtex:journal>IEEE Computational Sciences and Engineering</bibtex:journal>
<bibtex:year>1995</bibtex:year>
<bibtex:volume>2</bibtex:volume>
<bibtex:number>2</bibtex:number>
 
<bibtex:pages>50-61</bibtex:pages>
<bibtex:note>http://www.amara.com/ftpstuff/IEEEwavelet.ps.gz</bibtex:note>
</bibtex:article>
</bibtex:entry>
 
<bibtex:entry id="berkman">
<bibtex:book>
<bibtex:author>Berkman, R. I.</bibtex:author>
<bibtex:title>Find It Fast: How to Uncover Expert Information on Any Subject</bibtex:title>
<bibtex:publisher>HarperPerennial</bibtex:publisher>
<bibtex:year>1994</bibtex:year>
 
<bibtex:address>New York</bibtex:address>
</bibtex:book>
</bibtex:entry>
 
<bibtex:entry id="chicago">
<bibtex:inbook>
<bibtex:title>The Chicago Manual of Style</bibtex:title>
<bibtex:publisher>University of Chicago Press</bibtex:publisher>
<bibtex:edition>Thirteenth</bibtex:edition>
<bibtex:year>1982</bibtex:year>
<bibtex:pages>400-401</bibtex:pages>
 
<bibtex:key>Chicago</bibtex:key>
</bibtex:inbook>
</bibtex:entry>
 
 
<bibtex:entry id="testcase-percent">
<bibtex:article>
<bibtex:author>Doe, J.</bibtex:author>
<bibtex:title>The use of \% gives trouble</bibtex:title>
<bibtex:journal>Doe's Journal</bibtex:journal>
<bibtex:year>2004</bibtex:year>
<bibtex:volume>1</bibtex:volume>
 
<bibtex:number>1</bibtex:number>
<bibtex:pages>1-2</bibtex:pages>
</bibtex:article>
</bibtex:entry>
 
<bibtex:entry id="Gawinecki2005a">
<bibtex:inproceedings>
<bibtex:author>
<bibtex:person>Maciej Gawinecki</bibtex:person>
<bibtex:person>Minor Gordon</bibtex:person>
<bibtex:person>Marcin Paprzycki</bibtex:person>
<bibtex:person>Michał Szymczak</bibtex:person>
 
<bibtex:person>Zygmunt Vetulani</bibtex:person>
<bibtex:person>Jimmy Wright</bibtex:person>
</bibtex:author>
<bibtex:title>Enabling Semantic Referencing of Selected Travel Related Resources</bibtex:title>
<bibtex:booktitle>Proceedings of the 8 th International Conference on Business Information Systems (BIS 2005)</bibtex:booktitle>
<bibtex:year>2005</bibtex:year>
<bibtex:pages>271-28</bibtex:pages>
<bibtex:address>Poznań, Poland</bibtex:address>
<bibtex:publisher>Poznań University of Economics Press</bibtex:publisher>
 
<bibtex:abstract>This paper describes our efforts to semantically describe travelrelated documents on the Internet. We focus on the areas of lodging and gastronomy, with allowance for further expansion into other aspects of the world of travel. Based on an analysis of currently-available data, we develop hotel ontology. Furthermore, we explicitly define an ontology for the Chefmoz project data, which has no official schema. Finally, we sketch a way to combine these two ontologies for use in an integrated travel framework.</bibtex:abstract>
<bibtex:owner>maciej</bibtex:owner>
<bibtex:timestamp>2006.07.13</bibtex:timestamp>
<bibtex:url>http://agentlab.swps.edu.pl/BIS_2005.pdf</bibtex:url>
</bibtex:inproceedings>
</bibtex:entry>
 
  <!-- manual cleanup may be required... -->
</bibtex:file>
$xml->children('bibtex', true)->asXML() :
Code :
1
2
3
4
5
6
7
8
9
10
11
 
<bibtex:entry id="btxdoc">
<bibtex:manual>
<bibtex:author>Oren Patashnik</bibtex:author>
<bibtex:title>BibTeXing</bibtex:title>
<bibtex:address>BibTeX distribution</bibtex:address>
<bibtex:month>February</bibtex:month>
<bibtex:year>1988</bibtex:year>
<bibtex:url>ftp://sunsite.unc.edu/pub/packages/TeX/biblio/bibtex/distribs/doc/btxdoc.tex</bibtex:url>
</bibtex:manual>
</bibtex:entry>
$xml->count() :
$xml->attributes('bibtex', true)->asXML() :
Donc le problème est que je n'arrive à récupérer que le premier élément de la liste, et je n'arrive pas à saisir comment je dois procéder sans "racine" pour encadrer mes éléments...

Quelqu'un peut m'aider à résoudre ce problème ?

Merci d'avance!
Samax est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2011, 13h27   #2
Modérateur
 
Inscription : septembre 2010
Messages : 7 101
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 101
Points : 8 466
Points : 8 466
la racine c'est bibtex:file
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h54.


 
 
 
 
Partenaires

Hébergement Web