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

JavaScript Discussion :

[Débutant][XML Dom] object is null


Sujet :

JavaScript

  1. #1
    Membre expérimenté

    Homme Profil pro
    Senior Développeur JEE
    Inscrit en
    Avril 2002
    Messages
    795
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Senior Développeur JEE
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Points : 1 660
    Points
    1 660
    Par défaut [Débutant][XML Dom] object is null
    Bonjour à tous,

    voilà j'ai un petit soucis lorsque je souhaite intégrer un xml dans le dom

    Voici le html avec le javascript
    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
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    <html>
        <head>
            <script type="text/javascript">
                var http = false;
                var releaseXML = null;
                function loadXML(xmlFile)
                {
     
                    //load xml file
                    // code for IE
                    if (window.ActiveXObject)
                    {
                        alert("enter loadXML for activeX");
                        releaseXML = new ActiveXObject("Microsoft.XMLDOM");
                        releaseXML.async = false;
                        releaseXML.load(xmlFile);
                    }
                    // code for Mozilla, etc.
                    else if (document.implementation && document.implementation.createDocument)
                    {
                        alert("enter loadXML for gecko");
                        releaseXML = document.implementation.createDocument("", "", null);
                        releaseXML.load(xmlFile);
     
                    }
                    else
                    {
                        alert('Your browser can\'t handle this script');
                    }
                }
     
     
                function getHTTPObject()
                {
                    var xmlhttp = false;
     
                    if (window.ActiveXObject)
                    {
                        try
                        {
                            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                        }
                        catch(e)
                        {
                            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                    }
                    else if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
                    {
                        xmlhttp = new XMLHttpRequest();
                        if (xmlhttp.overrideMimeType)
                            xmlhttp.overrideMimeType('text/xml');
                        if (!xmlhttp)
                            xmlhttp = null;
                    }
     
                    return xmlhttp;
                }
     
                function getNewRelease()
                {
                    var urlic = "96522.xml";
     
                    http = getHTTPObject();
                    http.onreadystatechange = getReleaseInfo;
                    http.open("GET", urlic, true);
                    http.send(null);
                }
     
                function getReleaseInfo()
                {
                    var form = '';
     
                    if (http.readyState == 4)
                    {
                        if (http.status == 200)
                        {
                            var release = http.responseXML;
                            loadXML(release);
                            form = form + "Artist: ";
                            form = form + getArtists(releaseXML.documentElement);
                            form = form + "\n";
                            form = form + "Album: ";
                            form = form + getAlbum(releaseXML);
                            form = form + "\n";
                            form = form + "Discogs: ";
                            form = form + getDiscogsLink(releaseXML.documentElement);
                            form = form + "\n";
                            form = form + "Label: ";
                            form = form + getLabel(releaseXML);
                            form = form + "\n";
                            form = form + "Catalog#: ";
                            form = form + getCatalog(releaseXML);
                            form = form + "\n";
                            form = form + "Released: ";
                            form = form + getReleased(releaseXML);
                            form = form + "\n";
                            form = form + "Style: ";
                            form = form + getStyle(releaseXML);
                            form = form + "\n";
                            form = form + "Quality: ";
                            form = form + "\n\n";
                            form = form + "Tracklist: ";
                            form = form + "\n\n";
                            form = form + getTracklist(releaseXML);
                            form = form + "\n";
                            document.getElementById("text").value = form;
     
     
                        }
                        else
                        {
                            alert('Server is too busy or not responding in time; please try again later.');
                        }
                    }
     
                }
     
                function getArtists(xmlRelease)
                {
                    var artists;
                    var artistsValue = '';
                    var artistsNodes = xmlRelease.getElementsByTagName("artists");
     
                    for (var i = 0; i < artistsNodes.length; i++)
                    {
                        if (artistsNodes[i].parentNode.tagName == "release")
                        {
                            artists = artistsNodes[i].getElementsByTagName("artist");
     
     
                            for (var j = 0; j < artists.length; j++)
                            {
                                var name = '';
                                var anv = '';
                                var join = '';
                                name = artists[j].getElementsByTagName("name")[0].firstChild.data;
                                if (artists[j].getElementsByTagName("anv")[0])
                                    anv = artists[j].getElementsByTagName("anv")[0].firstChild.data;
                                if (artists[j].getElementsByTagName("join")[0])
                                    join = artists[j].getElementsByTagName("join")[0].firstChild.data;
     
                                artistsValue = artistsValue + " " + (anv.length > 0 ? anv : name) + " " + (join.length > 0 ? join : '');
                            }
     
                        }
                    }
     
                    return artistsValue.replace(/^\s+/g, '').replace(/\s+$/g, '');
                }
     
                function getDiscogsLink(xmlRelease)
                {
                    var releaseId = xmlRelease.getElementsByTagName("release")[0].attributes.getNamedItem("id").nodeValue;
                    return "http://www.discogs.com/release/"+ releaseId;                
                }
     
                function getAlbum(xmlRelease)
                {
                    var titles = xmlRelease.getElementsByTagName("title");
                    var title = '';
                    for (var i = 0; i < titles.length; i++)
                    {
                        if (titles[i].parentNode.tagName == "release")
                        {
                            title = titles[i].firstChild.data;
                        }
                    }
     
                    return title;
                }
     
                function getLabel(xmlRelease)
                {
                    var labels = xmlRelease.getElementsByTagName("labels");
                    var labelValue = '';
                    var label = '';
                    for (var i = 0; i < labels.length; i++)
                    {
                        label = labels[i].getElementsByTagName("label");
                        for (var j = 0; j < label.length; j++)
                        {
                            labelValue = labelValue + label[j].attributes.getNamedItem("name").nodeValue + " / ";
                        }
                    }
     
                    return labelValue.substring(0, labelValue.lastIndexOf("/")).replace(/^\s+/g, '').replace(/\s+$/g, '');
                }
     
                function getCatalog(xmlRelease)
                {
                    var labels = xmlRelease.getElementsByTagName("labels");
                    var catalog = '';
                    var catalogValue = '';
                    for (var i = 0; i < labels.length; i++)
                    {
                        catalog = labels[i].getElementsByTagName("label");
                        for (var j = 0; j < catalog.length; j++)
                        {
                            catalogValue = catalogValue + catalog[j].attributes.getNamedItem("catno").nodeValue + " / ";
                        }
                    }
     
                    return catalogValue.substring(0, catalogValue.lastIndexOf("/")).replace(/^\s+/g, '').replace(/\s+$/g, '');
                }
     
                function getReleased(xmlRelease)
                {
                    if (xmlRelease.getElementsByTagName("released")[0] && xmlRelease.getElementsByTagName("released")[0].firstChild != null)
                        return xmlRelease.getElementsByTagName("released")[0].firstChild.data;
                    else return '';
                }
     
                function getStyle(xmlRelease)
                {
                    var styles = xmlRelease.getElementsByTagName("styles");
                    var style = '';
                    var styleValue = '';
                    for (var i = 0; i < styles.length; i++)
                    {
                        style = styles[i].getElementsByTagName("style");
                        for (var j = 0; j < style.length; j++)
                        {
                            styleValue = styleValue + style[j].firstChild.data + " / ";
                        }
                    }
                    return styleValue.substring(0, styleValue.lastIndexOf("/")).replace(/^\s+/g, '').replace(/\s+$/g, '');
                }
     
                function getTracklist(xmlRelease)
                {
                    var tracks = xmlRelease.getElementsByTagName("track");
                    var tracklist = '';
     
                    for (var i = 0; i < tracks.length; i++)
                    {
                        var position = tracks[i].getElementsByTagName("position")[0].firstChild.data;
                        var artists = tracks[i].getElementsByTagName("artists");
                        var artist = '';
                        var artistValue = '';
                        for (var j = 0; j < artists.length; j++)
                        {
                            artist = artists[j].getElementsByTagName("artist");
     
                            for (var k = 0; k < artist.length; k++)
                            {
                                var name = '';
                                var anv = '';
                                var join = '';
                                name = artist[k].getElementsByTagName("name")[0].firstChild.data;
                                if (artist[k].getElementsByTagName("anv")[0])
                                    anv = artist[k].getElementsByTagName("anv")[0].firstChild.data;
                                if (artist[k].getElementsByTagName("join")[0])
                                    join = artist[k].getElementsByTagName("join")[0].firstChild.data;
     
                                artistValue = artistValue + (anv.length > 0 ? anv : name) + " " + (join.length > 0 ? " " + join + " " : " / ");
                            }
                        }
                        artistValue = artistValue.substring(0, artistValue.lastIndexOf("/")).replace(/^\s+/g, '').replace(/\s+$/g, '');
                        var title = tracks[i].getElementsByTagName("title")[0].firstChild.data;
                        var duration = '';
                        if (tracks[i].getElementsByTagName("duration")[0] && tracks[i].getElementsByTagName("duration")[0].firstChild != null)
                            duration = "(" + tracks[i].getElementsByTagName("duration")[0].firstChild.data + ")";
     
                        tracklist = tracklist + position + " " + artistValue + (artistValue.length > 0 ? " - " : "") + title + " " + duration + "\n";
                    }
                    return tracklist;
                }
            </script>
        </head>
        <body>
            <table>
                <tr><td>
                    <input type="text" id="ajdi" value=""/>
                    <input type="button" onclick="getNewRelease()" name="submitId" value="populate from Discogs"/>
                </td><td></td></tr>
                <tr><td colspan="2"><textarea rows="40" cols="100" id="text"></textarea></td></tr>
            </table>
     
     
            <div id="foo">
     
            </div>
        </body>
     
    </html>
    Et voici enfin le 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
    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
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    <?xml version="1.0" encoding="utf-8"?>
    <!-- Created with Liquid XML Studio 1.0.8.0 (http://www.liquid-technologies.com) -->
    <resp stat="ok" version="1.0" requests="4">
    	<release id="1109542" status="Accepted">
    		<images>
    			<image height="600" type="primary" uri="http://www.discogs.com/image/R-1109542-1192735422.jpeg" uri150="http://www.discogs.com/image/R-150-1109542-1192735422.jpeg" width="581" />
    			<image height="600" type="secondary" uri="http://www.discogs.com/image/R-1109542-1192735435.jpeg" uri150="http://www.discogs.com/image/R-150-1109542-1192735435.jpeg" width="580" />
    		</images>
    		<artists>
    			<artist>
    				<name>Various</name>
    			</artist>
    		</artists>
    		<title>2OO</title>
    		<labels>
    			<label catno="ZIQ200CD" name="Planet Mu" />
    		</labels>
    		<formats>
    			<format name="CDr" qty="2">
    				<descriptions>
    					<description>Compilation</description>
    					<description>Promo</description>
    					<description>Album</description>
    				</descriptions>
    			</format>
    		</formats>
    		<genres>
    			<genre>Electronic</genre>
    		</genres>
    		<styles>
    			<style>IDM</style>
    			<style>Dubstep</style>
    			<style>Breakcore</style>
    			<style>Acid</style>
    		</styles>
    		<country>UK</country>
    		<released>2007-10-08</released>
    		<notes>Celebrating Planet Mu's 10th birthday and 200th release. In PVC slipcase with printed insert.CD1/CD2 written on CD-R's in marker pen.</notes>
    		<tracklist>
    			<track>
    				<position>1.01</position>
    				<artists>
    					<artist>
    						<name>Ceephax Acid Crew</name>
    						<anv>Ceephax</anv>
    					</artist>
    				</artists>
    				<title>Castilian</title>
    				<duration>4:54</duration>
    			</track>
    			<track>
    				<position>1.02</position>
    				<artists>
    					<artist>
    						<name>Darqwan</name>
    					</artist>
    				</artists>
    				<title>M/A.. Ximum Reespek</title>
    				<duration>5:37</duration>
    			</track>
    			<track>
    				<position>1.03</position>
    				<artists>
    					<artist>
    						<name>Boxcutter</name>
    					</artist>
    				</artists>
    				<title>Good You Dub</title>
    				<duration>4:52</duration>
    			</track>
    			<track>
    				<position>1.04</position>
    				<artists>
    					<artist>
    						<name>Gasman, The</name>
    					</artist>
    				</artists>
    				<title>Equino</title>
    				<duration>4:51</duration>
    			</track>
    			<track>
    				<position>1.05</position>
    				<artists>
    					<artist>
    						<name>Ital Tek</name>
    					</artist>
    				</artists>
    				<title>Whitemark</title>
    				<duration>4:18</duration>
    			</track>
    			<track>
    				<position>1.06</position>
    				<artists>
    					<artist>
    						<name>Parson (2)</name>
    					</artist>
    				</artists>
    				<title>Throw Some Ds</title>
    				<duration>4:41</duration>
    			</track>
    			<track>
    				<position>1.07</position>
    				<artists>
    					<artist>
    						<name>Bizzy B</name>
    						<join>&amp;</join>
    					</artist>
    					<artist>
    						<name>Equinox (3)</name>
    					</artist>
    				</artists>
    				<title>Merda Style 2004</title>
    				<duration>5:11</duration>
    			</track>
    			<track>
    				<position>1.08</position>
    				<artists>
    					<artist>
    						<name>Syntheme</name>
    					</artist>
    				</artists>
    				<title>Finnial (Chevron's Acid Sandwich Bhuna Mix)</title>
    				<extraartists>
    					<artist>
    						<name>Chevron</name>
    						<role>Remix</role>
    					</artist>
    				</extraartists>
    				<duration>3:03</duration>
    			</track>
    			<track>
    				<position>1.09</position>
    				<artists>
    					<artist>
    						<name>Venetian Snares</name>
    					</artist>
    				</artists>
    				<title>Devil's Totem</title>
    				<duration>4:23</duration>
    			</track>
    			<track>
    				<position>1.10</position>
    				<artists>
    					<artist>
    						<name>Milanese</name>
    						<join>Feat.</join>
    					</artist>
    					<artist>
    						<name>Anneka</name>
    					</artist>
    				</artists>
    				<title>Reading You</title>
    				<extraartists>
    					<artist>
    						<name>Anneka</name>
    						<role>Featuring</role>
    					</artist>
    				</extraartists>
    				<duration>2:26</duration>
    			</track>
    			<track>
    				<position>1.11</position>
    				<artists>
    					<artist>
    						<name>Julian Fane</name>
    					</artist>
    				</artists>
    				<title>The Moon Is Gone</title>
    				<duration>4:33</duration>
    			</track>
    			<track>
    				<position>1.12</position>
    				<artists>
    					<artist>
    						<name>DJ Distance</name>
    						<anv>Distance</anv>
    					</artist>
    				</artists>
    				<title>Fallen (Vex'd Remix)</title>
    				<extraartists>
    					<artist>
    						<name>Vex'd</name>
    						<role>Remix</role>
    					</artist>
    				</extraartists>
    				<duration>6:18</duration>
    			</track>
    			<track>
    				<position>1.13</position>
    				<artists>
    					<artist>
    						<name>Ambulance</name>
    					</artist>
    				</artists>
    				<title>The Tams</title>
    				<duration>6:19</duration>
    			</track>
    			<track>
    				<position>2.01</position>
    				<artists>
    					<artist>
    						<name>Pinch (2)</name>
    					</artist>
    				</artists>
    				<title>Punisher (Loefah's SE25 Remix)</title>
    				<extraartists>
    					<artist>
    						<name>Loefah</name>
    						<role>Remix</role>
    					</artist>
    				</extraartists>
    				<duration>5:36</duration>
    			</track>
    			<track>
    				<position>2.02</position>
    				<artists>
    					<artist>
    						<name>Luke Vibert</name>
    					</artist>
    				</artists>
    				<title>Acid Meters</title>
    				<duration>3:45</duration>
    			</track>
    			<track>
    				<position>2.03</position>
    				<artists>
    					<artist>
    						<name>FFF</name>
    					</artist>
    				</artists>
    				<title>The Feeling</title>
    				<duration>5:43</duration>
    			</track>
    			<track>
    				<position>2.04</position>
    				<artists>
    					<artist>
    						<name>Pinch (2)</name>
    					</artist>
    				</artists>
    				<title>Pepper Spray</title>
    				<duration>4:49</duration>
    			</track>
    			<track>
    				<position>2.05</position>
    				<artists>
    					<artist>
    						<name>Shitmat</name>
    					</artist>
    				</artists>
    				<title>Shut Up (Hellfish Remix)</title>
    				<extraartists>
    					<artist>
    						<name>Hellfish</name>
    						<role>Remix</role>
    					</artist>
    				</extraartists>
    				<duration>5:41</duration>
    			</track>
    			<track>
    				<position>2.06</position>
    				<artists>
    					<artist>
    						<name>Tim Exile</name>
    						<anv>Exile</anv>
    						<join>&amp;</join>
    					</artist>
    					<artist>
    						<name>John B</name>
    					</artist>
    				</artists>
    				<title>Broken Language (Exile Mix)</title>
    				<extraartists>
    					<artist>
    						<name>Tim Exile</name>
    						<anv>Exile</anv>
    						<role>Remix</role>
    					</artist>
    				</extraartists>
    				<duration>5:38</duration>
    			</track>
    			<track>
    				<position>2.07</position>
    				<artists>
    					<artist>
    						<name>Doubtful Guest, The</name>
    					</artist>
    				</artists>
    				<title>Nannita</title>
    				<duration>7:11</duration>
    			</track>
    			<track>
    				<position>2.08</position>
    				<artists>
    					<artist>
    						<name>µ-Ziq</name>
    					</artist>
    				</artists>
    				<title>Lexicon</title>
    				<duration>4:16</duration>
    			</track>
    			<track>
    				<position>2.09</position>
    				<artists>
    					<artist>
    						<name>Jo Apps</name>
    					</artist>
    				</artists>
    				<title>Kausikan</title>
    				<duration>4:21</duration>
    			</track>
    			<track>
    				<position>2.10</position>
    				<artists>
    					<artist>
    						<name>Neil Landstrumm</name>
    					</artist>
    				</artists>
    				<title>Bleep Biopsy</title>
    				<duration>4:36</duration>
    			</track>
    			<track>
    				<position>2.11</position>
    				<artists>
    					<artist>
    						<name>Benga</name>
    					</artist>
    				</artists>
    				<title>Broken Dubstep</title>
    				<duration>5:33</duration>
    			</track>
    			<track>
    				<position>2.12</position>
    				<artists>
    					<artist>
    						<name>Duran Duran Duran</name>
    					</artist>
    				</artists>
    				<title>Face Blast</title>
    				<duration>3:53</duration>
    			</track>
    			<track>
    				<position>2.13</position>
    				<artists>
    					<artist>
    						<name>Mark One</name>
    						<anv>MRK 1</anv>
    					</artist>
    				</artists>
    				<title>Sensi Skank</title>
    				<duration>4:13</duration>
    			</track>
    		</tracklist>
    	</release>
    </resp>
    L'erreur retournée est que xmlRelease (paramètre de la fonction getArtist()) est null.

    Je ne comprends pas pourquoi. Mais comme je suis débutant je suppose que je fais une grosse boulette au moment de passer le xml dans l'arbre DOM.

    Et je suis obligé de passer par loadxml sinon le script ne marche pas sous IE.

    D'avance merci pour vos réponses.
    Langages : Java, SQL
    Outils : Eclipse, Intellij
    SGBD : Oracle, PostgreSQL
    Mes Articles

  2. #2
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Points : 91 220
    Points
    91 220
    Billets dans le blog
    20
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    var release = http.responseXML;
    loadXML(release);
    form = form + "Artist: ";
    form = form + getArtists(releaseXML.documentElement);
    Erreur de variable dans l'appel de la fonction ?
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  3. #3
    Membre expérimenté

    Homme Profil pro
    Senior Développeur JEE
    Inscrit en
    Avril 2002
    Messages
    795
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Senior Développeur JEE
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Points : 1 660
    Points
    1 660
    Par défaut
    Euh je ne pense pas, puisque tout en haut du script tu trouve la variable releaseXML. C'est cette variable que j'initialise et j'utilise par la suite.

    Merci quand même pour ton aide. Si tu as une autre idée elle est la bienvenue.
    Langages : Java, SQL
    Outils : Eclipse, Intellij
    SGBD : Oracle, PostgreSQL
    Mes Articles

  4. #4
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Points : 91 220
    Points
    91 220
    Billets dans le blog
    20
    Par défaut
    Euh, si :
    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
    if (window.ActiveXObject)
                    {
                        alert("enter loadXML for activeX");
                        releaseXML = new ActiveXObject("Microsoft.XMLDOM");
                        releaseXML.async = false;
                        releaseXML.load(xmlFile);
                    }
                    // code for Mozilla, etc.
                    else if (document.implementation && document.implementation.createDocument)
                    {
                        alert("enter loadXML for gecko");
                        releaseXML = document.implementation.createDocument("", "", null);
                        releaseXML.load(xmlFile);
     
                    }
    releaseXML est un objet, pas un document XML, donc :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    form = form + getArtists(releaseXML.documentElement);
    releaseXML.documentElement est null puisque documentElement n'est pas une propriété de ActiveXObject !
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

  5. #5
    Membre expérimenté

    Homme Profil pro
    Senior Développeur JEE
    Inscrit en
    Avril 2002
    Messages
    795
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Senior Développeur JEE
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Points : 1 660
    Points
    1 660
    Par défaut
    Je dois passer comme paramètre la variable 'release' alors??

    Parce que si je fais ça cela ne marche pas non plus.

    Peux-tu me dire si mon code javascript est standard pour tous les browsers??

    Parce que si j'utilise la variable release comme paramètre, internet explorer ne me retourne aucune erreur mais il ne me trouve aucune information non plus.

    Merci beaucoup
    Langages : Java, SQL
    Outils : Eclipse, Intellij
    SGBD : Oracle, PostgreSQL
    Mes Articles

  6. #6
    Membre expérimenté Avatar de DoubleU
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    1 106
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 1 106
    Points : 1 388
    Points
    1 388
    Par défaut
    Peux-tu me dire si mon code javascript est standard pour tous les browsers??
    Ca ne marchera pas sous Webkit (safari + chrome) ca :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
                    if (window.ActiveXObject)
                    {
                        alert("enter loadXML for activeX");
                        releaseXML = new ActiveXObject("Microsoft.XMLDOM");
                        releaseXML.async = false;
                        releaseXML.load(xmlFile);
                    }
                    // code for Mozilla, etc.
                    else if (document.implementation && document.implementation.createDocument)
                    {
                        alert("enter loadXML for gecko");
                        releaseXML = document.implementation.createDocument("", "", null);
                        releaseXML.load(xmlFile);
    Edit: la façon crossbrowser de charger un fichier xml pour ensuite le traiter est de le charger via XmlHTTPRequest, de récupérer le responseText, et ensuite parser ce texte pour créer un document xml.

    Sous IE:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async="false";
    xmlDoc.loadXML(xhr.responseText);
    Sous les autres navigateurs:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    parser=new DOMParser();
    xmlDoc=parser.parseFromString(xhr.responseText,"text/xml");
    Note bien que le xmlDoc que tu récupères correspond au document XML, le noeud racine est accessible via xmlDoc.documentElement.

  7. #7
    Membre expérimenté

    Homme Profil pro
    Senior Développeur JEE
    Inscrit en
    Avril 2002
    Messages
    795
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : Senior Développeur JEE
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Points : 1 660
    Points
    1 660
    Par défaut
    Ouiiiiiiiiiiii ça marche.

    Impeccable.

    Donc la technique c'est d'utiliser le xhr.responseText et de reparser le document texte en xml.

    Au moins j'en apprends tous les jours

    Merci beaucoup pour votre aide à tous les deux.
    Langages : Java, SQL
    Outils : Eclipse, Intellij
    SGBD : Oracle, PostgreSQL
    Mes Articles

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

Discussions similaires

  1. XML signature, DOM et noeuds null
    Par Saita dans le forum Format d'échange (XML, JSON...)
    Réponses: 5
    Dernier message: 30/06/2010, 11h01
  2. [débutant] XML<=>MDB (Access)
    Par francki51 dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 30/05/2004, 18h37
  3. [Débutant] java.lang.object
    Par bonnefr dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 27/05/2004, 14h54
  4. XML DOM et gros fichiers
    Par Manu_Just dans le forum APIs
    Réponses: 4
    Dernier message: 28/03/2003, 09h50
  5. Débutant XML
    Par viny dans le forum XML/XSL et SOAP
    Réponses: 8
    Dernier message: 25/07/2002, 12h07

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