如何在xml中读取标签下另一个标签的属性

How to read attributes of tag under another tag in xml

本文关键字:标签 另一个 属性 读取 xml      更新时间:2023-09-26

我想读取假设subTag1的名称和id的值,目前我能够读取TAG1的属性,但无法读取subTag1的属性。我使用以下代码:

  <TAG1>
<name ='tag1',id='ad'>
<subTAG1>
<name ='abc',id='123'>
<name ='asdfbc',id='143'>
</subTag1>
</TAG1>

    $.ajax({
                    type: "GET",
                    url: dataset,// url from where I am reading xml
                    dataType: "xml",
                    async: false,
                    crossDomain: true,
                    headers: {
                    },
                    success: function (xml) {
                              $(xml).find('TAG1').each(function () {
                                  var dsid = $(this).attr('id');
                                  var dsname = $(this).attr('name');
                              console.log("Dataset id ="+dsid);
                                  console.log("Dataset name ="+dsname);

                        });
相关文章: