Using ODF Relax NG schema to generate easier XML writing classes

Jos van den Oever jos at vandenoever.info
Sat Jun 11 23:39:32 BST 2011


On Saturday, June 11, 2011 19:07:52 PM Jos van den Oever wrote:
> Note that this currently will output without the required office:version
> and that text:outline-level in text:h is not part of the constructor atm
> even though it is required.

This is now fixed. I found an error in the example code: i forgot the mimetype. 
Now this code:
===
#include "odf.h"        
#include <QtCore/QBuffer>       
#include <QtCore/QFile> 
int     
main() {
    QFile out;  
    out.open(stdout, QIODevice::WriteOnly);
    KoXmlWriter xml(&out);
    {           
        OfficeDocumentWriter doc(&xml, "application/vnd.oasis.opendocument");
        OfficeBodyWriter content(doc);
        OfficeTextWriter text(content);
        TextHWriter h(text, 1);
        h.addTextNode("Hello ODF!");
        h.end();                        
        TextPWriter p(text);    
        p.writeTextStyleName("bold");
        p.addTextNode("This is paragraph 1.");
        p.end();                
        p = TextPWriter(text);
        p.addTextNode("This is paragraph 2.");
        p.end();
        text.end();
        content.end();
        doc.end();      
    }                   
    out.close();                
    return 0;           
}      
===         
gives this output:
===
<office:document office:version="1.2" 
office:mimetype="application/vnd.oasis.opendocument">
 <office:body>
  <office:text>
   <text:h text:outline-level="1">Hello ODF!</text:h>
   <text:p text:style-name="bold">This is paragraph 1.</text:p>
   <text:p>This is paragraph 2.</text:p>
  </office:text>
 </office:body>
</office:document>
===
The  office:version="1.2" was automatically added since it is always the same 
and required. office:mimetype and text:outline-level had to be specified in the 
constructor because they are required.

Cheers,
Jos

-------------- next part --------------
A non-text attachment was scrubbed...
Name: odf.h.bz2
Type: application/x-bzip
Size: 66220 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/calligra-devel/attachments/20110612/d969c824/attachment.bin>


More information about the calligra-devel mailing list