[prev in list] [next in list] [prev in thread] [next in thread]
List: calligra-devel
Subject: Re: Using ODF Relax NG schema to generate easier XML writing classes
From: Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date: 2011-06-10 6:30:36
Message-ID: BANLkTimLtb9guPqJNhVOqWbQwaVwgAeOmQ () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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@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@kde.org
> https://mail.kde.org/mailman/listinfo/calligra-devel
>
[Attachment #5 (text/html)]
I like the idea.<br>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.<br><br>
Pierre<br><br><br><div class="gmail_quote">On Fri, Jun 10, 2011 at 8:22 AM, Jos van \
den Oever <span dir="ltr"><<a \
href="mailto:jos.van.den.oever@kogmbh.com">jos.van.den.oever@kogmbh.com</a>></span> \
wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; \
border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Here is an idea to improve code quality in Calligra.<br>
<br>
Currently, we use KoXmlWriter to write ODF XML. For this, functions like<br>
startElement, endElement, addAttribute are used.<br>
<br>
By using the Relax NG schema, we could generate a wrapper around this class<br>
which would give us functions like<br>
<br>
TextPWriter TextContentWriter::startTextP();<br>
void TextHWriter::writeTextOutlineLevel(quint32 level);<br>
<br>
that would wrap around KoXmlWriter or QXmlStreamWriter:<br>
<br>
class TextHWriter {<br>
friend class TextContentWriter;<br>
private:<br>
KoXmlWriter* const xml;<br>
protected:<br>
TextHWriter(KoXmlWriter* xml_) :xml(xml_) {<br>
xml->startElement("text:h");<br>
}<br>
public:<br>
~TextHWriter() { xml->endElement(); }<br>
TextSpan startTextSpan() { return TextSpanWriter(xml); }<br>
void writeTextOutlineLevel(quint32 level) {<br>
xml->setAttribute("text:outline-level", level);<br>
}<br>
};<br>
<br>
These writer classes would all go in header files only and should not affect the<br>
compiled form; the functions are so simple and that they should all be<br>
compiled away.<br>
The classes would provide compile time checking of the code that writes XML.<br>
It would be easier for people to write code to write XML and it would be<br>
harder to make mistakes. When writing serialization code, one would not need<br>
to look up the what attributes can go in which element and what type they<br>
have; your development enviroment would tell you with autocompletion.<br>
<br>
Can you think of a reason why this would not work?<br>
<br>
Cheers,<br>
Jos<br>
<br>
--<br>
<font color="#888888">Jos van den Oever, software architect<br>
<a href="tel:%2B49%20391%2025%2019%2015%2053" value="+4939125191553">+49 391 25 19 15 \
53</a><br> 074 3491911<br>
<a href="http://kogmbh.com/legal/" target="_blank">http://kogmbh.com/legal/</a><br>
_______________________________________________<br>
calligra-devel mailing list<br>
<a href="mailto:calligra-devel@kde.org">calligra-devel@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/calligra-devel" \
target="_blank">https://mail.kde.org/mailman/listinfo/calligra-devel</a><br> \
</font></blockquote></div><br>
_______________________________________________
calligra-devel mailing list
calligra-devel@kde.org
https://mail.kde.org/mailman/listinfo/calligra-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic