豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

@coveralls
Copy link
Copy Markdown

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
Copy Markdown
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