Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent mapping of XML to JS #69

Open
mellis481 opened this issue Aug 7, 2018 · 1 comment
Open

Inconsistent mapping of XML to JS #69

mellis481 opened this issue Aug 7, 2018 · 1 comment

Comments

@mellis481
Copy link

mellis481 commented Aug 7, 2018

I have XML which contains a Purchase which has an optional attribute called purchaseClass.

So the XML could look like this:

<Purchase purchaseClass="Test_Class">Test_Purchase</Purchase>

or this:
Test_Purchase

I'm using the following code to convert the above XML string into JS:

const options: X2JS.Options = { };
const x2js = new X2JS(options);
const obj = x2js.xml2js(xml);

This works as expected when the purchaseClass attribute and the inner text is specified. The resulting converted JS object looks like this:

Purchase:  {
   _purchaseClass: 'Test_Class',
   __text: 'Test_Purchase'
}

The problem occurs if purchaseClass is not included. In this case, the converted javascript object looks like this, where the Purchase property is a string rather than an object:

Purchase: 'Test_Purchase'

Here is the example, where the purchaseClass property is optional.

arrayAccessForm is a config property that allows you to identify arrays in your XML. Is there a similar concept for objects with optional properties to avoid having the issue described above?

@mellis481
Copy link
Author

This is a huge issue for this library. Unless x2js is in maintenance mode, the author needs to address this ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant