0
votes

I am developing a mobile app using Ionic2 framework. I need to convert a xml file to json format.

For this I have installed "xml2json" using command "npm install xml2json --save".

This has saved a module named "xml2json" in "node_modules" folder.

I can also see it under dependencies in "package.json" file as "xml2json": "^0.9.1"

Now when I declared it in the .ts file as "import * as xml2json from "xml2json";", I am receiving the following error: "can not find module xml2json"

I guess I need to install the typings for this module. I have tried all the possible typings commands but could not install it. I received errors like

typings ERR! caused by https://api.typings.org/entries/dt/xml2json/versions/latest responded with 404, expected it to equal 200

Please let me know how can I install typings for xml2json OR how can I use xml2json in my project. Thanks.

My system information:

typings version - 1.3.2

Cordova CLI: 6.3.0 Gulp version: CLI version 3.9.1 Gulp local: Local version 3.9.1 Ionic Framework Version: 2.0.0-beta.11 Ionic CLI Version: 2.0.0-beta.36 Ionic App Lib Version: 2.0.0-beta.19 OS: Distributor ID: Ubuntu Description: Ubuntu 16.04 LTS Node Version: v6.3.0

3

3 Answers

0
votes

You can. Just add your node_modules/path_to_xml2json.js to your index.html and declare it in your component : declare var xml2json: any;

It's not a typescript module, so you can import it like you did.

0
votes

You can install the typings for xml2json now using the command

typings install xml2json --save

0
votes

For Parsing xml to json in ionic 2 You can install the typings for xml2json now using the command

typings install xml2json --save

If it generate error like this

'typings' is not recognized as an internal or external command,
operable program or batch file.

Then first use this command to install typing

npm install typings -g

Then run previous command

typings install xml2json --save

Then it'll work fine. Hope it work for you