Feature #6938
XML seriliazation improvement
0%
Related issues
History
#1 Updated by Igor Skornyakov over 1 year ago
- Related to Feature #6453: temp-table features added
#2 Updated by Igor Skornyakov over 1 year ago
At this moment the XMLExport
class uses manual formatting of the document based on indent()
/leneBreak()
calls (if formatting is required). In addition, it uses writeStartElement
/writeEndElement
calls and code blocks to ensure the correct matching of these calls.
As a result, the code is quite verbose and is difficult to maintain.
Why not extend XMLStreamWriter so that it will care about indentation itself? This will reduce the number of indent()
/leneBreak()
calls and indent level adjustments dramatically. After all, these actions are required only on writeStartElement
/writeEndElement
calls.
To ensure that elements are properly nested/closed we can add a single method public void writeElement(String name, ElementBuilder elementBuilder)
where ElementBuilder
is a functional interface with a single method (public void build()
).
After that, we can refactor the code moving the logic between writeStartElement
and writeEndElement
calls into a lambda expression and passing it to the writeElement
.
I believe that it will be much less error-prone than the current approach base just on the code formatting because the compiler will validate the document structure.