Replies: 1 comment
-
|
Apologies for replying so late to issues, I have little time for OSS lately. This can be achieved by filtering nodes without child nodes and removing them, e.g. const obj = {
Users: {
User: {
FirstName: {},
FirstNameEn: {},
MiddleNameEn: {}
}
}
};
const doc = create(obj);
const xml = doc.end({ prettyPrint: true });
console.log(xml);
doc.each(x => {
if (x.node.childElementCount === 0) {
x.node.remove()
}
}, false, true)
const purgedXml = doc.end({ prettyPrint: true });
console.log(purgedXml);Original:
<?xml version="1.0"?>
<Users>
<User>
<FirstName/>
<FirstNameEn/>
<MiddleNameEn/>
</User>
</Users><?xml version="1.0"?>
<Users>
<User/>
</Users> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
is there any way to delete empty tags like this?
The above fields should be skipped or deleted .
Beta Was this translation helpful? Give feedback.
All reactions