6

I tried to install xml2json package for node.js but it gives me error.

Error are as below :enter image description here

My system configuration are as below :

node.js version - v5.4.1

npm version - 3.3.12

Operating system - windows 10 64 bit

python - 2.7.11(set as environment variable )

After installing microsoft windows sdk v7.1 it gives me below error.

enter image description here

After added package.json below error is given.

enter image description here

Keval Trivedi
  • 1,290
  • 2
  • 13
  • 29
  • XML2JSON is just a wrapper around [node-expat](https://www.npmjs.com/package/node-expat) in Windows, so you have to install that first ? – adeneo Jan 21 '16 at 05:27
  • it gives me same error as above while try to install npm install node-expat – Keval Trivedi Jan 21 '16 at 05:32
  • Seems like something to do with the .NET framework, I assume you have this, otherwise you can download it for free from Microsoft. Also, here's a pull for expat that seems related -> https://github.com/node-xmpp/node-expat/issues/57 – adeneo Jan 21 '16 at 05:42
  • .NET framework is there. As per my knowledge windows 10 have inbuilt .NET framework. I found .NET framework in C:/windows/microsoft.NET – Keval Trivedi Jan 21 '16 at 05:47
  • why not to change the library ;) – Amit Kumar Gupta Jan 29 '17 at 12:41

3 Answers3

2

You have to explicitly specify the Platform Toolset when building with msbuild ( triggered by node-gyp rebuild) . Try command below, prior running npm:

call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x64

See meaning of passed arguments below, from SetEnv.cmd Usage:

/Release - Create a Release configuration build environment

/x64 - Create 64-bit x64 applications

Additional explanations

npm install xml2json require using Windows SDK under the hood to build projects, while installing packages, with MSBuild. You have faced situation that your Windows SDK configuration isn't compatible with required by node.

Configuring the Windows SDK Command Prompt Window section:

If you do not have Visual Studio 2010, you can use the Windows SDK Command Prompt window and the SetEnv utility to configure your application build settings.

So my suggestion is to use SetEnv utility to fix your problem ...

Other ways to fix problem

MSBuild uses VCTargetsPath property, which cannot be located because the registry lacks this key.

Check whether key exists and points to proper path

  1. Launch regedit Navigator to HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\WinSDKVersion
  2. Inspect VCTargetsPath key. The value should be "$(MSBuildExtensionsPath64)\Microsoft.Cpp\WinSDKVersion\"

if key doesn't exists or has wrong value, fix problem with steps below:

  1. Launch regedit Navigator to HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\WinSDKVersion
  2. Add string key VCTargetsPath key
  3. Set Value to "$(MSBuildExtensionsPath64)\Microsoft.Cpp\WinSDKVersion\"

WinSDKVersion == v4.0 (Looks like that's value of Your WinSDK Version), so replace WinSDKVersion to v4.0.

Andriy Ivaneyko
  • 20,639
  • 6
  • 60
  • 82
1

I believe you need to set the VCTargetsPath environment variable.

Have a look at the answers to this question, there are a couple of different approaches.

Setting it from the command-line by doing something like this is probably the easiest approach:

set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120"

The exact path will depend on the version of Visual Studio that you have installed.

Community
  • 1
  • 1
sheltond
  • 1,877
  • 11
  • 15
  • it gives the same error as above after set VCTargetsPah through cmd. – Keval Trivedi Jan 28 '16 at 07:30
  • Could you show me the command that you used to set VCTargetsPath, and the contents of the directory? – sheltond Jan 29 '16 at 16:16
  • directly execute above set VCTargetsPath in cmd. and I execute above command in D:/ drive. – Keval Trivedi Feb 01 '16 at 11:09
  • Does the directory "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120" exist? If so, what does it contain? It may be that you need to use a different directory name, depending on the version of the microsoft tools you have installed. – sheltond Feb 01 '16 at 12:10
  • No, MSBuild folder is missing. It is not available in C:\Program Files (x86)\ & C:\Program Files\ – Keval Trivedi Feb 01 '16 at 12:15
1

You have to change your code a bit
Instead of installing xml2json, install xml-js
npm install --save xml-js

and then use this code to convert your xml file to json

let convert = require('xml-js');
let xml = require('fs').readFileSync('./testscenario.xml', 'utf8');

let result = convert.xml2json(xml, {compact: true, spaces: 4});
console.log(result);

It will work

Kunal Tyagi
  • 2,341
  • 1
  • 15
  • 26
  • This is a great option that works very nicely with the caveats that (1) the JSON output is text If you're using the object: true option of xml2json then just stick the output in a JSON.parse() and (2) the output structure isn't exactly the same so if you're doing subsequent parsing you'll find the XML attributes not on the objects themselves but in a ['_attributes'] array. – Richard Wheeldon Feb 18 '23 at 17:26