cornelius / kode

XML meta programming
http://www.lst.de/~cs/kode
20 stars 10 forks source link

[kxml_compiler]Simplify the generated code for single sequence child elements #21

Open martonmiklos opened 5 years ago

martonmiklos commented 5 years ago

Hi guys,

I am have an XSD generated code where there are a lot elements which have only have one sequence type child (and no attributes). Example: Library -> Symbols -> Symbol::List

In this example (I think) it would be very convenient if the Symbol::List could be accessed directly from the Library itself. (Currently I access them with

lib->symbols().symbolList() ).

I have implemented it in my simplify_single_child_lists: https://github.com/cornelius/kode/compare/master...martonmiklos:simplify_single_child_lists?expand=1

If you have a bit time and find this feature useful please take a look on it. Any review comment is welcome!

dfaure-kdab commented 5 years ago

I have to ask... how about simplifying the XSD instead? ;-)

Also, this means that if the Symbols element is modified later to gain attributes or other children, the existing code won't compile anymore... which breaks the X in XML (extensible).

martonmiklos commented 5 years ago

Well I am generating code from XSD for an existing XML file format.

If attributes/childs added to the parsed XML the parser (generated with this simplified method) will still parse the XML, just leaving out the new elements/attributes. BTW. the current code has the same scenario.

If new attributes/childs added to the schema the generated code will be the same as it is generated by the current code.

dfaure-kdab commented 5 years ago

What I mean is:

Without the patch, the code is lib->symbols().symbolList() in both cases, so it keeps compiling.

martonmiklos commented 5 years ago

Ah I understand your concern now!

The patch adds this feature together with a command line option (which is disabled by default).

In my use case I am parsing XML files generated with an existing software where the format of the mentioned sections will unlikely to be changed. It might be the case that someone else has the similar needs.

What do you think shall I merge it upstream or not?