1、webservice 接口返回的xml文件,(利用dom解析后的)
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getMaterialsResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="http://service.ws.*.com/">
<getMaterialsReturn xsi:type="xsd:string">[{"name":"GL201","number":"1202001"}]</getMaterialsReturn>
</ns1:getMaterialsResponse>
</soapenv:Body>
</soapenv:Envelope>
var doc = XMLParser.parseFromString(res.data)
var a = doc.getElementsByTagName('getMaterialsReturn')['0'].childNodes[0].nodeValue;
得到最终结果:
[{"name":"GL201","number":"1202001"}]
//另一个案列-------------------------------------------------------------------------------------------------------------------------------------------------
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>