:
$.ajax({
//web service pubblico di prova
url: "*web service*"
type: 'POST',
dataType: "xml",
processData: false,
contentType: "text/xml",
data: soapMessage,
success: function(soapResponse){
//must access the xml tag HERE
var ss= $(soapResponse);
//like this i see all the xml
alert(ss.text());
},
error: function (request, status, error) {
alert(request);
alert(status);
alert(error);
}
});
}
我有一个像这样的xml:
<ROOT>
<ElencoSoggettiTemplate>
<SoggettiTemplate ID="1" Codice="2" Descrizione="aaa" ...>
<SoggettiTemplate ID="2" Codice="3" Descrizione="bbb" ...>
...
</ElencoSoggettiTemplate>
<TOTREC>0</TOTREC>
<PAGECOUNT>0</PAGECOUNT>
</ROOT>
我想要做的就是从SoggettiTemplate获取所有属性,比如ID,Codice
...这样做var alert($(soapResponse.text()))
我可以看到所有结构都像这样soapResponse.getElementsByTagName("ElencoSoggettiTemplate")
我得到的一个HTMLCollection
,但我不能继续,收集计数给我0。
答案 0 :(得分:1)
我解决了这样的事情:
channels: {
UCxxxxxxxxxxx: {
channelId: "xxxx",
channelTitle: "xxxx",
description: "xxxx",
channelId: "xxxx",
title: "xxxx"
},
UCxxxxxxxxxxx: {
channelId: "xxxx",
channelTitle: "xxxx",
description: "xxxx",
channelId: "xxxx",
title: "xxxx"
}
}
答案 1 :(得分:-2)
您必须将XML字符串转换为JS DOM对象,然后将DOM方法应用于xmlDoc。
var xmlob = new DOMParser();
var xmlDoc = xmlob.parseFromString(xml_string,"text/xml");
var tags = xmlDoc.getElementsByTagName('tag_ame');
//...traverse tags with for() instruction
请参阅此页面中的教程:http://coursesweb.net/ajax/ajax-xml
它有一个getElementsByTagName和getAttribute()
的例子