-
Notifications
You must be signed in to change notification settings - Fork 606
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
Improve roundtrip for some combinations of parser options #461
base: master
Are you sure you want to change the base?
Conversation
1 similar comment
I'll try to add some more test later.... |
This works great and should be merged ! |
if (typeof entry === "object") { | ||
if (Object.keys(entry).length === 1) { | ||
name = Object.keys(entry)[0]; | ||
element = render(element.ele(name), entry[name]).up(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This throws an error for self-closing elements without attributes because entry
for <foo />
looks like:
{
"#name": "foo"
}
I think if ('#name' in entry)
should be checked first.
Can you add round-trip test cases for self-closing elements, both with and without attributes?
I know this PR is super old but I would still love to see it merged! |
The problem I was trying to solve was to parse some XML data, modify it and encode it back, preserving the order of the XML elements.
The parser have options for that (
preserveChildrenOrder
), but the builder is not able to follow the new structure.The PR addresses the object structure, addresses the cases where the
explicitChildren
orpreserveChildrenOrder
options are set. Two new test cases have been added for them.This is done not relying in additional builder options. This way the parser can accept objects produced by parsers with different options.
I've also refactored slightly the builder loop making these metadata keys (
$
,$$
,_
) addressed before going into the key loop (allowing to take the decision of not looking into the remaining redundant keys)