2016-09-20 144 views
0

我已經展示了下面的Node.js:XML轉換爲字符串轉換

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:axlapi="http://www.cisco.com/AXL/API/10.0"> 
    <soapenv:Header /> 
    <soapenv:Body> 
     <axlapi:listDevicePool> 
       <searchCriteria> 
       <name>%</name> 
       </searchCriteria> 
       <returnedTags> 
       <name/> 

       </returnedTags> 
     </axlapi:listDevicePool> 
    </soapenv:Body> 
</soapenv:Envelope> 

這裏XML文件我想轉換此XMLstring

+2

你到目前爲止嘗試過什麼?你也知道XML實際上是字符串,對嗎?你需要更具體一些,並展示一些努力。 – Molda

回答

0

可以使用xml2js模塊可以輕鬆地將XML轉換成JavaScript對象,然後做它你想要的。

例子:

var parseString = require('xml2js').parseString; 
var xml = "YOUR XML"; 
parseString(xml, function (err, result) { 
    console.dir(result); 
}); 

你有字符串中的XML?在一個文件中?作爲對網絡請求的迴應?如果它不在字符串中,那麼你必須先加載它。