mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 08:31:43 +02:00
remove serializer part
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
|
||||
|
||||
#include "XMLStreamParserException.h"
|
||||
#include "XMLStreamSerializerException.h"
|
||||
#include <string>
|
||||
#include <cstddef> // std::size_t
|
||||
#include <iostream>
|
||||
@@ -100,16 +99,6 @@ T default_value_traits<T>::parse(std::string s, const XMLStreamParser& p)
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
std::string default_value_traits<T>::serialize(const T& v, const XMLStreamSerializer& s)
|
||||
{
|
||||
std::ostringstream os;
|
||||
if (!(os << v))
|
||||
throw XMLStreamSerializerException(s, "invalid value");
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,389 +0,0 @@
|
||||
//
|
||||
// XMLStreamSerializer.h
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Library: XML
|
||||
// Package: XML
|
||||
// Module: XMLStreamSerializer
|
||||
//
|
||||
// Definition of the XMLStreamSerializer class.
|
||||
//
|
||||
// Copyright (c) 2004-2015, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC
|
||||
// license : MIT; see accompanying LICENSE file
|
||||
|
||||
|
||||
#ifndef POCO_XML_XMLSERIALIZER_Included
|
||||
#define POCO_XML_XMLSERIALIZER_Included
|
||||
|
||||
|
||||
#include "QName.h"
|
||||
#include "ValueTraits.h"
|
||||
#include "genx.h"
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <cstddef> // std::size_t
|
||||
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace XML
|
||||
{
|
||||
|
||||
|
||||
class XML_API XMLStreamSerializer
|
||||
/// see: http://www.codesynthesis.com/projects/libstudxml/doc/intro.xhtml
|
||||
{
|
||||
public:
|
||||
XMLStreamSerializer(std::ostream&, const std::string& output_name, unsigned short indentation = 2);
|
||||
/// Serialize to std::ostream. Output name is used in diagnostics to
|
||||
/// identify the document being serialized. The indentation argument
|
||||
/// specifies the number of indentation spaces that should be used for
|
||||
/// pretty-printing. If 0 is passed, no pretty-printing is performed.
|
||||
///
|
||||
/// If stream exceptions are enabled then std::ios_base::failure
|
||||
/// exception is used to report io errors (badbit and failbit).
|
||||
/// Otherwise, those are reported as the XMLStreamSerializerException exception.
|
||||
|
||||
~XMLStreamSerializer();
|
||||
|
||||
const std::string& outputName() const;
|
||||
void startElement(const QName& qname);
|
||||
void startElement(const std::string& name);
|
||||
void startElement(const std::string& ns, const std::string& name);
|
||||
|
||||
void endElement();
|
||||
|
||||
// "Checked" end element. That is, it checks that the element
|
||||
// you think you are ending matches the current one.
|
||||
//
|
||||
void endElement (const QName& qname);
|
||||
void endElement (const std::string& name);
|
||||
void endElement (const std::string& ns, const std::string& name);
|
||||
|
||||
// Helpers for serializing elements with simple content. The first two
|
||||
// functions assume that startElement() has already been called. The
|
||||
// other two serialize the complete element, from start to end.
|
||||
|
||||
void element(const std::string& value);
|
||||
template<typename T>
|
||||
void element(const T& value);
|
||||
void element(const std::string& name, const std::string& value);
|
||||
template<typename T>
|
||||
void element(const std::string& name, const T& value);
|
||||
void element(const QName& qname, const std::string& value);
|
||||
template<typename T>
|
||||
void element(const QName& qname, const T& value);
|
||||
void element(const std::string& namespace_, const std::string& name, const std::string& value);
|
||||
template<typename T>
|
||||
void element(const std::string& namespace_, const std::string& name, const T& value);
|
||||
|
||||
// Attributes.
|
||||
//
|
||||
void startAttribute(const QName& qname);
|
||||
void startAttribute(const std::string& name);
|
||||
void startAttribute(const std::string& ns, const std::string& name);
|
||||
|
||||
void endAttribute();
|
||||
// "Checked" end attribute. That is, it checks that the attribute
|
||||
// you think you are ending matches the current one.
|
||||
//
|
||||
void endAttribute (const QName& qname);
|
||||
|
||||
void endAttribute (const std::string& name);
|
||||
|
||||
void endAttribute (const std::string& ns, const std::string& name);
|
||||
|
||||
void attribute(const QName& qname, const std::string& value);
|
||||
template<typename T>
|
||||
void attribute(const QName& qname, const T& value);
|
||||
void attribute(const std::string& name, const std::string& value);
|
||||
template<typename T>
|
||||
void attribute(const std::string& name, const T& value);
|
||||
void attribute(const std::string& ns, const std::string& name, const std::string& value);
|
||||
template<typename T>
|
||||
void attribute(const std::string& ns, const std::string& name, const T& value);
|
||||
|
||||
// Characters.
|
||||
//
|
||||
void characters(const std::string& value);
|
||||
template<typename T>
|
||||
void characters(const T& value);
|
||||
|
||||
void namespaceDecl(const std::string& ns, const std::string& prefix);
|
||||
/// Namespaces declaration. If prefix is empty, then the default
|
||||
/// namespace is declared. If both prefix and namespace are empty,
|
||||
/// then the default namespace declaration is cleared (xmlns="").
|
||||
/// This function should be called after start_element().
|
||||
|
||||
void xmlDecl(const std::string& version = "1.0", const std::string& encoding = "UTF-8", const std::string& standalone = "");
|
||||
/// XML declaration. If encoding or standalone are not specified,
|
||||
/// then these attributes are omitted from the output.
|
||||
|
||||
// DOCTYPE declaration. If encoding or standalone are not specified,
|
||||
// then these attributes are omitted from the output.
|
||||
//
|
||||
void doctypeDecl (const std::string& root_element,
|
||||
const std::string& public_id = "",
|
||||
const std::string& system_id = "",
|
||||
const std::string& internal_subset = "");
|
||||
|
||||
// Utility functions.
|
||||
//
|
||||
|
||||
bool lookupNamespacePrefix(const std::string& ns, std::string& prefix) const;
|
||||
/// Return true if there is a mapping. In this case, prefix contains
|
||||
/// the mapped prefix.
|
||||
|
||||
// Return the current element, that is, the latest element for which
|
||||
// start_element() but not endElement() have been called.
|
||||
//
|
||||
QName currentElement () const;
|
||||
|
||||
// Return the current attribute, that is, the latest attribute for
|
||||
// which start_attribute() but not endAttribute() have been called.
|
||||
//
|
||||
QName currentAttribute () const;
|
||||
|
||||
// Suspend/resume indentation.
|
||||
//
|
||||
// Indentation can be suspended only inside an element and, unless
|
||||
// explicitly resumed, it will remain suspended until the end of
|
||||
// that element. You should only explicitly resume indentation at
|
||||
// the element nesting level of suspension. If indentation is already
|
||||
// suspended at an outer nesting level, then subsequent calls to
|
||||
// suspend/resume are ignored. The indentation_suspended() function
|
||||
// can be used to check if indentation is currently suspended. If it
|
||||
// is not, then this function returns 0. Otherwise, it returns the
|
||||
// level at which pretty-printing was suspended, with root element
|
||||
// being level 1.
|
||||
//
|
||||
void suspendIndentation ();
|
||||
|
||||
void resumeIndentation ();
|
||||
|
||||
std::size_t indentationSuspended () const;
|
||||
|
||||
private:
|
||||
XMLStreamSerializer(const XMLStreamSerializer&);
|
||||
XMLStreamSerializer& operator=(const XMLStreamSerializer&);
|
||||
|
||||
void handleError(genxStatus) const;
|
||||
|
||||
std::ostream& _outputStream;
|
||||
std::ostream::iostate _lastStreamState;// Original exception state.
|
||||
const std::string _outputName;
|
||||
|
||||
genxWriter _writer;
|
||||
genxSender _sender;
|
||||
std::size_t _depth;
|
||||
};
|
||||
|
||||
XMLStreamSerializer& operator<< (XMLStreamSerializer&, void (*func) (XMLStreamSerializer&));
|
||||
/// Stream-like interface for serializer. If the passed argument
|
||||
/// is a function with the void f(serializer&) signature or is a
|
||||
/// function object with the void operator() (serializer&) const
|
||||
/// operator, then this function (object) is called with the passed
|
||||
/// serializer. Otherwise, the argument is passed to the serializer's
|
||||
// characters() function.
|
||||
|
||||
|
||||
template <typename T>
|
||||
XMLStreamSerializer& operator<< (XMLStreamSerializer&, const T& value);
|
||||
|
||||
inline void XMLStreamSerializer::startElement(const QName& qname)
|
||||
{
|
||||
startElement(qname.namespace_(), qname.name());
|
||||
}
|
||||
|
||||
inline void XMLStreamSerializer::startElement(const std::string& name)
|
||||
{
|
||||
startElement(std::string(), name);
|
||||
}
|
||||
|
||||
|
||||
inline void XMLStreamSerializer::endElement (const QName& qname)
|
||||
{
|
||||
endElement (qname.namespace_ (), qname.name ());
|
||||
}
|
||||
|
||||
|
||||
inline void XMLStreamSerializer::endElement (const std::string& name)
|
||||
{
|
||||
endElement (std::string (), name);
|
||||
}
|
||||
|
||||
|
||||
inline void XMLStreamSerializer::element(const std::string& v)
|
||||
{
|
||||
if (!v.empty())
|
||||
characters(v);
|
||||
|
||||
endElement();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void XMLStreamSerializer::element(const T& v)
|
||||
{
|
||||
element(ValueTraits < T > ::serialize(v, *this));
|
||||
}
|
||||
|
||||
inline void XMLStreamSerializer::element(const std::string& n, const std::string& v)
|
||||
{
|
||||
element(std::string(), n, v);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void XMLStreamSerializer::element(const std::string& n, const T& v)
|
||||
{
|
||||
element(n, ValueTraits < T > ::serialize(v, *this));
|
||||
}
|
||||
|
||||
inline void XMLStreamSerializer::element(const QName& qn, const std::string& v)
|
||||
{
|
||||
element(qn.namespace_(), qn.name(), v);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void XMLStreamSerializer::element(const QName& qn, const T& v)
|
||||
{
|
||||
element(qn, ValueTraits < T > ::serialize(v, *this));
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline void XMLStreamSerializer::element(const std::string& ns, const std::string& n, const T& v)
|
||||
{
|
||||
element(ns, n, ValueTraits < T > ::serialize(v, *this));
|
||||
}
|
||||
|
||||
|
||||
inline void XMLStreamSerializer::startAttribute(const QName& qname)
|
||||
{
|
||||
startAttribute(qname.namespace_(), qname.name());
|
||||
}
|
||||
|
||||
|
||||
inline void XMLStreamSerializer::startAttribute(const std::string& name)
|
||||
{
|
||||
startAttribute(std::string(), name);
|
||||
}
|
||||
|
||||
|
||||
inline void XMLStreamSerializer::endAttribute (const QName& qname)
|
||||
{
|
||||
endAttribute (qname.namespace_ (), qname.name ());
|
||||
}
|
||||
|
||||
|
||||
inline void XMLStreamSerializer::endAttribute (const std::string& name)
|
||||
{
|
||||
endAttribute (std::string (), name);
|
||||
}
|
||||
|
||||
|
||||
inline void XMLStreamSerializer::attribute(const QName& qname, const std::string& value)
|
||||
{
|
||||
attribute(qname.namespace_(), qname.name(), value);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline void XMLStreamSerializer::attribute(const QName& qname, const T& value)
|
||||
{
|
||||
attribute(qname, ValueTraits < T > ::serialize(value, *this));
|
||||
}
|
||||
|
||||
|
||||
inline void XMLStreamSerializer::attribute(const std::string& name, const std::string& value)
|
||||
{
|
||||
attribute(std::string(), name, value);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline void XMLStreamSerializer::attribute(const std::string& name, const T& value)
|
||||
{
|
||||
attribute(name, ValueTraits < T > ::serialize(value, *this));
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline void XMLStreamSerializer::attribute(const std::string& ns, const std::string& name, const T& value)
|
||||
{
|
||||
attribute(ns, name, ValueTraits < T > ::serialize(value, *this));
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline void XMLStreamSerializer::characters(const T& value)
|
||||
{
|
||||
characters(ValueTraits < T > ::serialize(value, *this));
|
||||
}
|
||||
|
||||
|
||||
// operator<<
|
||||
//
|
||||
|
||||
inline XMLStreamSerializer& operator<< (XMLStreamSerializer& s, void (*func) (XMLStreamSerializer&))
|
||||
{
|
||||
func (s);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
namespace details
|
||||
{
|
||||
// Detect whether T defines void operator(A) const.
|
||||
//
|
||||
template <typename T, typename A>
|
||||
struct is_functor
|
||||
{
|
||||
typedef char no[1];
|
||||
typedef char yes[2];
|
||||
|
||||
template <typename X, X> struct check;
|
||||
|
||||
template <typename>
|
||||
static no& test (...);
|
||||
|
||||
template <typename X>
|
||||
static yes& test (check<void (X::*) (A) const, &X::operator ()>*);
|
||||
|
||||
static const bool value = sizeof (test<T> (0)) == sizeof (yes);
|
||||
};
|
||||
|
||||
template <typename T, bool = is_functor<T, XMLStreamSerializer&>::value>
|
||||
struct inserter;
|
||||
|
||||
template <typename T>
|
||||
struct inserter<T, true>
|
||||
{
|
||||
static void insert (XMLStreamSerializer& s, const T& f) {f (s);}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct inserter<T, false>
|
||||
{
|
||||
static void insert (XMLStreamSerializer& s, const T& v) {s.characters (v);}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline XMLStreamSerializer& operator<< (XMLStreamSerializer& s, const T& value)
|
||||
{
|
||||
details::inserter<T>::insert (s, value);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // XML_SERIALIZER
|
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// XMLStreamSerializerException.h
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Library: XML
|
||||
// Package: XML
|
||||
// Module: XMLStreamSerializerException
|
||||
//
|
||||
// Definition of the XMLStreamSerializerException class.
|
||||
//
|
||||
// Copyright (c) 2004-2015, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC
|
||||
// license : MIT; see accompanying LICENSE file
|
||||
|
||||
|
||||
#ifndef POCO_XML_XMLSTREAMSERIALIZEREXCEPTION_H_
|
||||
#define POCO_XML_XMLSTREAMSERIALIZEREXCEPTION_H_
|
||||
|
||||
#include <Poco/DOM/DOMException.h>
|
||||
|
||||
namespace Poco
|
||||
{
|
||||
namespace XML
|
||||
{
|
||||
class XMLStreamSerializer;
|
||||
|
||||
struct XML_API XMLStreamSerializerException:
|
||||
public Poco::XML::XMLException
|
||||
{
|
||||
XMLStreamSerializerException(const std::string& name, const std::string& description);
|
||||
XMLStreamSerializerException(const XMLStreamSerializer&, const std::string& description);
|
||||
virtual ~XMLStreamSerializerException() throw ();
|
||||
|
||||
const char* name() const throw ();
|
||||
const std::string& description() const;
|
||||
virtual const char* what() const throw ();
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
std::string _name;
|
||||
std::string _description;
|
||||
std::string _what;
|
||||
};
|
||||
|
||||
}
|
||||
/* namespace XML */
|
||||
} /* namespace Poco */
|
||||
#endif /* POCO_XML_XMLSTREAMPARSEREXCEPTION_H_ */
|
@@ -1,390 +0,0 @@
|
||||
/*
|
||||
* genx - C-callable library for generating XML documents
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2013 Code Synthesis Tools CC.
|
||||
* Copyright (c) 2004 by Tim Bray and Sun Microsystems.
|
||||
*
|
||||
* For copying permission, see the accompanying COPYING file.
|
||||
*/
|
||||
|
||||
#ifndef GENX_H
|
||||
#define GENX_H
|
||||
|
||||
#include <stddef.h> /* size_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Note on error handling: genx routines mostly return
|
||||
* GENX_SUCCESS (guaranteed to be zero) in normal circumstances, one of
|
||||
* these other GENX_ values on a memory allocation or I/O failure or if the
|
||||
* call would result in non-well-formed output.
|
||||
* You can associate an error message with one of these codes explicitly
|
||||
* or with the most recent error using genxGetErrorMessage() and
|
||||
* genxLastErrorMessage(); see below.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GENX_SUCCESS = 0,
|
||||
GENX_BAD_UTF8,
|
||||
GENX_NON_XML_CHARACTER,
|
||||
GENX_BAD_NAME,
|
||||
GENX_ALLOC_FAILED,
|
||||
GENX_BAD_NAMESPACE_NAME,
|
||||
GENX_INTERNAL_ERROR,
|
||||
GENX_DUPLICATE_PREFIX,
|
||||
GENX_SEQUENCE_ERROR,
|
||||
GENX_NO_START_TAG,
|
||||
GENX_IO_ERROR,
|
||||
GENX_MISSING_VALUE,
|
||||
GENX_MALFORMED_COMMENT,
|
||||
GENX_XML_PI_TARGET,
|
||||
GENX_MALFORMED_PI,
|
||||
GENX_DUPLICATE_ATTRIBUTE,
|
||||
GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE,
|
||||
GENX_DUPLICATE_NAMESPACE,
|
||||
GENX_BAD_DEFAULT_DECLARATION
|
||||
} genxStatus;
|
||||
|
||||
/* character types */
|
||||
#define GENX_XML_CHAR 1
|
||||
#define GENX_LETTER 2
|
||||
#define GENX_NAMECHAR 4
|
||||
|
||||
/* The size of the character table. Valid values are 0x100 (first 255
|
||||
chars are checked) and 0x10000 (all chars are checked). */
|
||||
#ifndef GENX_CHAR_TABLE_SIZE
|
||||
# define GENX_CHAR_TABLE_SIZE 0x100
|
||||
#endif
|
||||
|
||||
/* a UTF-8 string */
|
||||
typedef unsigned char * utf8;
|
||||
typedef const unsigned char * constUtf8;
|
||||
|
||||
/*
|
||||
* genx's own types
|
||||
*/
|
||||
typedef struct genxWriter_rec * genxWriter;
|
||||
typedef struct genxNamespace_rec * genxNamespace;
|
||||
typedef struct genxElement_rec * genxElement;
|
||||
typedef struct genxAttribute_rec * genxAttribute;
|
||||
|
||||
typedef void * (*genxAlloc) (void * userData, size_t bytes);
|
||||
typedef void (*genxDealloc) (void * userData, void* data);
|
||||
|
||||
/*
|
||||
* Constructors, set/get
|
||||
*/
|
||||
|
||||
/*
|
||||
* Create a new writer. For generating multiple XML documents, it's most
|
||||
* efficient to re-use the same genx object. However, you can only write
|
||||
* one document at a time with a writer.
|
||||
* Returns NULL if it fails, which can only be due to an allocation failure.
|
||||
*/
|
||||
genxWriter genxNew(genxAlloc alloc, genxDealloc dealloc, void * userData);
|
||||
|
||||
/*
|
||||
* Reset the writer object back into usable state after an error or
|
||||
* interruption.
|
||||
*/
|
||||
genxStatus genxReset (genxWriter w);
|
||||
|
||||
/*
|
||||
* Dispose of a writer, freeing all associated memory
|
||||
*/
|
||||
void genxDispose(genxWriter w);
|
||||
|
||||
/*
|
||||
* Set/get
|
||||
*/
|
||||
|
||||
/*
|
||||
* The userdata pointer will be passed to memory-allocation
|
||||
* and I/O callbacks. If not set, genx will pass NULL
|
||||
*/
|
||||
void genxSetUserData(genxWriter w, void * userData);
|
||||
void * genxGetUserData(genxWriter w);
|
||||
|
||||
/*
|
||||
* Set/get pretty-printing. If indentation is set to 0, then no pretty-
|
||||
* printing is performed.
|
||||
*/
|
||||
genxStatus genxSetPrettyPrint(genxWriter w, int indentation);
|
||||
int genxGetPrettyPrint(genxWriter w);
|
||||
|
||||
/*
|
||||
* Suspend/resume pretty-printing. Pretty-printing can be suspended
|
||||
* only inside an element and, unless explicitly resumed, it will
|
||||
* remain suspended until the end of that element. You should only
|
||||
* explicitly resume pretty-printing at the element nesting level
|
||||
* of suspension. If pretty-printing is already suspended at an
|
||||
* outer nesting level, then subsequent calls to suspend/resume
|
||||
* are ignored. The PrettyPrintSuspended() function can be used
|
||||
* to check if pretty-printing is currently suspended. If it is
|
||||
* not, then this function returns 0. Otherwise, it returns the
|
||||
* level at which pretty-printing was suspended, with root element
|
||||
* being level 1.
|
||||
*/
|
||||
genxStatus genxSuspendPrettyPrint(genxWriter w);
|
||||
genxStatus genxResumePrettyPrint(genxWriter w);
|
||||
int genxPrettyPrintSuspended(genxWriter w);
|
||||
|
||||
|
||||
/*
|
||||
* Set/get canonicalization. If true, then output explicit closing
|
||||
* tags and sort attributes. Default is false.
|
||||
*/
|
||||
genxStatus genxSetCanonical(genxWriter w, int flag);
|
||||
int genxGetCanonical(genxWriter w);
|
||||
|
||||
/*
|
||||
* User-provided memory allocator, if desired. For example, if you were
|
||||
* in an Apache module, you could arrange for genx to use ap_palloc by
|
||||
* making the pool accessible via the userData call.
|
||||
* The "dealloc" is to be used to free memory allocated with "alloc". If
|
||||
* alloc is provided but dealloc is NULL, genx will not attempt to free
|
||||
* the memory; this would be appropriate in an Apache context.
|
||||
* If "alloc" is not provided, genx routines use malloc() to allocate memory
|
||||
*/
|
||||
void genxSetAlloc(genxWriter w, genxAlloc alloc);
|
||||
void genxSetDealloc(genxWriter w, genxDealloc dealloc);
|
||||
genxAlloc genxGetAlloc(genxWriter w);
|
||||
genxDealloc genxGetDealloc(genxWriter w);
|
||||
|
||||
/*
|
||||
* Get the prefix associated with a namespace
|
||||
*/
|
||||
utf8 genxGetNamespacePrefix(genxNamespace ns);
|
||||
|
||||
/*
|
||||
* Declaration functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Declare a namespace. The provided prefix is the default but can be
|
||||
* overridden by genxAddNamespace. If no default prefiix is provided,
|
||||
* genx will generate one of the form g-%d.
|
||||
* On error, returns NULL and signals via statusp
|
||||
*/
|
||||
genxNamespace genxDeclareNamespace(genxWriter w,
|
||||
constUtf8 uri, constUtf8 prefix,
|
||||
genxStatus * statusP);
|
||||
|
||||
/*
|
||||
* Declare an element
|
||||
* If something failed, returns NULL and sets the status code via statusP
|
||||
*/
|
||||
genxElement genxDeclareElement(genxWriter w,
|
||||
genxNamespace ns, constUtf8 name,
|
||||
genxStatus * statusP);
|
||||
|
||||
/*
|
||||
* Declare an attribute
|
||||
*/
|
||||
genxAttribute genxDeclareAttribute(genxWriter w,
|
||||
genxNamespace ns,
|
||||
constUtf8 name, genxStatus * statusP);
|
||||
|
||||
/*
|
||||
* Writing XML
|
||||
*/
|
||||
|
||||
/*
|
||||
* Caller-provided I/O package.
|
||||
* First form is for a null-terminated string.
|
||||
* for second, if you have s="abcdef" and want to send "abc", you'd call
|
||||
* sendBounded(userData, s, s + 3)
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
genxStatus (* send)(void * userData, constUtf8 s);
|
||||
genxStatus (* sendBounded)(void * userData, constUtf8 start, constUtf8 end);
|
||||
genxStatus (* flush)(void * userData);
|
||||
} genxSender;
|
||||
|
||||
genxStatus genxStartDocSender(genxWriter w, genxSender * sender);
|
||||
|
||||
/*
|
||||
* End a document. Calls "flush".
|
||||
*/
|
||||
genxStatus genxEndDocument(genxWriter w);
|
||||
|
||||
/*
|
||||
* Write XML declaration. If encoding or standalone are NULL, then those
|
||||
* attributes are omitted.
|
||||
*/
|
||||
genxStatus genxXmlDeclaration(genxWriter w,
|
||||
constUtf8 version,
|
||||
constUtf8 encoding,
|
||||
constUtf8 standalone);
|
||||
/*
|
||||
* Write DOCTYPE declaration. If public_id is not NULL, then this is
|
||||
* a PUBLIC DOCTYPE declaration, otherwise, if system_id is not NULL,
|
||||
* then this is a SYSTEM DOCTYPE. If both are NULL, then a DOCTYPE
|
||||
* that only contains the root element and, if not NULL, internal
|
||||
* subset is written.
|
||||
*/
|
||||
genxStatus genxDoctypeDeclaration(genxWriter w,
|
||||
constUtf8 root_element,
|
||||
constUtf8 public_id,
|
||||
constUtf8 system_id,
|
||||
constUtf8 internal_subset);
|
||||
|
||||
/*
|
||||
* Write a comment
|
||||
*/
|
||||
genxStatus genxComment(genxWriter w, constUtf8 text);
|
||||
|
||||
/*
|
||||
* Write a PI
|
||||
*/
|
||||
genxStatus genxPI(genxWriter w, constUtf8 target, constUtf8 text);
|
||||
|
||||
/*
|
||||
* Start an element
|
||||
*/
|
||||
genxStatus genxStartElementLiteral(genxWriter w,
|
||||
constUtf8 xmlns, constUtf8 name);
|
||||
|
||||
/*
|
||||
* Start a predeclared element
|
||||
* - element must have been declared
|
||||
*/
|
||||
genxStatus genxStartElement(genxElement e);
|
||||
|
||||
/*
|
||||
* Get current element. The returned values are valid until this
|
||||
* element ceases to be current (i.e., EndElement() is called).
|
||||
* If the element is unqualified, then xmlns is set to NULL.
|
||||
*/
|
||||
genxStatus genxGetCurrentElement (genxWriter w,
|
||||
constUtf8* xmlns, constUtf8* name);
|
||||
|
||||
/*
|
||||
* Write an attribute
|
||||
*/
|
||||
genxStatus genxAddAttributeLiteral(genxWriter w, constUtf8 xmlns,
|
||||
constUtf8 name, constUtf8 value);
|
||||
|
||||
/*
|
||||
* Write a predeclared attribute
|
||||
*/
|
||||
genxStatus genxAddAttribute(genxAttribute a, constUtf8 value);
|
||||
|
||||
/*
|
||||
* Start an attribute
|
||||
*/
|
||||
genxStatus genxStartAttributeLiteral(genxWriter w,
|
||||
constUtf8 xmlns, constUtf8 name);
|
||||
|
||||
/*
|
||||
* Start a predeclared attribute
|
||||
*/
|
||||
genxStatus genxStartAttribute(genxAttribute a);
|
||||
|
||||
/*
|
||||
* Get current attribute. The returned values are valid until this
|
||||
* attribute ceases to be current (i.e., EndAttribute() is called).
|
||||
* If the attribute is unqualified, then xmlns is set to NULL.
|
||||
*/
|
||||
genxStatus genxGetCurrentAttribute (genxWriter w,
|
||||
constUtf8* xmlns, constUtf8* name);
|
||||
|
||||
/*
|
||||
* End an attribute
|
||||
*/
|
||||
genxStatus genxEndAttribute(genxWriter w);
|
||||
|
||||
/*
|
||||
* add a namespace declaration
|
||||
*/
|
||||
genxStatus genxAddNamespaceLiteral(genxWriter w,
|
||||
constUtf8 uri, constUtf8 prefix);
|
||||
|
||||
/*
|
||||
* add a predefined namespace declaration
|
||||
*/
|
||||
genxStatus genxAddNamespace(genxNamespace ns, constUtf8 prefix);
|
||||
|
||||
/*
|
||||
* Clear default namespace declaration
|
||||
*/
|
||||
genxStatus genxUnsetDefaultNamespace(genxWriter w);
|
||||
|
||||
/*
|
||||
* Write an end tag
|
||||
*/
|
||||
genxStatus genxEndElement(genxWriter w);
|
||||
|
||||
/*
|
||||
* Write some text
|
||||
* You can't write any text outside the root element, except with
|
||||
* genxComment and genxPI.
|
||||
*/
|
||||
genxStatus genxAddText(genxWriter w, constUtf8 start);
|
||||
genxStatus genxAddCountedText(genxWriter w, constUtf8 start, size_t byteCount);
|
||||
genxStatus genxAddBoundedText(genxWriter w, constUtf8 start, constUtf8 end);
|
||||
|
||||
/*
|
||||
* Write one character. The integer value is the Unicode character
|
||||
* value, as usually expressed in U+XXXX notation.
|
||||
*/
|
||||
genxStatus genxAddCharacter(genxWriter w, int c);
|
||||
|
||||
/*
|
||||
* Utility routines
|
||||
*/
|
||||
|
||||
/*
|
||||
* Return the Unicode character encoded by the UTF-8 pointed-to by the
|
||||
* argument, and advance the argument past the encoding of the character.
|
||||
* Returns -1 if the UTF-8 is malformed, in which case advances the
|
||||
* argument to point at the first byte past the point past the malformed
|
||||
* ones.
|
||||
*/
|
||||
int genxNextUnicodeChar(constUtf8 * sp);
|
||||
|
||||
/*
|
||||
* Scan a buffer allegedly full of UTF-8 encoded XML characters; return
|
||||
* one of GENX_SUCCESS, GENX_BAD_UTF8, or GENX_NON_XML_CHARACTER
|
||||
*/
|
||||
genxStatus genxCheckText(genxWriter w, constUtf8 s);
|
||||
|
||||
/*
|
||||
* return character status, the OR of GENX_XML_CHAR,
|
||||
* GENX_LETTER, and GENX_NAMECHAR
|
||||
*/
|
||||
int genxCharClass(genxWriter w, int c);
|
||||
|
||||
/*
|
||||
* Silently wipe any non-XML characters out of a chunk of text.
|
||||
* If you call this on a string before you pass it addText or
|
||||
* addAttribute, you will never get an error from genx unless
|
||||
* (a) there's a bug in your software, e.g. a malformed element name, or
|
||||
* (b) there's a memory allocation or I/O error
|
||||
* The output can never be longer than the input.
|
||||
* Returns true if any changes were made.
|
||||
*/
|
||||
int genxScrubText(genxWriter w, constUtf8 in, utf8 out);
|
||||
|
||||
/*
|
||||
* return error messages
|
||||
*/
|
||||
char * genxGetErrorMessage(genxWriter w, genxStatus status);
|
||||
char * genxLastErrorMessage(genxWriter w);
|
||||
|
||||
/*
|
||||
* return version
|
||||
*/
|
||||
char * genxGetVersion();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GENX_H */
|
Reference in New Issue
Block a user