hughsie / libxmlb

A library to help create and query binary XML blobs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Export XML node without children in "collapsed" form?

aleksander0m opened this issue · comments

I'm using xb_node_export() for a node that I know doesn't have any children, and the XML built is in the following format:

<node attr1="val1" attr2="val2"></node>

Is there any way to export the node so that it looks like this instead?

<node attr1="val1" attr2="val2" />

None of the XbNodeExportFlags seem to support this?

For some context, I'm using libxmlb to parse and generate XML transferred from/to the bootloader/programmer of a wwan device and it looks like the embedded XML parser is not very robust...

I guess that makes a lot of sense; would you be able to work on PR for this? I think xb_silo_export_node() in src/xb-silo-export.c should be easy enough to understand; I think g_string_append (helper->xml, ">"); needs some logic to find out if there are any child nodes, and if not close the tag. And if we do that, we shouldn't do the g_string_append_printf (helper->xml, "</%s>", lower down of course. I think doing it unconditionally without an extra flag is probably fine; it's XML afterall.

I already have it,let me push it

@hughsie see #73

I already started to work on it before your comment, and I thought that adding a new flag would make sense. It's XML after all, yes, but in the same way my wwan module doesn't like non-collapsed empty tags, there may be some other interpreter that may not like collapsed empty tags. But whatever you prefer, can remove the flag if you think it's not needed, although then, I would leave the unit test in place making sure the tags without children or text are always collapsed.

I've added a unit test for the export method, I didn't see more unit tests, but it may make sense to add more, not just the ones I added?

Let me know what you think :)