Skip to content

Keep undefined nodes out of the XML output. #63

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

Merged

Conversation

HaroldPutman
Copy link
Contributor

This is useful when you are deleting nodes from the JSON and rewriting XML. While I could see a case for writing an empty node in this case (<b/>), I'm fairly certain we never want the current behavior which is <b>undefined</b>.

so if you have:

const obj = {
  house: {
    pet: [
        "cat",
       "spider",
       "dog"]
   }
};
delete obj.house.pet[1]; // get rid of spider!
var result = parser.parse(obj);

You get:

<house>
  <pet>cat</pet>
  <pet>undefined</pet>
  <pet>dog</pet>
</house>

IMO you wanted:

<house>
  <pet>cat</pet>
  <pet>dog</pet>
</house>

This is useful when you are deleting nodes from the JSON and rewriting XML. While I could see a case for writing an empty node in this case (`<b/>`), I'm fairly certain we never want the current behavior which is `<b>undefined</b>`.
@HaroldPutman
Copy link
Contributor Author

(Sorry my editor also got rid of trailing whitespace on some lines)

@coveralls
Copy link

coveralls commented Mar 2, 2018

Coverage Status

Coverage increased (+0.005%) to 99.043% when pulling 007a3a8 on HaroldPutman:suppress-undefined into 7d0a8c5 on NaturalIntelligence:master.

@amitguptagwl
Copy link
Member

Sorry for the late response, it's a festive season here. I will check and merge it on Monday.

@amitguptagwl amitguptagwl merged commit 87c9324 into NaturalIntelligence:master Mar 5, 2018
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

Successfully merging this pull request may close these issues.

None yet

4 participants