Issue
I am working on an angular application which communicate with the API of Prestashop.
I can easily retrieve the list of products ... because Prestashop can return it in the JSON format.
Now I wish to create data ( POST data ) and Prestashop require XML ... Prestashop provide the blank schema, example :
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product>
<id><![CDATA[]]></id>
<id_manufacturer><![CDATA[]]></id_manufacturer>
<id_supplier><![CDATA[]]></id_supplier>
<id_category_default><![CDATA[]]></id_category_default>
<new><![CDATA[]]></new>
Off course I can create the XML with a string but ... is there a better solution to manipulate this type of XML ? Something like :
- Download the blank XML from http://....
- Set value1 ...
- Post the xml
Solution
The full method :
To convert from XML to JSON :
var json = JSON.parse(converter.xml2json(xml_as_string, {compact: true, spaces: 4}));
To convert from json to XML :
var jsonString = JSON.stringify(json);
var xml = converter.json2xml(jsonString, {compact: true, spaces: 4});
The original data is an XML, consequently the XML header is already available.
ty,
Answered By - Jonathan Le Cornichone
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.