Using ODF Relax NG schema to generate easier XML writing classes

Pierre Stirnweiss pstirnweiss at googlemail.com
Fri Jun 10 07:30:36 BST 2011


I like the idea.
On the headerWriter example you give, the end-element is written when the
Writer gets out of scope. We'd need to verify that all our start/end element
couples are within the same scope however.

Pierre


On Fri, Jun 10, 2011 at 8:22 AM, Jos van den Oever <
jos.van.den.oever at kogmbh.com> wrote:

> Here is an idea to improve code quality in Calligra.
>
> Currently, we use KoXmlWriter to write ODF XML. For this, functions like
> startElement, endElement, addAttribute are used.
>
> By using the Relax NG schema, we could generate a wrapper around this class
> which would give us functions like
>
>  TextPWriter TextContentWriter::startTextP();
>  void TextHWriter::writeTextOutlineLevel(quint32 level);
>
> that would wrap around KoXmlWriter or QXmlStreamWriter:
>
> class TextHWriter {
> friend class TextContentWriter;
> private:
>    KoXmlWriter* const xml;
> protected:
>    TextHWriter(KoXmlWriter* xml_) :xml(xml_) {
>        xml->startElement("text:h");
>    }
> public:
>    ~TextHWriter() { xml->endElement(); }
>    TextSpan startTextSpan() { return TextSpanWriter(xml); }
>    void writeTextOutlineLevel(quint32 level) {
>        xml->setAttribute("text:outline-level", level);
>    }
> };
>
> These writer classes would all go in header files only and should not
> affect the
> compiled form; the functions are so simple and that they should all be
> compiled away.
> The classes would provide compile time checking of the code that writes
> XML.
> It would be easier for people to write code to write XML and it would be
> harder to make mistakes. When writing serialization code, one would not
> need
> to look up the what attributes can go in which element and what type they
> have; your development enviroment would tell you with autocompletion.
>
> Can you think of a reason why this would not work?
>
> Cheers,
> Jos
>
> --
> Jos van den Oever, software architect
> +49 391 25 19 15 53
> 074 3491911
> http://kogmbh.com/legal/
> _______________________________________________
> calligra-devel mailing list
> calligra-devel at kde.org
> https://mail.kde.org/mailman/listinfo/calligra-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/calligra-devel/attachments/20110610/94c3b9f9/attachment.htm>


More information about the calligra-devel mailing list