2016-04-15 9 views
0
  1. Input: Es ein JSON-Objekt hat, wie "root" Objekt
  2. Ausgang: und jetzt, wie man ein XML-Format wie folgt konvertieren:
  3. Programmsprache, können Sie Knoten verwenden, Java, etc

Eingang json Objekt:Wie json arry konvertiert in node.js in XML

"root" :{ 
    "Yylb": { 
     "Yylb_id": [1,2] 
    }, 
    "Fj": [ 
    { 
     "Fjxx":1 
    }, 
    { 
    "Fjxx":2 
    } 
    ] 
} 

Outpu xml für Matte:

<root> 
    <Yylb> 
     <Yylb_id>1</Yylb_id> 
     <Yylb_id>1</Yylb_id> 
    </Yylb> 
    <Fj> 
     <Fjxx>1</Fjxx> 
    </Fj> 
    <Fj> 
     <Fjxx>2</Fjxx> 
    </Fj> 
</root> 

Antwort

0

Versuchen Sie, diese Node-Modul: https://www.npmjs.com/package/js2xmlparser.

Beispiel:

var js2xmlparser = require("js2xmlparser"); 

var data = { 
    "firstName": "John", 
    "lastName": "Smith" 
}; 

console.log(js2xmlparser("person", data)); 

> <?xml version="1.0" encoding="UTF-8"?> 
> <person> 
>  <firstName>John</firstName> 
>  <lastName>Smith</lastName> 
> </person>