Skip to content
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

Empty text childs increase XML file size #570

Open
Mai1er opened this issue Jun 12, 2023 · 5 comments
Open

Empty text childs increase XML file size #570

Mai1er opened this issue Jun 12, 2023 · 5 comments

Comments

@Mai1er
Copy link

Mai1er commented Jun 12, 2023

// (pseudo code)
xml::node Node = ParentNode.append_child("NewChildNode");
Node.text().set(""); // << create new text-type subchild with no text

// after save document to file we have:
<NewChildNode></NewChildNode>
// but must be (by default output format)
<NewChildNode />
// "virtual" empty text-child lock short form of record

@Mai1er Mai1er added the bug label Jun 12, 2023
@zeux
Copy link
Owner

zeux commented Jun 16, 2023

Sure... why is this a problem? It's not clear to me if changing this is worth the benefit, as the application can just not create empty text children.

@zeux zeux added enhancement and removed bug labels Jun 16, 2023
@Mai1er
Copy link
Author

Mai1er commented Jun 16, 2023

I have text fields assigned by a template, without checking for empty/filled.
There are many fields in the file and often most of them are empty.
This increases the size of the files by 20-30%, and there are... a lot of files on the disk.

Besides, why leave a mistake when you can do better?

@zeux
Copy link
Owner

zeux commented Jun 16, 2023

Ok, and it's impractical for your application to check if the field is empty before assigning? What if the field value is purely white space?

Additionally, if your data has a lot of empty fields and the output size matters, do you need to add the nodes corresponding to empty fields at all? <NewChildNode /> still takes space and you might be able to omit the node entirely.

Overall I'm not entirely sure where the "mistake" is here. Maybe set() shouldn't even create a PCDATA node, or maybe the library works fine; it's an odd corner case.

@Mai1er
Copy link
Author

Mai1er commented Jun 16, 2023

  1. THATS not app side of responsibility
  2. empty fields need by format

@zeux zeux mentioned this issue Aug 25, 2023
8 tasks
@chr-thien
Copy link

This behavior is confusing because:

  1. you create a XML file with empty nodes -> after save with default flags then empty nodes are expanded.
  2. you load that file and save it again with default flags -> empty nodes got compressed.

I found out after comparing files with diff tool.
It is impractical to compare those files using a diff tool.

So in case one wants to have expanded empty nodes then one should use existing format flag format_no_empty_element_tags.
Omitting that flag one would always expect compressed empty nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants