libmobi
C library for handling MOBI format ebook documents
Macros | Functions
xmlwriter.c File Reference

Implements a simplified subset of libxml2 functions used in libmobi. More...

#include <stdlib.h>
#include <string.h>
#include "xmlwriter.h"
#include "debug.h"
#include "util.h"
#include "parse_rawml.h"

Macros

#define _GNU_SOURCE   1
 
#define __USE_BSD   /* for strdup on linux/glibc */
 
#define MOBI_XML_BUFFERSIZE   4096
 
#define MOBI_XML_STATESSIZE   200
 
#define XML_ERROR   -1
 
#define XML_OK   0
 

Functions

xmlBufferPtr xmlBufferCreate (void)
 Create xml buffer. More...
 
void xmlBufferFree (xmlBufferPtr buf)
 Free XML buffer. More...
 
xmlTextWriterPtr xmlNewTextWriterMemory (xmlBufferPtr xmlbuf, int compression)
 Initialize TextWriter structure. More...
 
void xmlFreeTextWriter (xmlTextWriterPtr writer)
 Deallocate TextWriter instance and all its resources. More...
 
int xmlTextWriterStartDocument (xmlTextWriterPtr writer, const char *version, const char *encoding, const char *standalone)
 Start xml document. More...
 
int xmlTextWriterEndDocument (xmlTextWriterPtr writer)
 End xml document. More...
 
int xmlTextWriterStartElement (xmlTextWriterPtr writer, const xmlChar *name)
 Start xml element. More...
 
int xmlTextWriterEndElement (xmlTextWriterPtr writer)
 End current element. More...
 
int xmlTextWriterStartAttribute (xmlTextWriterPtr writer, const xmlChar *name)
 Start attribute for current xml element. More...
 
int xmlTextWriterEndAttribute (xmlTextWriterPtr writer)
 End current attribute. More...
 
int xmlTextWriterWriteAttribute (xmlTextWriterPtr writer, const xmlChar *name, const xmlChar *content)
 Write attribute with given name and content. More...
 
int xmlTextWriterStartAttributeNS (xmlTextWriterPtr writer, const xmlChar *prefix, const xmlChar *name, const xmlChar *namespaceURI)
 Start attribute with namespace support for current xml element. More...
 
int xmlTextWriterWriteAttributeNS (xmlTextWriterPtr writer, const xmlChar *prefix, const xmlChar *name, const xmlChar *namespaceURI, const xmlChar *content)
 Write attribute with namespace support. More...
 
int xmlTextWriterStartElementNS (xmlTextWriterPtr writer, const xmlChar *prefix, const xmlChar *name, const xmlChar *namespaceURI)
 Start element with namespace support. More...
 
int xmlTextWriterWriteElementNS (xmlTextWriterPtr writer, const xmlChar *prefix, const xmlChar *name, const xmlChar *namespaceURI, const xmlChar *content)
 Write element with namespace support. More...
 
int xmlTextWriterWriteString (xmlTextWriterPtr writer, const xmlChar *content)
 Write xml string. More...
 
int xmlTextWriterSetIndent (xmlTextWriterPtr writer, int indent)
 Set indentation option. More...
 

Detailed Description

Implements a simplified subset of libxml2 functions used in libmobi.

Copyright (c) 2016 Bartek Fabiszewski http://www.fabiszewski.net

This file is part of libmobi. Licensed under LGPL, either version 3, or any later. See http://www.gnu.org/licenses/

Function Documentation

◆ xmlBufferCreate()

xmlBufferPtr xmlBufferCreate ( void  )

Create xml buffer.

Libxml2 compatibility wrapper for MOBIBuffer structure. Must be deallocated with xmlBufferFree

Returns
Buffer pointer

◆ xmlBufferFree()

void xmlBufferFree ( xmlBufferPtr  buf)

Free XML buffer.

Parameters
[in,out]bufXML buffer

◆ xmlFreeTextWriter()

void xmlFreeTextWriter ( xmlTextWriterPtr  writer)

Deallocate TextWriter instance and all its resources.

Parameters
[in,out]writerTextWriter

◆ xmlNewTextWriterMemory()

xmlTextWriterPtr xmlNewTextWriterMemory ( xmlBufferPtr  xmlbuf,
int  compression 
)

