从jml中提取的值从xml复杂的模式nodejs / javascript转换而来

时间:2018-04-09 07:59:24

标签: javascript html json node.js xml

您好我从基于肥皂的ui

跟随xml repsonse
<?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:Header>
    <ns1:RequestHeader
         soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
         soapenv:mustUnderstand="0"
         xmlns:ns1="https://www.google.com/apis/ads/publisher/v201802">
      <ns1:networkCode>123456</ns1:networkCode>
      <ns1:applicationName>DfpApi-Java-2.1.0-dfp_test</ns1:applicationName>
    </ns1:RequestHeader>
  </soapenv:Header>
  <soapenv:Body>
    <getAdUnitsByStatement xmlns="https://www.google.com/apis/ads/publisher/v201802">
      <filterStatement>
        <query>WHERE parentId IS NULL LIMIT 500</query>
      </filterStatement>
    </getAdUnitsByStatement>
  </soapenv:Body>
</soapenv:Envelope>

使用xml2js我将其解析为json

var parser=ew xml2js.Parser({explicitArray: false, trim: true});
parser.parseString(bdy, (err, result)=>{
     console.log(util.inspect(result, false, null));

我得到以下json值

 {
  "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:Header": {
      "ns1:RequestHeader": {
        "-xmlns:ns1": "https://www.google.com/apis/ads/publisher/v201802",
        "-soapenv:actor": "http://schemas.xmlsoap.org/soap/actor/next",
        "-soapenv:mustUnderstand": "0",
        "ns1:networkCode": "123456",
        "ns1:applicationName": "DfpApi-Java-2.1.0-dfp_test"
      }
    },
    "soapenv:Body": {
      "getAdUnitsByStatement": {
        "-xmlns": "https://www.google.com/apis/ads/publisher/v201802",
        "filterStatement": { "query": "WHERE parentId IS NULL LIMIT 500" }
      }
    }
  }
}

我要做的是保存单个值以使用它们。例如,我想要

to save 
var t1=-xlmns     
or 
var t2=ns1:networkCode

请让我知道最好的办法...我正在考虑创建json对象,但不知道如何处理这个json ...让我知道最好的方法。

0 个答案:

没有答案