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

<?xml version="1.0" encoding="UTF-8"?> repeats for every line #27

Closed
herghost opened this issue Jul 27, 2015 · 2 comments
Closed

<?xml version="1.0" encoding="UTF-8"?> repeats for every line #27

herghost opened this issue Jul 27, 2015 · 2 comments

Comments

@herghost
Copy link

Usage :
var js2xmlparser = require("js2xmlparser");
var params = req.params.all();
var json = params.id;

    var success = 1;

    var xml = js2xmlparser("row",json);
    console.log(xml);

result:

<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<row>
    <user_id>429</user_id>
    <sku_id>1030589</sku_id>
    <qty>0</qty>
    <picklist_id>364720</picklist_id>
</row><row>
    <user_id>429</user_id>
    <sku_id>952656</sku_id>
    <qty>0</qty>
    <picklist_id>364720</picklist_id>
</row><row>
    <user_id>429</user_id>
    <sku_id>903790</sku_id>
    <qty>0</qty>
    <picklist_id>364720</picklist_id>
</row><row>
    <user_id>429</user_id>
    <sku_id>1029530</sku_id>
    <qty>0</qty>
    <picklist_id>364720</picklist_id>
</row><row>
    <user_id>429</user_id>
    <sku_id>998902</sku_id>
    <qty>0</qty>
    <picklist_id>364720</picklist_id>
</row>
@michaelkourlas
Copy link
Owner

XML documents cannot have more than one root element, so an array cannot be the root object that you pass into js2xmlparser (unless you're using the arrayMap functionality).

It's concerning that no error was thrown when you tried to do this, though.

@herghost
Copy link
Author

Apologies, I found a similar issue in the closed issues section and closed this one.
If I parsed the data as JSON then the error appeared, however as I just sent it a String that contained the json data I guess it didn't know. It almost works though! I guess I could have just have done some regex on the xml and replaced the duplicate headers.

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

2 participants