Skip to content

Keep undefined nodes out of the XML output.#63

Merged
amitguptagwl merged 1 commit intoNaturalIntelligence:masterfrom
HaroldPutman:suppress-undefined
Mar 5, 2018
Merged

Keep undefined nodes out of the XML output.#63
amitguptagwl merged 1 commit intoNaturalIntelligence:masterfrom
HaroldPutman:suppress-undefined

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.

4 participants