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 :

[AJAX] JSon noeud enfants


Sujet :

JavaScript

  1. #1
    Membre émérite

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

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

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Par défaut [AJAX] JSon noeud enfants
    Bonjour à tous,

    voilà j'ai un petit soucis de compréhension avec JSon.

    Je dois remplir un champ textarea avec certaines données.
    Pour certaines des valeurs je n'ai pas de soucis, mais pour d'autres je n'y arrive pas du tout

    Voici le fichier html avec le code 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
    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
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    <html>
        <head>
            <script type="text/javascript" src="softxmllib.js"></script>
            <script type="text/javascript">
                var http = false;
     
                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 = "1109542.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 xmlRelease = new SoftXMLLib();
                            xmlRelease.loadXML(http.responseText);
     
                            if (xmlRelease.loadXMLError != 0)
                            {
                                alert("XML file is not valid!");
                            }
                            else
                            {
                                form = form + "Artist: ";
                                form = form + getArtists(xmlRelease.selectNodes("/resp/release/artists/artist"));
                                form = form + "\n";
                                form = form + "Album: ";
                                form = form + getAlbum(xmlRelease.selectNodes("/resp/release//title/text()"));
                                form = form + "\n";
                                form = form + "Discogs: ";
                                form = form + getDiscogsLink(xmlRelease.selectNodes("/resp/release"));
                                form = form + "\n";
                                form = form + "Label: ";
                                form = form + getLabel(xmlRelease.selectNodes("/resp/release/labels/label"));
                                form = form + "\n";
                                form = form + "Catalog#: ";
                                form = form + getCatalog(xmlRelease.selectNodes("/resp/release/labels/label"));
                                form = form + "\n";
                                form = form + "Released: ";
                                form = form + getReleased(xmlRelease.selectNodes("/resp/release/released/text()"));
                                form = form + "\n";
                                form = form + "Style: ";
                                form = form + getStyle(xmlRelease.selectNodes("/resp/release/styles/style/text()"));
                                form = form + "\n";
                                form = form + "Quality: ";
                                form = form + "\n\n";
                                form = form + "Tracklist: ";
                                form = form + getTracklist(xmlRelease.selectNodes("/resp/release/tracklist/track"));
                                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(artistNode)
                {
                    var artists = "";
     
                    var nodes = artistNode[0].self.childNodes;
     
                    for (var j = 0; j < nodes.length; j++)
                    {
     
                        var artistName = "";
                        var anv = "";
                        var join = "";
                        var node = nodes[j].childNodes;
     
                        for (var k = 0; k < node.length; k++)
                        {
     
                            var n = node[k];
                            if (n.nodeName == "name")
                            {
                                artistName = n.childNodes[0].nodeValue;
                            }
                            if (n.nodeName == "anv")
                            {
                                anv = n.childNodes[0].nodeValue;
                            }
                            if (n.nodeName == "join")
                            {
                                join = n.childNodes[0].nodeValue;
                            }
                        }
     
                        if (anv.length == 0 && anv == "")
                        {
                            artists = artists + artistName + " ";
                        }
                        else artists = artists + anv + " ";
     
                        if (join.length > 0)
                        {
                            artists = artists + join + " ";
                        }
     
                    }                
                    return artists.replace(/^\s+/g, '').replace(/\s+$/g, '');
                }
     
                function getDiscogsLink(releaseId)
                {
                    return "http://www.discogs.com/release/"+ releaseId[0].attributes[0].id;
                }
     
                function getAlbum(albumNode)
                {
                    return albumNode[0].self.nodeValue;
                }
     
                function getLabel(labelNode)
                {
                    var label = "";
                    for (var i = 0; i < labelNode.length; i++)
                    {
                        label = label + labelNode[i].attributes[0].name + " / ";
                    }
                    return label.substring(0,label.lastIndexOf("/")).replace(/^\s+/g, '').replace(/\s+$/g, '');
                }
     
                function getCatalog(catalogNode)
                {
                    var label = "";
                    for (var i = 0; i < catalogNode.length; i++)
                    {
                        label = label + catalogNode[i].attributes[0].catno + " / ";
                    }
                    return label.substring(0,label.lastIndexOf("/")).replace(/^\s+/g, '').replace(/\s+$/g, '');
                }
     
                function getReleased(releasedNode)
                {
                    return releasedNode[0].self.nodeValue;
                }
     
                function getStyle(styleNode)
                {
                    var style = "";
                    for (var i = 0; i < styleNode.length; i++)
                    {
                        style = style + styleNode[i].self.nodeValue + " / ";
                    }
                    return style.substring(0,style.lastIndexOf("/")).replace(/^\s+/g, '').replace(/\s+$/g, '');
                }
     
                function getTracklist(tracklistNode)
                {
                    var tracklist = "";
                    alert(tracklistNode.length);
                    //alert(matchedTracks[0].self.childNodes[0].childNodes[0].nodeName);
                    //for (var i = 0; i < tracklistNode.length; i++)
                    //{
                        var trackChilds = tracklistNode[0].self.childNodes;
                        var position = '';
                        var artist = '';
                        var title = '';
                        var duration = '';
     
                        for (var j = 0; j < trackChilds.length; j++)
                        {
                            //alert(trackChilds[j].childNodes[0].nodeName);
                            var nodes = trackChilds[j].childNodes;
                            alert(nodes.length);
                            for (var z = 0; z < nodes.length; z++)
                            {
                                var node = nodes[z];
                                if (node.nodeName == "position")
                                {
                                    position = node.childNodes[0].nodeValue;
                                }
                                else if (node.nodeName == "artists")
                                {
                                    var artistNode = node.childNodes;
                                    for (var k = 0; k < artistNode.length; k++)
                                    {
                                        var artistChildNode = artistNode[k].childNodes;
                                        var art = "";
                                        var anv = "";
                                        for (var l = 0; l < artistChildNode.length; l++)
                                        {
                                            if (artistChildNode[l].nodeName == "name")
                                            {
                                                art = artistChildNode[l].childNodes[0].nodeValue;
                                            }
                                            if(artistChildNode[l].nodeName == "anv")
                                            {
                                                anv = artistChildNode[l].childNodes[0].nodeValue;
                                            }
     
                                            artist = artist + (anv.length > 0 ? anv : art) + " / ";
                                        }
                                    }
                                    artist = artist.substring(0, artist.lastIndexOf("/"));
                                }
                                else if (node.nodeName == "title")
                                {
                                    title = node.childNodes[0].nodeValue;
                                }
                                else if (node.nodeName == "duration")
                                {
                                    duration = '(' + node.childNodes[0].nodeValue + ')';
                                }
                            }
                            tracklist = tracklist + position + " " + artist + " - " + title + " " + duration + "\n";
                        }
     
                    //}
                    return tracklist.substring(0,tracklist.lastIndexOf("/")).replace(/^\s+/g, '').replace(/\s+$/g, '');
                    //alert(tracklist);
     
                }
     
     
                function loadRelease()
                {
                    //var urlic = "http://www.torrentech.org/myadmin/discogs.php?id=" + document.getElementById('ajdi').value;
                    http = getHTTPObject();
                    var urlic = "http://10.1.1.29/Torrentech/resources/1506005.xml";
     
                    //ne moze ovo jer se dobija permission denied... ne moze ajax da ucitava nista sto nije sa domena gde je on sam
                    //var urlic = "http://www.discogs.com/release/" + document.getElementById('ajdi').value + "?f=xml&api_key=59d9b19e15";
                    http.open("GET", urlic, true);
                    http.onreadystatechange = function()
                    {
                        if (http.readyState == 4)
                        {
                            if (http.status == 200)
                            {
                                var matchedNodes;
                                var xmlData = new SoftXMLLib();
                                xmlData.load(http.responseXML);
     
                                if (xmlData.loadXMLError != 0)
                                {
                                    alert("XML file is not valid!");
                                }
                                else
                                {
                                    //Artisti:
                                    var xpath = "/resp/release/artists/artist/name/text()";
                                    var form = "Artist: ";
                                    matchedNodes = xmlData.selectNodes(xpath);
                                    var b = matchedNodes.length - 1;
                                    for (var i = 0; i < matchedNodes.length; i++)
                                    {
                                        form = form + matchedNodes[i].self.nodeValue;
                                        //ako nije zadnji element...
                                        if (i != b) form = form + " / ";
                                    }
                                    form = form + "\n";
     
                                    //Album:
                                    xpath = "/resp/release//title/text()";
                                    matchedNodes = xmlData.selectNodes(xpath);
                                    form = form + "Album: " + matchedNodes[0].self.nodeValue + "\n";
     
                                    //Discogs:
                                    xpath = "//resp/release";
                                    matchedNodes = xmlData.selectNodes(xpath);
                                    form = form + "Discogs: http://www.discogs.com/release/" + matchedNodes[0].attributes[0].id + "\n";
                                }
     
                                //Label:
                                xpath = "/resp/release/labels/label";
                                matchedNodes = xmlData.selectNodes(xpath);
                                var b = matchedNodes.length - 1;
                                for (var i = 0; i < matchedNodes.length; i++)
                                {
                                    form = form + "Label: " + matchedNodes[i].attributes[0].name;
                                    //ako nije zadnji element...
                                    if (i != b) form = form + " / ";
                                }
                                form = form + "\n";
     
                                //Catno:
                                matchedNodes = xmlData.selectNodes(xpath);
                                form = form + "Catalog#: " + matchedNodes[0].attributes[0].catno + "\n";
     
                                //Released:
                                xpath = "/resp/release/released/text()";
                                matchedNodes = xmlData.selectNodes(xpath);
                                form = form + "Released: " + matchedNodes[0].self.nodeValue + "\n";
     
                                //Style:
                                var xpath = "/resp/release/styles/style/text()";
                                form = form + "Style: ";
                                matchedNodes = xmlData.selectNodes(xpath);
                                b = matchedNodes.length - 1;
                                for (var i = 0; i < matchedNodes.length; i++)
                                {
                                    form = form + matchedNodes[i].self.nodeValue;
                                    //ako nije zadnji element...
                                    if (i != b) form = form + " / ";
                                }
                                form = form + "\n";
                                form = form + "Quality: " + "\n\n";
     
                                //Tracklist:
                                xpath = "/resp/release/tracklist/track";
                                var tracklist = "";
                                var tempTrack = "";
                                var matchedTracks = xmlData.selectNodes(xpath);
                                alert(matchedTracks.length);
                                //alert(matchedTracks[0].self.childNodes[0].childNodes[0].nodeName);
                                for (var i = 0; i < matchedTracks.length; i++)
                                {
                                    var trackChilds = matchedTracks[i].self.childNodes;
                                    var position = '';
                                    var artist = '';
                                    var title = '';
                                    var duration = '';
     
                                    for (var j = 0; j < trackChilds.length; j++)
                                    {
                                        //alert(trackChilds[j].childNodes[0].nodeName);
                                        var nodes = trackChilds[j].childNodes;
                                        for (var z = 0; z < nodes.length; z++)
                                        {
                                            var node = nodes[z];
                                            if (node.nodeName == "position")
                                            {
                                                position = node.childNodes[0].nodeValue;
                                            }
                                            else if (node.nodeName == "artists")
                                            {
                                                var artistNode = node.childNodes;
                                                for (var k = 0; k < artistNode.length; k++)
                                                {
                                                    var artistChildNode = artistNode[k].childNodes;
                                                    for (var l = 0; l < artistChildNode.length; l++)
                                                    {
                                                        if (artistChildNode[l].nodeName == "name")
                                                        {
                                                            artist = artist + artistChildNode[l].childNodes[0].nodeValue + " / ";
                                                        }
                                                    }
                                                }
                                                artist = artist.substring(0, artist.lastIndexOf("/"));
                                            }
                                            else if (node.nodeName == "title")
                                            {
                                                title = node.childNodes[0].nodeValue;
                                            }
                                            else if (node.nodeName == "duration")
                                            {
                                                duration = '(' + node.childNodes[0].nodeValue + ')';
                                            }
                                        }
                                        tracklist = tracklist + position + " " + artist + " - " + title + " " + duration + "\n";
                                    }
     
                                }
                                form = form + tracklist;
                                alert(form);
                                //alert(tracklist);
     
                            }
                            //od else iz linije 30
                        }
                    }
                    http.send(null);
                }
     
     
            </script>
        </head>
        <body>
            <table>
                <tr><td>
                    <input type="text" id="ajdi" value="2"/>
                    <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>
    Voici le 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
    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>
    Et enfin la librairie (en pièce jointe) qui permet de parser le xml pour le transformer en code lisible par JSon.

    Tout se passe excepté pour la création de la tracklist.

    Voici ce qu'il devrait me retourner

    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
    1.01  	 Ceephax  	Castilian (4:54)
    1.02 	Darqwan 	M/A.. Ximum Reespek (5:37)
    1.03 	Boxcutter 	Good You Dub (4:52)
    1.04 	Gasman, The 	Equino (4:51)
    1.05 	Ital Tek 	Whitemark (4:18)
    1.06 	Parson (2) 	Throw Some Ds (4:41)
    1.07 	Bizzy B & Equinox (3) 	Merda Style 2004 (5:11)
    1.08 	Syntheme 	Finnial (Chevron's Acid Sandwich Bhuna Mix) (3:03)  	  
    1.09 	Venetian Snares 	Devil's Totem (4:23)
    1.10 	Milanese Feat. Anneka 	Reading You (2:26)  	  
    1.11 	Julian Fane 	The Moon Is Gone (4:33)
    1.12 	Dstance 	Fallen (Vex'd Remix) (6:18)  	  
    1.13 	Ambulance 	The Tams (6:19)
    2.01 	Pinch (2) 	Punisher (Loefah's SE25 Remix) (5:36)  	  
    2.02 	Luke Vibert 	Acid Meters (3:45)
    2.03 	FFF 	The Feeling (5:43)
    2.04 	Pinch (2) 	Pepper Spray (4:49)
    2.05 	Shitmat 	Shut Up (Hellfish Remix) (5:41)  	  
    2.06 	Exile & John B 	Broken Language (Exile Mix) (5:38)  	  
    2.07 	Doubtful Guest, The 	Nannita (7:11)
    2.08 	µ-Ziq 	Lexicon (4:16)
    2.09 	Jo Apps 	Kausikan (4:21)
    2.10 	Neil Landstrumm 	Bleep Biopsy (4:36)
    2.11 	Benga 	Broken Dubstep (5:33)
    2.12 	Duran Duran Duran 	Face Blast (3:53)
    2.13 	MRK 1 	Sensi Skank (4:13)
    En exécutant le code vous remarquerez qu'il ne me retourne pas du tout le résultat escompté.

    Si une âme charitable pourrait m'aiguiller, cela serait très gentil.

    D'avance merci pour vos réponses.
    Fichiers attachés Fichiers attachés

  2. #2
    Membre Expert 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
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    tracklist = tracklist + position + " " + artist + " - " + title + " " + duration + "\n";
    position = '';
    artist = '';
    title = '';
    duration = '';
    Tu oublies de réinitialiser tes variables à chaque tour de boucle, du coup les précédentes valeurs sont conservées.

    PS: Ce que tu fais ici, c'est pas du JSON. Ce qu'on appelle JSON c'est un autre mode de transprt qu'xml qui utilise une notation spéciale pour décrire les objets Javascript.

  3. #3
    Membre émérite

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

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

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Par défaut
    Ben justement la librairie softxmllib transforme le xml en objet lisible par JSon.

    Mais je sais aussi que je me mélange les pinceaux entre les requêtes.

    Voici un exemple de ce qu'il me retourne

    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
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    {
    	resp:{
    		stat:'ok',
    		version:1,
    		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
    					},
    					{
    						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
    					}
    				]
    			},
    			artists:{
    				artist:{
    					name:'Various'
    				}
    			},
    			title:'2OO',
    			labels:{
    				label:{
    					catno:'ZIQ200CD',
    					name:'Planet Mu'
    				}
    			},
    			formats:{
    				format:{
    					name:'CDr',
    					qty:2,
    					descriptions:{
    						description:[
    							'Compilation',
    							'Promo',
    							'Album'
    						]
    					}
    				}
    			},
    			genres:{
    				genre:'Electronic'
    			},
    			styles:{
    				style:[
    					'IDM',
    					'Dubstep',
    					'Breakcore',
    					'Acid'
    				]
    			},
    			country:'UK',
    			released:'2007-10-08',
    			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.',
    			tracklist:{
    				track:[
    					{
    						position:1.01,
    						artists:{
    							artist:{
    								name:'Ceephax Acid Crew',
    								anv:'Ceephax'
    							}
    						},
    						title:'Castilian',
    						duration:'4:54'
    					},
    					{
    						position:1.02,
    						artists:{
    							artist:{
    								name:'Darqwan'
    							}
    						},
    						title:'M/A.. Ximum Reespek',
    						duration:'5:37'
    					},
    					{
    						position:1.03,
    						artists:{
    							artist:{
    								name:'Boxcutter'
    							}
    						},
    						title:'Good You Dub',
    						duration:'4:52'
    					},
    					{
    						position:1.04,
    						artists:{
    							artist:{
    								name:'Gasman, The'
    							}
    						},
    						title:'Equino',
    						duration:'4:51'
    					},
    					{
    						position:1.05,
    						artists:{
    							artist:{
    								name:'Ital Tek'
    							}
    						},
    						title:'Whitemark',
    						duration:'4:18'
    					},
    					{
    						position:1.06,
    						artists:{
    							artist:{
    								name:'Parson (2)'
    							}
    						},
    						title:'Throw Some Ds',
    						duration:'4:41'
    					},
    					{
    						position:1.07,
    						artists:{
    							artist:[
    								{
    									name:'Bizzy B',
    									join:'&amp;'
    								},
    								{
    									name:'Equinox (3)'
    								}
    							]
    						},
    						title:'Merda Style 2004',
    						duration:'5:11'
    					},
    					{
    						position:1.08,
    						artists:{
    							artist:{
    								name:'Syntheme'
    							}
    						},
    						title:'Finnial (Chevron\'s Acid Sandwich Bhuna Mix)',
    						extraartists:{
    							artist:{
    								name:'Chevron',
    								role:'Remix'
    							}
    						},
    						duration:'3:03'
    					},
    					{
    						position:1.09,
    						artists:{
    							artist:{
    								name:'Venetian Snares'
    							}
    						},
    						title:'Devil\'s Totem',
    						duration:'4:23'
    					},
    					{
    						position:1.1,
    						artists:{
    							artist:[
    								{
    									name:'Milanese',
    									join:'Feat.'
    								},
    								{
    									name:'Anneka'
    								}
    							]
    						},
    						title:'Reading You',
    						extraartists:{
    							artist:{
    								name:'Anneka',
    								role:'Featuring'
    							}
    						},
    						duration:'2:26'
    					},
    					{
    						position:1.11,
    						artists:{
    							artist:{
    								name:'Julian Fane'
    							}
    						},
    						title:'The Moon Is Gone',
    						duration:'4:33'
    					},
    					{
    						position:1.12,
    						artists:{
    							artist:{
    								name:'DJ Distance',
    								anv:'Distance'
    							}
    						},
    						title:'Fallen (Vex\'d Remix)',
    						extraartists:{
    							artist:{
    								name:'Vex\'d',
    								role:'Remix'
    							}
    						},
    						duration:'6:18'
    					},
    					{
    						position:1.13,
    						artists:{
    							artist:{
    								name:'Ambulance'
    							}
    						},
    						title:'The Tams',
    						duration:'6:19'
    					},
    					{
    						position:2.01,
    						artists:{
    							artist:{
    								name:'Pinch (2)'
    							}
    						},
    						title:'Punisher (Loefah\'s SE25 Remix)',
    						extraartists:{
    							artist:{
    								name:'Loefah',
    								role:'Remix'
    							}
    						},
    						duration:'5:36'
    					},
    					{
    						position:2.02,
    						artists:{
    							artist:{
    								name:'Luke Vibert'
    							}
    						},
    						title:'Acid Meters',
    						duration:'3:45'
    					},
    					{
    						position:2.03,
    						artists:{
    							artist:{
    								name:'FFF'
    							}
    						},
    						title:'The Feeling',
    						duration:'5:43'
    					},
    					{
    						position:2.04,
    						artists:{
    							artist:{
    								name:'Pinch (2)'
    							}
    						},
    						title:'Pepper Spray',
    						duration:'4:49'
    					},
    					{
    						position:2.05,
    						artists:{
    							artist:{
    								name:'Shitmat'
    							}
    						},
    						title:'Shut Up (Hellfish Remix)',
    						extraartists:{
    							artist:{
    								name:'Hellfish',
    								role:'Remix'
    							}
    						},
    						duration:'5:41'
    					},
    					{
    						position:2.06,
    						artists:{
    							artist:[
    								{
    									name:'Tim Exile',
    									anv:'Exile',
    									join:'&amp;'
    								},
    								{
    									name:'John B'
    								}
    							]
    						},
    						title:'Broken Language (Exile Mix)',
    						extraartists:{
    							artist:{
    								name:'Tim Exile',
    								anv:'Exile',
    								role:'Remix'
    							}
    						},
    						duration:'5:38'
    					},
    					{
    						position:2.07,
    						artists:{
    							artist:{
    								name:'Doubtful Guest, The'
    							}
    						},
    						title:'Nannita',
    						duration:'7:11'
    					},
    					{
    						position:2.08,
    						artists:{
    							artist:{
    								name:'µ-Ziq'
    							}
    						},
    						title:'Lexicon',
    						duration:'4:16'
    					},
    					{
    						position:2.09,
    						artists:{
    							artist:{
    								name:'Jo Apps'
    							}
    						},
    						title:'Kausikan',
    						duration:'4:21'
    					},
    					{
    						position:2.1,
    						artists:{
    							artist:{
    								name:'Neil Landstrumm'
    							}
    						},
    						title:'Bleep Biopsy',
    						duration:'4:36'
    					},
    					{
    						position:2.11,
    						artists:{
    							artist:{
    								name:'Benga'
    							}
    						},
    						title:'Broken Dubstep',
    						duration:'5:33'
    					},
    					{
    						position:2.12,
    						artists:{
    							artist:{
    								name:'Duran Duran Duran'
    							}
    						},
    						title:'Face Blast',
    						duration:'3:53'
    					},
    					{
    						position:2.13,
    						artists:{
    							artist:{
    								name:'Mark One',
    								anv:'MRK 1'
    							}
    						},
    						title:'Sensi Skank',
    						duration:'4:13'
    					}
    				]
    			}
    		}
    	}
    }

  4. #4
    Membre Expert 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
    Par défaut
    C'est quoi l'interet d'utiliser du JSON ici (et ou tu le fais d'ailleurs, j'en avais pas vu)?
    Parce que j'ai vu que tu faisais du xpath partout, donc c'est bien que tu manipules du xml nan? (me dit pas que tu fais du xpath sur du json ^^)

  5. #5
    Membre émérite

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

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

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Par défaut
    C'est justement ce que j'indiquais plus haut.

    Je me mélange les pinceaux entre les requêtes xpath et les requêtes json.

    Et c'est en train de m'embrouiller de plus en plus.

    Je suis en train de tout doucement m'énerver avec ces requêtes où je n'y comprends rien.

    Maintenant j'ai une question.

    Prenons par exemple un 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
    <resp stat="ok" version="1.0" requests="7">
        <release id="1506005" status="Accepted">
            <images>
                <image height="484" type="secondary" uri="http://www.discogs.com/image/R-1506005-1224752748.jpeg"
                       uri150="http://www.discogs.com/image/R-150-1506005-1224752748.jpeg" width="482"/>
            </images>
            <artists>
                <artist>
                    <name>Beenie Man</name>
                    <join>&amp;</join>
                </artist>
                <artist>
                    <name>Lukie D</name>
                    <anv>Lukie D.</anv>
                    <join>&amp;</join>
                </artist>
                <artist>
                    <name>Black Pearl (5)</name>
                </artist>
            </artists>
            <title>Bag It Up</title>
            <labels>
                <label catno="none" name="Shocking Vibes"/>
            </labels>
            <extraartists>
                <artist>
                    <name>Shocking Vibes Crew, The</name>
                    <anv>Shocking Vibes Crew</anv>
                    <role>Arranged By</role>
                </artist>
                <artist>
                    <name>Andrew Thomas (2)</name>
                    <role>Mixed By</role>
                </artist>
                <artist>
                    <name>Patrick Roberts</name>
                    <role>Producer</role>
                </artist>
            </extraartists>
            <formats>
                <format name="Vinyl" qty="1">
                    <descriptions>
                        <description>7"</description>
                        <description>45 RPM</description>
                    </descriptions>
                </format>
            </formats>
            <genres>
                <genre>Reggae</genre>
            </genres>
            <styles>
                <style>Dancehall</style>
            </styles>
            <country>Jamaica</country>
            <released>1997</released>
            <notes>etchings in runout grooves:
                DSR ASIDE-19073-BAG IT UP-GEOVANNI
                DSR BSIDE-19074-VER(BAG IT UP)-GEOVANNI
            </notes>
            <tracklist>
                <track>
                    <position>A</position>
                    <title>Bag It Up</title>
                    <duration/>
                </track>
                <track>
                    <position>B</position>
                    <title>Version Instrumental</title>
                    <duration/>
                </track>
            </tracklist>
        </release>
    </resp>
    Si j'utilise un getElementbyTagName("artist"), il va me retourner tous les élements "artist" juste??

    Maintenant comment peut-on différencier les différents tag artist, car certains ne sont pas enfants des même tags.

    Moi par exemple je voudrais récupérer tous les "artist" étant enfant de "artists"
    donc récupérer les /resp/release/tracklist/track/artists/artist et pas les autres.

    Comment dois-je faire?

    Merci beaucoup pour ton aide.

  6. #6
    Membre Expert 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
    Par défaut
    Si j'utilise un getElementbyTagName("artist"), il va me retourner tous les élements "artist" juste??
    Oui ^^

    Maintenant comment peut-on différencier les différents tag artist, car certains ne sont pas enfants des même tags.

    Moi par exemple je voudrais récupérer tous les "artist" étant enfant de "artists"
    donc récupérer les /resp/release/tracklist/track/artists/artist et pas les autres.
    A priori, je vois deux solutions, qui reviennent grosso modo au meme:
    1/ recupérer /resp/release/tracklist/track/artists/, et parcourir ses fils
    2/ récupérer //artist et parcourir seulement les noeuds qui ont pour parent /artists. Comme ca tu élimines ceux qui viennent de //extraartists

  7. #7
    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 : 54
    Localisation : France, Gironde (Aquitaine)

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

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Billets dans le blog
    20
    Par défaut
    Moi par exemple je voudrais récupérer tous les "artist" étant enfant de "artists"
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    getElementsByTagName('artists').getElementsByTagNagName('artist');
    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

  8. #8
    Membre émérite

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

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

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Par défaut
    Je suis désolé de revenir à la charge mais il y a une chose que je ne comprends pas

    voici 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
    <resp stat="ok" version="1.0" requests="7">
        <release id="1506005" status="Accepted">
            <images>
                <image height="484" type="secondary" uri="http://www.discogs.com/image/R-1506005-1224752748.jpeg"
                       uri150="http://www.discogs.com/image/R-150-1506005-1224752748.jpeg" width="482"/>
            </images>
            <artists>
                <artist>
                    <name>Beenie Man</name>
                    <join>&amp;</join>
                </artist>
                <artist>
                    <name>Lukie D</name>
                    <anv>Lukie D.</anv>
                    <join>&amp;</join>
                </artist>
                <artist>
                    <name>Black Pearl (5)</name>
                </artist>
            </artists>
            <title>Bag It Up</title>
            <labels>
                <label catno="none" name="Shocking Vibes"/>
            </labels>
            <extraartists>
                <artist>
                    <name>Shocking Vibes Crew, The</name>
                    <anv>Shocking Vibes Crew</anv>
                    <role>Arranged By</role>
                </artist>
                <artist>
                    <name>Andrew Thomas (2)</name>
                    <role>Mixed By</role>
                </artist>
                <artist>
                    <name>Patrick Roberts</name>
                    <role>Producer</role>
                </artist>
            </extraartists>
            <formats>
                <format name="Vinyl" qty="1">
                    <descriptions>
                        <description>7"</description>
                        <description>45 RPM</description>
                    </descriptions>
                </format>
            </formats>
            <genres>
                <genre>Reggae</genre>
            </genres>
            <styles>
                <style>Dancehall</style>
            </styles>
            <country>Jamaica</country>
            <released>1997</released>
            <notes>etchings in runout grooves:
                DSR ASIDE-19073-BAG IT UP-GEOVANNI
                DSR BSIDE-19074-VER(BAG IT UP)-GEOVANNI
            </notes>
            <tracklist>
                <track>
                    <position>A</position>
                    <title>Bag It Up</title>
                    <duration/>
                </track>
                <track>
                    <position>B</position>
                    <title>Version Instrumental</title>
                    <duration/>
                </track>
            </tracklist>
        </release>
    </resp>
    et voici 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
     <script type="text/javascript">
                var http = false;
     
                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 = "1506005.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 test = http.responseXML.documentElement;
                            form = form + "Artist: ";
                                form = form + getArtists(test);
                                form = form + "\n";
                                form = form + "Album: ";
                                //form = form + getAlbum(xmlRelease.selectNodes("/resp/release//title/text()"));
                                form = form + "\n";
                                form = form + "Discogs: ";
                                form = form + getDiscogsLink(test);
                                form = form + "\n";
                                /*form = form + "Label: ";
                                form = form + getLabel(xmlRelease.selectNodes("/resp/release/labels/label"));
                                form = form + "\n";
                                form = form + "Catalog#: ";
                                form = form + getCatalog(xmlRelease.selectNodes("/resp/release/labels/label"));
                                form = form + "\n";
                                form = form + "Released: ";
                                form = form + getReleased(xmlRelease.selectNodes("/resp/release/released/text()"));
                                form = form + "\n";
                                form = form + "Style: ";
                                form = form + getStyle(xmlRelease.selectNodes("/resp/release/styles/style/text()"));
                                form = form + "\n";
                                form = form + "Quality: ";
                                form = form + "\n\n";
                                form = form + "Tracklist: ";
                                form = form + "\n\n";
                                form = form + getTracklist(xmlRelease.selectNodes("/resp/release/tracklist"));
                                form = form + "\n";
                                document.getElementById("text").value = form;*/
                                //document.getElementById("text").value = JSON.stringify(xmlRelease.selectNodes("/resp/release/tracklist"));
     
     
     
                        }
                        else
                        {
                            alert('Server is too busy or not responding in time; please try again later.');
                        }
     
                }
     
                function getArtists(test)
                {
                    var artists;
                    var artistsNodes = test.getElementsByTagName("artists");
                    alert (artistsNodes.length);
                    for(var i = 0; i < artistsNodes.length; i++)
                    {
                        if(artistsNodes[i].parentNode.tagName == "release")
                        {
                            artists = artistsNodes[i];
                        }
                    }
     
                    var artist = artists.getElementsByTagName("artist")[0].childNodes;
                    alert(artist.length);
     
                    /*var nodes = artistNode[0].self.childNodes;
     
                    for (var j = 0; j < nodes.length; j++)
                    {
     
                        var artistName = "";
                        var anv = "";
                        var join = "";
                        var node = nodes[j].childNodes;
     
                        for (var k = 0; k < node.length; k++)
                        {
     
                            var n = node[k];
                            if (n.nodeName == "name")
                            {
                                artistName = n.childNodes[0].nodeValue;
                            }
                            if (n.nodeName == "anv")
                            {
                                anv = n.childNodes[0].nodeValue;
                            }
                            if (n.nodeName == "join")
                            {
                                join = n.childNodes[0].nodeValue;
                            }
                        }
     
                        if (anv.length == 0 && anv == "")
                        {
                            artists = artists + artistName + " ";
                        }
                        else artists = artists + anv + " ";
     
                        if (join.length > 0)
                        {
                            artists = artists + join + " ";
                        }
     
                    }                
                    return artists.replace(/^\s+/g, '').replace(/\s+$/g, '');*/
                }
     
                function getDiscogsLink(xml)
                {                
                    var releaseId = xml.getElementsByTagName("release")[0].attributes.getNamedItem("id").nodeValue;
                    return "http://www.discogs.com/release/"+ releaseId;
                }</script>
    Comment se fait-il que IE m'affiche 2 dans la méthode getArtists alors que FF m'affiche 5 après la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    artists.getElementsByTagName("artist")[0].childNodes
    .

    Merci pour vos réponses

  9. #9
    Membre Expert 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
    Par défaut
    Parce qu'une des joies du développement web, c'est que les navigateurs ne gèrent pas le DOM exactement de la même facon.

    IE gere le truc de la façon dont on l'attend naturellement, alors que FF va lui te rajouter les noeuds texte qui correspondent à l'indentation de ton fichier (c'est a dire, les \n, les \t, etc...). C'est pour ca que les fonctions comme childNodes, nextSibling et prevSibling sont à manier avec précaution.

  10. #10
    Membre émérite

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

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

    Informations forums :
    Inscription : Avril 2002
    Messages : 795
    Par défaut
    Voilà pourquoi je n'aime pas le développement web

    Je vais marquer le sujet résolu, vu que j'ai recommencé depuis le début les fonctions. Et comme je n'utilise plus JSON, ce topic n'a plus de raison d'être alimenté.

    En tout cas un grand merci pour votre aide.

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

Discussions similaires

  1. Extraire des données JSON par les valeurs d'un noeud enfant
    Par titeuf92 dans le forum Format d'échange (XML, JSON...)
    Réponses: 0
    Dernier message: 21/11/2016, 21h21
  2. Duplication et suppression de noeud enfant en javascript
    Par kalbo dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 23/05/2008, 16h54
  3. [XML] Parser selon des noeuds enfants
    Par GLDavid dans le forum Modules
    Réponses: 5
    Dernier message: 20/08/2004, 20h42
  4. [XSL] aide pour lire un id de noeud enfant.
    Par stebar dans le forum XSL/XSLT/XPATH
    Réponses: 7
    Dernier message: 01/07/2004, 13h38

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