Initialize TextWriter structure.

Parameters
[in]xmlbufInitialized xml output buffer
[in]compressionUnused
Returns
TextWriter pointer

◆ xmlTextWriterEndAttribute()

int xmlTextWriterEndAttribute ( xmlTextWriterPtr  writer)

End current attribute.

Parameters
[in,out]writerTextWriter
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterEndDocument()

int xmlTextWriterEndDocument ( xmlTextWriterPtr  writer)

End xml document.

All open elements will be closed. xmlBuffer will be flushed.

Parameters
[in]writerTextWriter
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterEndElement()

int xmlTextWriterEndElement ( xmlTextWriterPtr  writer)

End current element.

Parameters
[in]writerTextWriter
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterSetIndent()

int xmlTextWriterSetIndent ( xmlTextWriterPtr  writer,
int  indent 
)

Set indentation option.

Parameters
[in,out]writerTextWriter
[in]indentIndent output if value greater than zero
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterStartAttribute()

int xmlTextWriterStartAttribute ( xmlTextWriterPtr  writer,
const xmlChar *  name 
)

Start attribute for current xml element.

Parameters
[in,out]writerTextWriter
[in]nameAttribute name
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterStartAttributeNS()

int xmlTextWriterStartAttributeNS ( xmlTextWriterPtr  writer,
const xmlChar *  prefix,
const xmlChar *  name,
const xmlChar *  namespaceURI 
)

Start attribute with namespace support for current xml element.

Parameters
[in,out]writerTextWriter
[in]prefixNamespace prefix or NULL
[in]nameAttribute name
[in]namespaceURINamespace uri or NULL
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterStartDocument()

int xmlTextWriterStartDocument ( xmlTextWriterPtr  writer,
const char *  version,
const char *  encoding,
const char *  standalone 
)

Start xml document.

Only utf-8 encoding supported.

Parameters
[in]writerTextWriter
[in]versionValue of version attribute, "1.0" if NULL
[in]encodingUnused, defaults to utf-8
[in]standaloneUnused, omitted in declaration
Returns
TextWriter pointer

◆ xmlTextWriterStartElement()

int xmlTextWriterStartElement ( xmlTextWriterPtr  writer,
const xmlChar *  name 
)

Start xml element.

Parameters
[in,out]writerTextWriter
[in]nameElement name
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterStartElementNS()

int xmlTextWriterStartElementNS ( xmlTextWriterPtr  writer,
const xmlChar *  prefix,
const xmlChar *  name,
const xmlChar *  namespaceURI 
)

Start element with namespace support.

Parameters
[in,out]writerTextWriter
[in]prefixNamespace prefix or NULL
[in]nameElement name
[in]namespaceURINamespace uri or NULL
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterWriteAttribute()

int xmlTextWriterWriteAttribute ( xmlTextWriterPtr  writer,
const xmlChar *  name,
const xmlChar *  content 
)

Write attribute with given name and content.

Parameters
[in,out]writerTextWriter
[in]nameAttribute name
[in]contentAttribute content
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterWriteAttributeNS()

int xmlTextWriterWriteAttributeNS ( xmlTextWriterPtr  writer,
const xmlChar *  prefix,
const xmlChar *  name,
const xmlChar *  namespaceURI,
const xmlChar *  content 
)

Write attribute with namespace support.

Parameters
[in,out]writerTextWriter
[in]prefixNamespace prefix or NULL
[in]nameAttribute name
[in]namespaceURINamespace uri or NULL
[in]contentAttribute content
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterWriteElementNS()

int xmlTextWriterWriteElementNS ( xmlTextWriterPtr  writer,
const xmlChar *  prefix,
const xmlChar *  name,
const xmlChar *  namespaceURI,
const xmlChar *  content 
)

Write element with namespace support.

Parameters
[in,out]writerTextWriter
[in]prefixNamespace prefix or NULL
[in]nameElement name
[in]namespaceURINamespace uri or NULL
[in]contentElement content
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure

◆ xmlTextWriterWriteString()

int xmlTextWriterWriteString ( xmlTextWriterPtr  writer,
const xmlChar *  content 
)

Write xml string.

Parameters
[in,out]writerTextWriter
[in]contentAttribute content
Returns
XML_OK (0) on success, XML_ERROR (-1) on failure