Initial adding of XMLStream API based on libstudxml library

This commit is contained in:
Marian Krivos
2015-08-22 16:32:51 +02:00
parent 5e3258f92e
commit 11211d345d
17 changed files with 5531 additions and 4 deletions

View File

@@ -12,17 +12,18 @@ COMMONFLAGS += -DXML_NS -DXML_DTD -DHAVE_EXPAT_CONFIG_H
objects = AbstractContainerNode AbstractNode Attr AttrMap Attributes \ objects = AbstractContainerNode AbstractNode Attr AttrMap Attributes \
AttributesImpl CDATASection CharacterData ChildNodesList Comment \ AttributesImpl CDATASection CharacterData ChildNodesList Comment \
ContentHandler DOMBuilder DOMException DOMImplementation DOMObject \ Content ContentHandler DOMBuilder DOMException DOMImplementation DOMObject \
DOMParser DOMSerializer DOMWriter DTDHandler DTDMap DeclHandler \ DOMParser DOMSerializer DOMWriter DTDHandler DTDMap DeclHandler \
DefaultHandler Document DocumentEvent DocumentFragment DocumentType \ DefaultHandler Document DocumentEvent DocumentFragment DocumentType \
Element ElementsByTagNameList Entity EntityReference EntityResolver \ Element ElementsByTagNameList Entity EntityReference EntityResolver \
EntityResolverImpl ErrorHandler Event EventDispatcher EventException \ EntityResolverImpl ErrorHandler Event EventDispatcher EventException \
EventListener EventTarget InputSource LexicalHandler Locator LocatorImpl \ EventListener EventTarget InputSource LexicalHandler Locator LocatorImpl \
MutationEvent Name NamePool NamedNodeMap NamespaceStrategy \ MutationEvent Name NamePool NamedNodeMap NamespaceStrategy \
NamespaceSupport Node NodeFilter NodeIterator NodeList Notation \ NamespaceSupport NodeAppender Node NodeFilter NodeIterator NodeList Notation \
ParserEngine ProcessingInstruction SAXException SAXParser Text \ ParserEngine ProcessingInstruction QName SAXException SAXParser Text \
TreeWalker WhitespaceFilter XMLException XMLFilter XMLFilterImpl XMLReader \ TreeWalker WhitespaceFilter XMLException XMLFilter XMLFilterImpl XMLReader \
XMLString XMLWriter NodeAppender XMLString XMLWriter XMLStreamParser XMLStreamParserException XMLStreamSerializer \
XMLStreamSerializerException char-props genx
expat_objects = xmlparse xmlrole xmltok expat_objects = xmlparse xmlrole xmltok

View File

@@ -0,0 +1,43 @@
// file : xml/content -*- C++ -*-
// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
#ifndef POCO_XML_CONTENT
#define POCO_XML_CONTENT
namespace Poco
{
namespace XML
{
/// XML content model. C++11 enum class emulated for C++98.
struct Content
{
enum value
{
// element characters whitespaces notes
Empty, // no no ignored
Simple, // no yes preserved content accumulated
Complex, // yes no ignored
Mixed // yes yes preserved
};
Content(value v)
: v_(v)
{
}
operator value() const
{
return v_;
}
private:
value v_;
};
}
}
#endif // XML_CONTENT

View File

@@ -0,0 +1,103 @@
// file : cutl/xml/QName.hxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
#ifndef POCO_XML_QNAME_HXX
#define POCO_XML_QNAME_HXX
#include "Poco/XML/XML.h"
#include <string>
#include <iosfwd>
namespace Poco
{
namespace XML
{
// Note that the optional prefix is just a "syntactic sugar". In
// particular, it is ignored by the comparison operators and the
// std::ostream insertion operator.
//
class XML_API QName
{
public:
QName()
{
}
QName(const std::string& name) :
name_(name)
{
}
QName(const std::string& ns, const std::string& name) :
ns_(ns),
name_(name)
{
}
QName(const std::string& ns, const std::string& name, const std::string& prefix) :
ns_(ns),
name_(name),
prefix_(prefix)
{
}
const std::string& namespace_() const
{
return ns_;
}
const std::string& name() const
{
return name_;
}
const std::string& prefix() const
{
return prefix_;
}
std::string& namespace_()
{
return ns_;
}
std::string& name()
{
return name_;
}
std::string& prefix()
{
return prefix_;
}
// Printable representation in the [<namespace>#]<name> form.
//
std::string string() const;
// Note that comparison operators
//
public:
friend bool operator<(const QName& x, const QName& y)
{
return x.ns_ < y.ns_ || (x.ns_ == y.ns_ && x.name_ < y.name_);
}
friend bool operator==(const QName& x, const QName& y)
{
return x.ns_ == y.ns_ && x.name_ == y.name_;
}
friend bool operator!=(const QName& x, const QName& y)
{
return !(x == y);
}
private:
std::string ns_;
std::string name_;
std::string prefix_;
};
XML_API std::ostream& operator<<(std::ostream&, const QName&);
}
}
#endif // CUTL_XML_QNAME_HXX

View File

@@ -0,0 +1,90 @@
// file : cutl/xml/value-traits.hxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
#ifndef POCO_XML_VALUE_TRAITS_HXX
#define POCO_XML_VALUE_TRAITS_HXX
#include <string>
#include <cstddef> // std::size_t
#include <iostream>
#include <sstream>
#include "XMLStreamParserException.h"
#include "XMLStreamSerializerException.h"
namespace Poco
{
namespace XML
{
class XMLStreamParser;
class XMLStreamSerializer;
template<typename T>
struct default_value_traits
{
static T
parse(std::string, const XMLStreamParser&);
static std::string
serialize(const T&, const XMLStreamSerializer&);
};
template<>
struct XML_API default_value_traits<bool>
{
static bool
parse(std::string, const XMLStreamParser&);
static std::string serialize(bool v, const XMLStreamSerializer&)
{
return v ? "true" : "false";
}
};
template<>
struct XML_API default_value_traits<std::string>
{
static std::string parse(std::string s, const XMLStreamParser&)
{
return s;
}
static std::string serialize(const std::string& v, const XMLStreamSerializer&)
{
return v;
}
};
template<typename T>
struct ValueTraits: default_value_traits<T>
{
};
template<typename T, std::size_t N>
struct ValueTraits<T[N]> : default_value_traits<const T*>
{
};
template<typename T>
T default_value_traits<T>::parse(std::string s, const XMLStreamParser& p)
{
T r;
std::istringstream is(s);
if (!(is >> r && is.eof()))
throw XMLStreamParserException(p, "invalid value '" + s + "'");
return r;
}
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();
}
}
}
#endif // CUTL_XML_VALUE_TRAITS_HXX

View File

@@ -0,0 +1,614 @@
// file : XMLStreamParser.hxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
#ifndef POCO_XML_PARSER_HXX
#define POCO_XML_PARSER_HXX
// We only support UTF-8 expat.
//
#ifdef XML_UNICODE
# error UTF-16 expat (XML_UNICODE defined) is not supported
#endif
#include "Poco/XML/QName.h"
#include "Poco/XML/ValueTraits.h"
#include "Poco/XML/Content.h"
#include <Poco/XML/expat.h>
#include <map>
#include <vector>
#include <string>
#include <iosfwd>
#include <cstddef> // std::size_t
#include <cassert>
namespace Poco
{
namespace XML
{
class XML_API XMLStreamParser
{
public:
typedef unsigned short FeatureType;
// If both receive_attributes_event and receive_attributes_map are
// specified, then receive_attributes_event is assumed.
//
static const FeatureType RECEIVE_ELEMENTS = 0x0001;
static const FeatureType RECEIVE_CHARACTERS = 0x0002;
static const FeatureType RECEIVE_ATTRIBUTE_MAP = 0x0004;
static const FeatureType RECEIVE_ATTRIBUTES_EVENT = 0x0008;
static const FeatureType RECEIVE_NAMESPACE_DECLS = 0x0010;
static const FeatureType RECEIVE_DEFAULT = RECEIVE_ELEMENTS | RECEIVE_CHARACTERS | RECEIVE_ATTRIBUTE_MAP;
// Parse std::istream. Input name is used in diagnostics to identify
// the document being parsed.
//
// 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 parsing exception.
//
XMLStreamParser(std::istream&, const std::string& input_name, FeatureType = RECEIVE_DEFAULT);
// Parse memory buffer that contains the whole document. Input name
// is used in diagnostics to identify the document being parsed.
//
XMLStreamParser(const void* data, std::size_t size, const std::string& input_name, FeatureType = RECEIVE_DEFAULT);
const std::string& input_name() const
{
return iname_;
}
~XMLStreamParser();
/// Parsing events.
enum EventType
{
// If adding new events, also update the stream insertion operator.
//
StartElement,
EndElement,
StartAttribute,
EndAttribute,
Characters,
StartNamespaceDecl,
EndNamespaceDecl,
Eof
};
EventType next();
// Get the next event and make sure that it's what's expected. If it
// is not, then throw an appropriate parsing exception.
//
void nextExpect(EventType);
void nextExpect(EventType, const std::string& name);
void nextExpect(EventType, const QName& qname);
void nextExpect(EventType, const std::string& ns, const std::string& name);
EventType peek();
// Return the even that was last returned by the call to next() or
// peek().
//
EventType event()
{
return event_;
}
// Event data.
//
const QName& qname() const
{
return *pqname_;
}
const std::string& namespace_() const
{
return pqname_->namespace_();
}
const std::string& name() const
{
return pqname_->name();
}
const std::string& prefix() const
{
return pqname_->prefix();
}
std::string& value()
{
return *pvalue_;
}
const std::string& value() const
{
return *pvalue_;
}
template<typename T> T value() const;
Poco::UInt64 line() const
{
return line_;
}
Poco::UInt64 column() const
{
return column_;
}
// Attribute map lookup. If attribute is not found, then the version
// without the default value throws an appropriate parsing exception
// while the version with the default value returns that value.
//
// Note also that there is no attribute(ns,name) version since it
// would conflict with attribute(name,dv) (qualified attributes
// are not very common).
//
// Attribute map is valid throughout at the "element level" until
// end_element and not just during startElement. As a special case,
// the map is still valid after peek() that returned end_element until
// this end_element event is retrieved with next().
//
const std::string&
attribute(const std::string& name) const;
template<typename T>
T attribute(const std::string& name) const;
std::string attribute(const std::string& name, const std::string& default_value) const;
template<typename T>
T attribute(const std::string& name, const T& default_value) const;
const std::string& attribute(const QName& qname) const;
template<typename T>
T attribute(const QName& qname) const;
std::string attribute(const QName& qname, const std::string& default_value) const;
template<typename T>
T attribute(const QName& qname, const T& default_value) const;
bool attributePresent(const std::string& name) const;
bool attributePresent(const QName& qname) const;
// Low-level attribute map access. Note that this API assumes
// all attributes are handled.
//
struct AttributeValueType
{
std::string value;
mutable bool handled;
};
typedef std::map<QName, AttributeValueType> AttributeMapType;
const AttributeMapType& attributeMap() const;
// Optional content processing.
//
// Note that you cannot get/set content while peeking.
//
void content(Content);
Content content() const;
// Versions that also set the content. Event type must be startElement.
//
void nextExpect(EventType, const std::string& name, Content);
void nextExpect(EventType, const QName& qname, Content);
void nextExpect(EventType, const std::string& ns, const std::string& name, Content);
// Helpers for parsing elements with simple content. The first two
// functions assume that startElement has already been parsed. The
// rest parse the complete element, from start to end.
//
// Note also that as with attribute(), there is no (namespace,name)
// overload since it would conflicts with (namespace,default_value).
//
std::string element();
template<typename T>
T element();
std::string element(const std::string& name);
std::string element(const QName& qname);
template<typename T>
T element(const std::string& name);
template<typename T>
T element(const QName& qname);
std::string element(const std::string& name, const std::string& default_value);
std::string element(const QName& qname, const std::string& default_value);
template<typename T>
T element(const std::string& name, const T& default_value);
template<typename T>
T element(const QName& qname, const T& default_value);
// C++11 range-based for support. Generally, the iterator interface
// doesn't make much sense for the XMLStreamParser so for now we have an
// implementation that is just enough to the range-based for.
//
struct Iterator
{
typedef EventType value_type;
Iterator(XMLStreamParser* p = 0, EventType e = Eof) :
p_(p),
e_(e)
{
}
value_type operator*() const
{
return e_;
}
Iterator& operator++()
{
e_ = p_->next();
return *this;
}
// Comparison only makes sense when comparing to end (eof).
//
bool operator==(Iterator y) const
{
return e_ == Eof && y.e_ == Eof;
}
bool operator!=(Iterator y) const
{
return !(*this == y);
}
private:
XMLStreamParser* p_;
EventType e_;
};
Iterator begin()
{
return Iterator(this, next());
}
Iterator end()
{
return Iterator(this, Eof);
}
private:
XMLStreamParser(const XMLStreamParser&);
XMLStreamParser& operator=(const XMLStreamParser&);
static void XMLCALL start_element_(void*, const XML_Char*, const XML_Char**);
static void XMLCALL end_element_(void*, const XML_Char*);
static void XMLCALL characters_(void*, const XML_Char*, int);
static void XMLCALL start_namespace_decl_(void*, const XML_Char*, const XML_Char*);
static void XMLCALL end_namespace_decl_(void*, const XML_Char*);
void init();
EventType next_(bool peek);
EventType next_body();
void handle_error();
// If size_ is 0, then data is std::istream. Otherwise, it is a buffer.
//
union
{
std::istream* is;
const void* buf;
}data_;
std::size_t size_;
const std::string iname_;
FeatureType feature_;
XML_Parser p_;
std::size_t depth_;
bool accumulate_; // Whether we are accumulating character content.
enum
{
state_next, state_peek
}state_;
EventType event_;
EventType queue_;
QName qname_;
std::string value_;
// These are used to avoid copying when we are handling attributes
// and namespace decls.
//
const QName* pqname_;
std::string* pvalue_;
Poco::UInt64 line_;
Poco::UInt64 column_;
// Attributes as events.
//
struct attribute_type
{
QName qname;
std::string value;
};
typedef std::vector<attribute_type> attributes;
attributes attr_;
attributes::size_type attr_i_; // Index of the current attribute.
// Namespace declarations.
//
typedef std::vector<QName> namespace_decls;
namespace_decls start_ns_;
namespace_decls::size_type start_ns_i_;// Index of the current decl.
namespace_decls end_ns_;
namespace_decls::size_type end_ns_i_;// Index of the current decl.
// Element state consisting of the content model and attribute map.
//
struct ElementEntry
{
ElementEntry(std::size_t d, Content c = Content::Mixed) :
depth(d),
content(c),
attr_unhandled_(0)
{
}
std::size_t depth;
Content content;
AttributeMapType attr_map_;
mutable AttributeMapType::size_type attr_unhandled_;
};
typedef std::vector<ElementEntry> ElementState;
std::vector<ElementEntry> element_state_;
// Empty attribute map to return when an element has no attributes.
//
const AttributeMapType empty_attr_map_;
// Return the element entry corresponding to the current depth, if
// exists, and NULL otherwise.
//
const ElementEntry* getElement() const;
const ElementEntry* get_element_() const;
void pop_element();
};
XML_API std::ostream& operator<<(std::ostream&, XMLStreamParser::EventType);
inline XMLStreamParser::XMLStreamParser(std::istream& is, const std::string& iname, FeatureType f)
: size_(0), iname_(iname), feature_(f)
{
data_.is = &is;
init();
}
inline XMLStreamParser::XMLStreamParser(const void* data, std::size_t size, const std::string& iname, FeatureType f)
: size_(size), iname_(iname), feature_(f)
{
assert(data != 0 && size != 0);
data_.buf = data;
init();
}
inline XMLStreamParser::EventType XMLStreamParser::peek()
{
if (state_ == state_peek)
return event_;
else
{
EventType e(next_(true));
state_ = state_peek; // Set it after the call to next_().
return e;
}
}
template<typename T>
inline T XMLStreamParser::value() const
{
return ValueTraits < T > ::parse(value(), *this);
}
inline const std::string& XMLStreamParser::attribute(const std::string& n) const
{
return attribute(QName(n));
}
template<typename T>
inline T XMLStreamParser::attribute(const std::string& n) const
{
return attribute < T > (QName(n));
}
inline std::string XMLStreamParser::attribute(const std::string& n, const std::string& dv) const
{
return attribute(QName(n), dv);
}
template<typename T>
inline T XMLStreamParser::attribute(const std::string& n, const T& dv) const
{
return attribute < T > (QName(n), dv);
}
template<typename T>
inline T XMLStreamParser::attribute(const QName& qn) const
{
return ValueTraits < T > ::parse(attribute(qn), *this);
}
inline bool XMLStreamParser::attributePresent(const std::string& n) const
{
return attributePresent(QName(n));
}
inline const XMLStreamParser::AttributeMapType& XMLStreamParser::attributeMap() const
{
if (const ElementEntry* e = getElement())
{
e->attr_unhandled_ = 0; // Assume all handled.
return e->attr_map_;
}
return empty_attr_map_;
}
inline void XMLStreamParser::nextExpect(EventType e, const QName& qn)
{
nextExpect(e, qn.namespace_(), qn.name());
}
inline void XMLStreamParser::nextExpect(EventType e, const std::string& n)
{
nextExpect(e, std::string(), n);
}
inline void XMLStreamParser::nextExpect(EventType e, const QName& qn, Content c)
{
nextExpect(e, qn);
assert(e == StartElement);
content(c);
}
inline void XMLStreamParser::nextExpect(EventType e, const std::string& n, Content c)
{
nextExpect(e, std::string(), n);
assert(e == StartElement);
content(c);
}
inline void XMLStreamParser::nextExpect(EventType e, const std::string& ns, const std::string& n, Content c)
{
nextExpect(e, ns, n);
assert(e == StartElement);
content(c);
}
template<typename T>
inline T XMLStreamParser::element()
{
return ValueTraits < T > ::parse(element(), *this);
}
inline std::string XMLStreamParser::element(const std::string& n)
{
nextExpect(StartElement, n);
return element();
}
inline std::string XMLStreamParser::element(const QName& qn)
{
nextExpect(StartElement, qn);
return element();
}
template<typename T>
inline T XMLStreamParser::element(const std::string& n)
{
return ValueTraits < T > ::parse(element(n), *this);
}
template<typename T>
inline T XMLStreamParser::element(const QName& qn)
{
return ValueTraits < T > ::parse(element(qn), *this);
}
inline std::string XMLStreamParser::element(const std::string& n, const std::string& dv)
{
return element(QName(n), dv);
}
template<typename T>
inline T XMLStreamParser::element(const std::string& n, const T& dv)
{
return element < T > (QName(n), dv);
}
inline void XMLStreamParser::content(Content c)
{
assert(state_ == state_next);
if (!element_state_.empty() && element_state_.back().depth == depth_)
element_state_.back().content = c;
else
element_state_.push_back(ElementEntry(depth_, c));
}
inline Content XMLStreamParser::content() const
{
assert(state_ == state_next);
return !element_state_.empty() && element_state_.back().depth == depth_ ? element_state_.back().content : Content(Content::Mixed);
}
inline const XMLStreamParser::ElementEntry* XMLStreamParser::getElement() const
{
return element_state_.empty() ? 0 : get_element_();
}
template<typename T>
T XMLStreamParser::attribute(const QName& qn, const T& dv) const
{
if (const ElementEntry* e = getElement())
{
AttributeMapType::const_iterator i(e->attr_map_.find(qn));
if (i != e->attr_map_.end())
{
if (!i->second.handled)
{
i->second.handled = true;
e->attr_unhandled_--;
}
return ValueTraits < T > ::parse(i->second.value, *this);
}
}
return dv;
}
template<typename T>
T XMLStreamParser::element(const QName& qn, const T& dv)
{
if (peek() == StartElement && qname() == qn)
{
next();
return element<T>();
}
return dv;
}
}
}
#endif // CUTL_XML_PARSER_HXX

View File

@@ -0,0 +1,69 @@
///
/// \package metamodel
/// \file XMLStreamException.h
///
/// \author Marian Krivos <marian.krivos@rsys.sk>
/// \date Aug 21, 2015 - 6:52:24 PM
/// \brief definicia typu
///
/// (C) Copyright 2015 R-SYS,s.r.o
/// All rights reserved.
///
#ifndef POCO_XML_XMLSTREAMPARSEREXCEPTION_H_
#define POCO_XML_XMLSTREAMPARSEREXCEPTION_H_
#include <Poco/DOM/DOMException.h>
namespace Poco
{
namespace XML
{
class XMLStreamParser;
class XML_API XMLStreamParserException :
public Poco::XML::XMLException
{
public:
XMLStreamParserException(const std::string& name, Poco::UInt64 line, Poco::UInt64 column, const std::string& description);
XMLStreamParserException(const XMLStreamParser&, const std::string& description);
virtual ~XMLStreamParserException() throw ();
const char* name() const throw()
{
return name_.c_str();
}
Poco::UInt64 line() const
{
return line_;
}
Poco::UInt64 column() const
{
return column_;
}
const std::string& description() const
{
return description_;
}
virtual const char* what() const throw ();
private:
void init();
std::string name_;
Poco::UInt64 line_;
Poco::UInt64 column_;
std::string description_;
std::string what_;
};
}
/* namespace XML */
} /* namespace Poco */
#endif /* POCO_XML_XMLSTREAMPARSEREXCEPTION_H_ */

View File

@@ -0,0 +1,239 @@
// file : xml/XMLStreamSerializer -*- C++ -*-
// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
#ifndef POCO_XML_XMLSERIALIZER
#define POCO_XML_XMLSERIALIZER
#include "QName.h"
#include "ValueTraits.h"
#include "genx.h"
#include <string>
#include <ostream>
#include <cstddef> // std::size_t
namespace Poco
{
namespace XML
{
class XMLStreamSerializer;
class XML_API XMLStreamSerializer
{
public:
// 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(std::ostream&, const std::string& output_name, unsigned short indentation = 2);
const std::string& outputName() const
{
return oname_;
}
~XMLStreamSerializer();
void startElement(const QName& qname);
void startElement(const std::string& name);
void startElement(const std::string& ns, const std::string& name);
void endElement();
// 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();
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);
// 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="").
//
void namespaceDecl(const std::string& ns, const std::string& prefix);
// XML declaration. If encoding or standalone are not specified,
// then these attributes are omitted from the output.
//
void xmlDecl(const std::string& version = "1.0", const std::string& encoding = "UTF-8", const std::string& standalone = "");
// Utility functions.
//
// Return true if there is a mapping. In this case, prefix contains
// the mapped prefix.
//
bool lookupNamespacePrefix(const std::string& ns, std::string& prefix);
private:
XMLStreamSerializer(const XMLStreamSerializer&);
XMLStreamSerializer& operator=(const XMLStreamSerializer&);
void handleError(genxStatus);
std::ostream& os_;
std::ostream::iostate os_state_;// Original exception state.
const std::string oname_;
genxWriter s_;
genxSender sender_;
std::size_t depth_;
};
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::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::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));
}
}
}
#endif // XML_SERIALIZER

View File

@@ -0,0 +1,57 @@
///
/// \package metamodel
/// \file XMLStreamException.h
///
/// \author Marian Krivos <marian.krivos@rsys.sk>
/// \date Aug 21, 2015 - 6:52:24 PM
/// \brief definicia typu
///
/// (C) Copyright 2015 R-SYS,s.r.o
/// All rights reserved.
///
#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
{
virtual ~XMLStreamSerializerException() throw ();
XMLStreamSerializerException(const std::string& name, const std::string& description);
XMLStreamSerializerException(const XMLStreamSerializer&, const std::string& description);
const char* name() const throw ()
{
return name_.c_str();
}
const std::string& description() const
{
return description_;
}
virtual const char* what() const throw ();
private:
void init();
private:
std::string name_;
std::string description_;
std::string what_;
};
}
/* namespace XML */
} /* namespace Poco */
#endif /* POCO_XML_XMLSTREAMPARSEREXCEPTION_H_ */

34
XML/src/QName.cpp Normal file
View File

@@ -0,0 +1,34 @@
// file : cutl/xml/QName.cxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
#include "QName.h"
#include <ostream>
using namespace std;
namespace Poco
{
namespace XML
{
string QName::string() const
{
std::string r;
if (!ns_.empty())
{
r += ns_;
r += '#';
}
r += name_;
return r;
}
ostream& operator<<(ostream& os, const QName& qn)
{
return os << qn.string();
}
}
}

26
XML/src/ValueTraits.cpp Normal file
View File

@@ -0,0 +1,26 @@
// file : cutl/xml/value-traits.cxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
#include "XMLStreamParser.h"
#include "XMLStreamParserException.h"
using namespace std;
namespace Poco
{
namespace XML
{
bool default_value_traits<bool>::parse(string s, const XMLStreamParser& p)
{
if (s == "true" || s == "1" || s == "True" || s == "TRUE")
return true;
else if (s == "false" || s == "0" || s == "False" || s == "FALSE")
return false;
else
throw XMLStreamParserException(p, "invalid bool value '" + s + "'");
}
}
}

882
XML/src/XMLStreamParser.cpp Normal file
View File

@@ -0,0 +1,882 @@
// file : cutl/xml/XMLStreamParser.cxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
#include <new> // std::bad_alloc
#include <cassert>
#include <cstring> // std::strchr
#include <istream>
#include <ostream>
#include <sstream>
#include "XMLStreamParser.h"
using namespace std;
namespace Poco
{
namespace XML
{
// XMLStreamParser::event_type
//
static const char* parser_event_str[] =
{ "start element", "end element", "start attribute", "end attribute", "characters", "start namespace declaration", "end namespace declaration", "end of file" };
ostream&
operator<<(ostream& os, XMLStreamParser::EventType e)
{
return os << parser_event_str[e];
}
// XMLStreamParser
//
XMLStreamParser::~XMLStreamParser()
{
if (p_ != 0)
XML_ParserFree (p_);
}
void XMLStreamParser::init()
{
depth_ = 0;
state_ = state_next;
event_ = Eof;
queue_ = Eof;
pqname_ = &qname_;
pvalue_ = &value_;
line_ = 0;
column_ = 0;
attr_i_ = 0;
start_ns_i_ = 0;
end_ns_i_ = 0;
if ((feature_ & RECEIVE_ATTRIBUTE_MAP) != 0 && (feature_ & RECEIVE_ATTRIBUTES_EVENT) != 0)
feature_ &= ~RECEIVE_ATTRIBUTE_MAP;
// Allocate the XMLStreamParser. Make sure nothing else can throw after
// this call since otherwise we will leak it.
//
p_ = XML_ParserCreateNS(0, XML_Char(' '));
if (p_ == 0)
throw bad_alloc();
// Get prefixes in addition to namespaces and local names.
//
XML_SetReturnNSTriplet(p_, true);
// Set handlers.
//
XML_SetUserData(p_, this);
if ((feature_ & RECEIVE_ELEMENTS) != 0)
{
XML_SetStartElementHandler(p_, &start_element_);
XML_SetEndElementHandler(p_, &end_element_);
}
if ((feature_ & RECEIVE_CHARACTERS) != 0)
XML_SetCharacterDataHandler(p_, &characters_);
if ((feature_ & RECEIVE_NAMESPACE_DECLS) != 0)
XML_SetNamespaceDeclHandler(p_, &start_namespace_decl_, &end_namespace_decl_);
}
void XMLStreamParser::handle_error()
{
XML_Error e(XML_GetErrorCode (p_));
if (e == XML_ERROR_ABORTED)
{
// For now we only abort the XMLStreamParser in the characters_() and
// start_element_() handlers.
//
switch (content())
{
case Content::Empty:
throw XMLStreamParserException(*this, "characters in empty content");
case Content::Simple:
throw XMLStreamParserException(*this, "element in simple content");
case Content::Complex:
throw XMLStreamParserException(*this, "characters in complex content");
default:
assert(false);
}
}
else
throw XMLStreamParserException(iname_, XML_GetCurrentLineNumber(p_), XML_GetCurrentColumnNumber(p_), XML_ErrorString(e));
}
struct stream_exception_controller
{
~stream_exception_controller()
{
istream::iostate s = is_.rdstate();
s &= ~istream::failbit;
// If our error state (sans failbit) intersects with the
// exception state then that means we have an active
// exception and changing error/exception state will
// cause another to be thrown.
//
if (!(old_state_ & s))
{
// Clear failbit if it was caused by eof.
//
if (is_.fail() && is_.eof())
is_.clear(s);
is_.exceptions(old_state_);
}
}
stream_exception_controller(istream& is)
: is_(is), old_state_(is_.exceptions())
{
is_.exceptions(old_state_ & ~istream::failbit);
}
private:
stream_exception_controller(const stream_exception_controller&);
stream_exception_controller&
operator=(const stream_exception_controller&);
private:
istream& is_;
istream::iostate old_state_;
};
XMLStreamParser::EventType XMLStreamParser::next()
{
if (state_ == state_next)
return next_(false);
else
{
// If we previously peeked at start/end_element, then adjust
// state accordingly.
//
switch (event_)
{
case EndElement:
{
if (!element_state_.empty() && element_state_.back().depth == depth_)
pop_element();
depth_--;
break;
}
case StartElement:
{
depth_++;
break;
}
default:
break;
}
state_ = state_next;
return event_;
}
}
const string& XMLStreamParser::attribute(const QName& qn) const
{
if (const ElementEntry* e = getElement())
{
AttributeMapType::const_iterator i(e->attr_map_.find(qn));
if (i != e->attr_map_.end())
{
if (!i->second.handled)
{
i->second.handled = true;
e->attr_unhandled_--;
}
return i->second.value;
}
}
throw XMLStreamParserException(*this, "attribute '" + qn.string() + "' expected");
}
string XMLStreamParser::attribute(const QName& qn, const string& dv) const
{
if (const ElementEntry* e = getElement())
{
AttributeMapType::const_iterator i(e->attr_map_.find(qn));
if (i != e->attr_map_.end())
{
if (!i->second.handled)
{
i->second.handled = true;
e->attr_unhandled_--;
}
return i->second.value;
}
}
return dv;
}
bool XMLStreamParser::attributePresent(const QName& qn) const
{
if (const ElementEntry* e = getElement())
{
AttributeMapType::const_iterator i(e->attr_map_.find(qn));
if (i != e->attr_map_.end())
{
if (!i->second.handled)
{
i->second.handled = true;
e->attr_unhandled_--;
}
return true;
}
}
return false;
}
void XMLStreamParser::nextExpect(EventType e)
{
if (next() != e)
throw XMLStreamParserException(*this, string(parser_event_str[e]) + " expected");
}
void XMLStreamParser::nextExpect(EventType e, const string& ns, const string& n)
{
if (next() != e || namespace_() != ns || name() != n)
throw XMLStreamParserException(*this, string(parser_event_str[e]) + " '" + QName(ns, n).string() + "' expected");
}
string XMLStreamParser::element()
{
content(Content::Simple);
string r;
// The content of the element can be empty in which case there
// will be no characters event.
//
EventType e(next());
if (e == Characters)
{
r.swap(value());
e = next();
}
// We cannot really get anything other than end_element since
// the simple content validation won't allow it.
//
assert(e == EndElement);
return r;
}
string XMLStreamParser::element(const QName& qn, const string& dv)
{
if (peek() == StartElement && qname() == qn)
{
next();
return element();
}
return dv;
}
const XMLStreamParser::ElementEntry* XMLStreamParser::get_element_() const
{
// The start_element_() Expat handler may have already provisioned
// an entry in the element stack. In this case, we need to get the
// one before it, if any.
//
const ElementEntry* r(0);
ElementState::size_type n(element_state_.size() - 1);
if (element_state_[n].depth == depth_)
r = &element_state_[n];
else if (n != 0 && element_state_[n].depth > depth_)
{
n--;
if (element_state_[n].depth == depth_)
r = &element_state_[n];
}
return r;
}
void XMLStreamParser::pop_element()
{
// Make sure there are no unhandled attributes left.
//
const ElementEntry& e(element_state_.back());
if (e.attr_unhandled_ != 0)
{
// Find the first unhandled attribute and report it.
//
for (AttributeMapType::const_iterator i(e.attr_map_.begin()); i != e.attr_map_.end(); ++i)
{
if (!i->second.handled)
throw XMLStreamParserException(*this, "unexpected attribute '" + i->first.string() + "'");
}
assert(false);
}
element_state_.pop_back();
}
XMLStreamParser::EventType XMLStreamParser::next_(bool peek)
{
EventType e(next_body());
// Content-specific processing. Note that we handle characters in the
// characters_() Expat handler for two reasons. Firstly, it is faster
// to ignore the whitespaces at the source. Secondly, this allows us
// to distinguish between element and attribute characters. We can
// move this processing to the handler because the characters event
// is never queued.
//
switch (e)
{
case EndElement:
{
// If this is a peek, then avoid popping the stack just yet.
// This way, the attribute map will still be valid until we
// call next().
//
if (!peek)
{
if (!element_state_.empty() && element_state_.back().depth == depth_)
pop_element();
depth_--;
}
break;
}
case StartElement:
{
if (const ElementEntry* e = getElement())
{
switch (e->content)
{
case Content::Empty:
throw XMLStreamParserException(*this, "element in empty content");
case Content::Simple:
throw XMLStreamParserException(*this, "element in simple content");
default:
break;
}
}
// If this is a peek, then delay adjusting the depth.
//
if (!peek)
depth_++;
break;
}
default:
break;
}
return e;
}
XMLStreamParser::EventType XMLStreamParser::next_body()
{
// See if we have any start namespace declarations we need to return.
//
if (start_ns_i_ < start_ns_.size())
{
// Based on the previous event determine what's the next one must be.
//
switch (event_)
{
case StartNamespaceDecl:
{
if (++start_ns_i_ == start_ns_.size())
{
start_ns_i_ = 0;
start_ns_.clear();
pqname_ = &qname_;
break; // No more declarations.
}
// Fall through.
}
case StartElement:
{
event_ = StartNamespaceDecl;
pqname_ = &start_ns_[start_ns_i_];
return event_;
}
default:
{
assert(false);
return event_ = Eof;
}
}
}
// See if we have any attributes we need to return as events.
//
if (attr_i_ < attr_.size())
{
// Based on the previous event determine what's the next one must be.
//
switch (event_)
{
case StartAttribute:
{
event_ = Characters;
pvalue_ = &attr_[attr_i_].value;
return event_;
}
case Characters:
{
event_ = EndAttribute; // Name is already set.
return event_;
}
case EndAttribute:
{
if (++attr_i_ == attr_.size())
{
attr_i_ = 0;
attr_.clear();
pqname_ = &qname_;
pvalue_ = &value_;
break; // No more attributes.
}
// Fall through.
}
case StartElement:
case StartNamespaceDecl:
{
event_ = StartAttribute;
pqname_ = &attr_[attr_i_].qname;
return event_;
}
default:
{
assert(false);
return event_ = Eof;
}
}
}
// See if we have any end namespace declarations we need to return.
//
if (end_ns_i_ < end_ns_.size())
{
// Based on the previous event determine what's the next one must be.
//
switch (event_)
{
case EndNamespaceDecl:
{
if (++end_ns_i_ == end_ns_.size())
{
end_ns_i_ = 0;
end_ns_.clear();
pqname_ = &qname_;
break; // No more declarations.
}
// Fall through.
}
// The end namespace declaration comes before the end element
// which means it can follow pretty much any other event.
//
default:
{
event_ = EndNamespaceDecl;
pqname_ = &end_ns_[end_ns_i_];
return event_;
}
}
}
// Check the queue.
//
if (queue_ != Eof)
{
event_ = queue_;
queue_ = Eof;
line_ = XML_GetCurrentLineNumber(p_);
column_ = XML_GetCurrentColumnNumber(p_);
return event_;
}
// Reset the character accumulation flag.
//
accumulate_ = false;
XML_ParsingStatus ps;
XML_GetParsingStatus(p_, &ps);
switch (ps.parsing)
{
case XML_INITIALIZED:
{
// As if we finished the previous chunk.
break;
}
case XML_PARSING:
{
assert(false);
return event_ = Eof;
}
case XML_FINISHED:
{
return event_ = Eof;
}
case XML_SUSPENDED:
{
switch (XML_ResumeParser(p_))
{
case XML_STATUS_SUSPENDED:
{
// If the XMLStreamParser is again in the suspended state, then
// that means we have the next event.
//
return event_;
}
case XML_STATUS_OK:
{
// Otherwise, we need to get and parse the next chunk of data
// unless this was the last chunk, in which case this is eof.
//
if (ps.finalBuffer)
return event_ = Eof;
break;
}
case XML_STATUS_ERROR:
handle_error();
}
break;
}
}
// Get and parse the next chunk of data until we get the next event
// or reach eof.
//
if (!accumulate_)
event_ = Eof;
XML_Status s;
do
{
if (size_ != 0)
{
s = XML_Parse(p_, static_cast<const char*>(data_.buf), static_cast<int>(size_), true);
if (s == XML_STATUS_ERROR)
handle_error();
break;
}
else
{
const size_t cap(4096);
char* b(static_cast<char*>(XML_GetBuffer(p_, cap)));
if (b == 0)
throw bad_alloc();
// Temporarily unset the exception failbit. Also clear the fail bit
// when we reset the old state if it was caused by eof.
//
istream& is(*data_.is);
{
stream_exception_controller sec(is);
is.read(b, static_cast<streamsize>(cap));
}
// If the caller hasn't configured the stream to use exceptions,
// then use the parsing exception to report an error.
//
if (is.bad() || (is.fail() && !is.eof()))
throw XMLStreamParserException(*this, "io failure");
bool eof(is.eof());
s = XML_ParseBuffer(p_, static_cast<int>(is.gcount()), eof);
if (s == XML_STATUS_ERROR)
handle_error();
if (eof)
break;
}
} while (s != XML_STATUS_SUSPENDED);
return event_;
}
static void splitName(const XML_Char* s, QName& qn)
{
string& ns(qn.namespace_());
string& name(qn.name());
string& prefix(qn.prefix());
const char* p(strchr(s, ' '));
if (p == 0)
{
ns.clear();
name = s;
prefix.clear();
}
else
{
ns.assign(s, 0, p - s);
s = p + 1;
p = strchr(s, ' ');
if (p == 0)
{
name = s;
prefix.clear();
}
else
{
name.assign(s, 0, p - s);
prefix = p + 1;
}
}
}
void XMLCALL XMLStreamParser::start_element_(void* v, const XML_Char* name, const XML_Char** atts)
{
XMLStreamParser& p(*static_cast<XMLStreamParser*>(v));
XML_ParsingStatus ps;
XML_GetParsingStatus(p.p_, &ps);
// Expat has a (mis)-feature of a possibily calling handlers even
// after the non-resumable XML_StopParser call.
//
if (ps.parsing == XML_FINISHED)
return;
// Cannot be a followup event.
//
assert(ps.parsing == XML_PARSING);
// When accumulating characters in simple content, we expect to
// see more characters or end element. Seeing start element is
// possible but means violation of the content model.
//
if (p.accumulate_)
{
// It would have been easier to throw the exception directly,
// however, the Expat code is most likely not exception safe.
//
p.line_ = XML_GetCurrentLineNumber(p.p_);
p.column_ = XML_GetCurrentColumnNumber(p.p_);
XML_StopParser(p.p_, false);
return;
}
p.event_ = StartElement;
splitName(name, p.qname_);
p.line_ = XML_GetCurrentLineNumber(p.p_);
p.column_ = XML_GetCurrentColumnNumber(p.p_);
// Handle attributes.
//
if (*atts != 0)
{
bool am((p.feature_ & RECEIVE_ATTRIBUTE_MAP) != 0);
bool ae((p.feature_ & RECEIVE_ATTRIBUTES_EVENT) != 0);
// Provision an entry for this element.
//
ElementEntry* pe(0);
if (am)
{
p.element_state_.push_back(ElementEntry(p.depth_ + 1));
pe = &p.element_state_.back();
}
if (am || ae)
{
for (; *atts != 0; atts += 2)
{
if (am)
{
QName qn;
splitName(*atts, qn);
AttributeMapType::value_type v(qn, AttributeValueType());
v.second.value = *(atts + 1);
v.second.handled = false;
pe->attr_map_.insert(v);
}
else
{
p.attr_.push_back(attribute_type());
splitName(*atts, p.attr_.back().qname);
p.attr_.back().value = *(atts + 1);
}
}
if (am)
pe->attr_unhandled_ = pe->attr_map_.size();
}
}
XML_StopParser(p.p_, true);
}
void XMLCALL XMLStreamParser::end_element_(void* v, const XML_Char* name)
{
XMLStreamParser& p(*static_cast<XMLStreamParser*>(v));
XML_ParsingStatus ps;
XML_GetParsingStatus(p.p_, &ps);
// Expat has a (mis)-feature of a possibily calling handlers even
// after the non-resumable XML_StopParser call.
//
if (ps.parsing == XML_FINISHED)
return;
// This can be a followup event for empty elements (<foo/>). In this
// case the element name is already set.
//
if (ps.parsing != XML_PARSING)
p.queue_ = EndElement;
else
{
splitName(name, p.qname_);
// If we are accumulating characters, then queue this event.
//
if (p.accumulate_)
p.queue_ = EndElement;
else
{
p.event_ = EndElement;
p.line_ = XML_GetCurrentLineNumber(p.p_);
p.column_ = XML_GetCurrentColumnNumber(p.p_);
}
XML_StopParser(p.p_, true);
}
}
void XMLCALL XMLStreamParser::characters_(void* v, const XML_Char* s, int n)
{
XMLStreamParser& p(*static_cast<XMLStreamParser*>(v));
XML_ParsingStatus ps;
XML_GetParsingStatus(p.p_, &ps);
// Expat has a (mis)-feature of a possibily calling handlers even
// after the non-resumable XML_StopParser call.
//
if (ps.parsing == XML_FINISHED)
return;
Content cont(p.content());
// If this is empty or complex content, see if these are whitespaces.
//
switch (cont)
{
case Content::Empty:
case Content::Complex:
{
for (int i(0); i != n; ++i)
{
char c(s[i]);
if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09)
continue;
// It would have been easier to throw the exception directly,
// however, the Expat code is most likely not exception safe.
//
p.line_ = XML_GetCurrentLineNumber(p.p_);
p.column_ = XML_GetCurrentColumnNumber(p.p_);
XML_StopParser(p.p_, false);
break;
}
return;
}
default:
break;
}
// Append the characters if we are accumulating. This can also be a
// followup event for another character event. In this case also
// append the data.
//
if (p.accumulate_ || ps.parsing != XML_PARSING)
{
assert(p.event_ == Characters);
p.value_.append(s, n);
}
else
{
p.event_ = Characters;
p.value_.assign(s, n);
p.line_ = XML_GetCurrentLineNumber(p.p_);
p.column_ = XML_GetCurrentColumnNumber(p.p_);
// In simple content we need to accumulate all the characters
// into a single event. To do this we will let the XMLStreamParser run
// until we reach the end of the element.
//
if (cont == Content::Simple)
p.accumulate_ = true;
else
XML_StopParser(p.p_, true);
}
}
void XMLCALL XMLStreamParser::start_namespace_decl_(void* v, const XML_Char* prefix, const XML_Char* ns)
{
XMLStreamParser& p(*static_cast<XMLStreamParser*>(v));
XML_ParsingStatus ps;
XML_GetParsingStatus(p.p_, &ps);
// Expat has a (mis)-feature of a possibily calling handlers even
// after the non-resumable XML_StopParser call.
//
if (ps.parsing == XML_FINISHED)
return;
p.start_ns_.push_back(QName());
p.start_ns_.back().prefix() = (prefix != 0 ? prefix : "");
p.start_ns_.back().namespace_() = (ns != 0 ? ns : "");
}
void XMLCALL XMLStreamParser::end_namespace_decl_(void* v, const XML_Char* prefix)
{
XMLStreamParser& p(*static_cast<XMLStreamParser*>(v));
XML_ParsingStatus ps;
XML_GetParsingStatus(p.p_, &ps);
// Expat has a (mis)-feature of a possibily calling handlers even
// after the non-resumable XML_StopParser call.
//
if (ps.parsing == XML_FINISHED)
return;
p.end_ns_.push_back(QName());
p.end_ns_.back().prefix() = (prefix != 0 ? prefix : "");
}
}
}

View File

@@ -0,0 +1,54 @@
///
/// \package metamodel
/// \file XMLStreamException.cpp
///
/// \author Marian Krivos <marian.krivos@rsys.sk>
/// \date Aug 21, 2015 - 6:52:24 PM
/// \brief definicia typu
///
/// (C) Copyright 2015 R-SYS,s.r.o
/// All rights reserved.
///
#include "XMLStreamParserException.h"
#include "XMLStreamParser.h"
using namespace std;
namespace Poco
{
namespace XML
{
XMLStreamParserException::~XMLStreamParserException() throw ()
{
}
XMLStreamParserException::XMLStreamParserException(const string& n, Poco::UInt64 l, Poco::UInt64 c, const string& d)
: name_(n), line_(l), column_(c), description_(d)
{
init();
}
XMLStreamParserException::XMLStreamParserException(const XMLStreamParser& p, const std::string& d)
: name_(p.input_name()), line_(p.line()), column_(p.column()), description_(d)
{
init();
}
void XMLStreamParserException::init()
{
std::ostringstream os;
if (!name_.empty())
os << name_ << ':';
os << line_ << ':' << column_ << ": error: " << description_;
what_ = os.str();
}
char const* XMLStreamParserException::what() const throw ()
{
return what_.c_str();
}
} /* namespace XML */
} /* namespace Poco */

View File

@@ -0,0 +1,191 @@
// file : xml/XMLStreamSerializer.cxx
// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
#include "XMLStreamSerializer.h"
#include "XMLStreamSerializerException.h"
#include <new> // std::bad_alloc
#include <cstring> // std::strlen
using namespace std;
namespace Poco
{
namespace XML
{
// XMLStreamSerializer
//
extern "C" genxStatus genx_write(void* p, constUtf8 us)
{
// It would have been easier to throw the exception directly,
// however, the Genx code is most likely not exception safe.
//
ostream* os(static_cast<ostream*>(p));
const char* s(reinterpret_cast<const char*>(us));
os->write(s, static_cast<streamsize>(strlen(s)));
return os->good() ? GENX_SUCCESS : GENX_IO_ERROR;
}
extern "C" genxStatus genx_write_bound(void* p, constUtf8 start, constUtf8 end)
{
ostream* os(static_cast<ostream*>(p));
const char* s(reinterpret_cast<const char*>(start));
streamsize n(static_cast<streamsize>(end - start));
os->write(s, n);
return os->good() ? GENX_SUCCESS : GENX_IO_ERROR;
}
extern "C" genxStatus genx_flush(void* p)
{
ostream* os(static_cast<ostream*>(p));
os->flush();
return os->good() ? GENX_SUCCESS : GENX_IO_ERROR;
}
XMLStreamSerializer::~XMLStreamSerializer()
{
if (s_ != 0)
genxDispose (s_);
}
XMLStreamSerializer::XMLStreamSerializer(ostream& os, const string& oname, unsigned short ind)
: os_(os), os_state_(os.exceptions()), oname_(oname), depth_(0)
{
// Temporarily disable exceptions on the stream.
//
os_.exceptions(ostream::goodbit);
// Allocate the XMLStreamSerializer. Make sure nothing else can throw after
// this call since otherwise we will leak it.
//
s_ = genxNew(0, 0, 0);
if (s_ == 0)
throw bad_alloc();
genxSetUserData(s_, &os_);
if (ind != 0)
genxSetPrettyPrint(s_, ind);
sender_.send = &genx_write;
sender_.sendBounded = &genx_write_bound;
sender_.flush = &genx_flush;
if (genxStatus e = genxStartDocSender(s_, &sender_))
{
string m(genxGetErrorMessage(s_, e));
genxDispose (s_);
throw XMLStreamSerializerException(oname, m);
}
}
void XMLStreamSerializer::handleError(genxStatus e)
{
switch (e)
{
case GENX_ALLOC_FAILED:
throw bad_alloc();
case GENX_IO_ERROR:
// Restoring the original exception state should trigger the
// exception. If it doesn't (e.g., because the user didn't
// configure the stream to throw), then fall back to the
// serialiation exception.
//
os_.exceptions(os_state_);
// Fall through.
default:
throw XMLStreamSerializerException(oname_, genxGetErrorMessage(s_, e));
}
}
void XMLStreamSerializer::startElement(const string& ns, const string& name)
{
if (genxStatus e = genxStartElementLiteral(s_, reinterpret_cast<constUtf8>(ns.empty() ? 0 : ns.c_str()), reinterpret_cast<constUtf8>(name.c_str())))
handleError(e);
depth_++;
}
void XMLStreamSerializer::endElement()
{
if (genxStatus e = genxEndElement(s_))
handleError(e);
// Call EndDocument() if we are past the root element.
//
if (--depth_ == 0)
{
if (genxStatus e = genxEndDocument(s_))
handleError(e);
// Also restore the original exception state on the stream.
//
os_.exceptions(os_state_);
}
}
void XMLStreamSerializer::element(const string& ns, const string& n, const string& v)
{
startElement(ns, n);
element(v);
}
void XMLStreamSerializer::startAttribute(const string& ns, const string& name)
{
if (genxStatus e = genxStartAttributeLiteral(s_, reinterpret_cast<constUtf8>(ns.empty() ? 0 : ns.c_str()), reinterpret_cast<constUtf8>(name.c_str())))
handleError(e);
}
void XMLStreamSerializer::endAttribute()
{
if (genxStatus e = genxEndAttribute(s_))
handleError(e);
}
void XMLStreamSerializer::attribute(const string& ns, const string& name, const string& value)
{
if (genxStatus e = genxAddAttributeLiteral(s_, reinterpret_cast<constUtf8>(ns.empty() ? 0 : ns.c_str()), reinterpret_cast<constUtf8>(name.c_str()),
reinterpret_cast<constUtf8>(value.c_str())))
handleError(e);
}
void XMLStreamSerializer::characters(const string& value)
{
if (genxStatus e = genxAddCountedText(s_, reinterpret_cast<constUtf8>(value.c_str()), value.size()))
handleError(e);
}
void XMLStreamSerializer::namespaceDecl(const string& ns, const string& p)
{
if (genxStatus e =
ns.empty() && p.empty() ?
genxUnsetDefaultNamespace(s_) :
genxAddNamespaceLiteral(s_, reinterpret_cast<constUtf8>(ns.c_str()), reinterpret_cast<constUtf8>(p.c_str())))
handleError(e);
}
void XMLStreamSerializer::xmlDecl(const string& ver, const string& enc, const string& stl)
{
if (genxStatus e = genxXmlDeclaration(s_, reinterpret_cast<constUtf8>(ver.c_str()), (enc.empty() ? 0 : reinterpret_cast<constUtf8>(enc.c_str())),
(stl.empty() ? 0 : reinterpret_cast<constUtf8>(stl.c_str()))))
handleError(e);
}
bool XMLStreamSerializer::lookupNamespacePrefix(const string& ns, string& p)
{
// Currently Genx will create a namespace mapping if one doesn't
// already exist.
//
genxStatus e;
genxNamespace gns(genxDeclareNamespace(s_, reinterpret_cast<constUtf8>(ns.c_str()), 0, &e));
if (e != GENX_SUCCESS)
handleError(e);
p = reinterpret_cast<const char*>(genxGetNamespacePrefix(gns));
return true;
}
}
}

View File

@@ -0,0 +1,59 @@
///
/// \package metamodel
/// \file XMLStreamException.cpp
///
/// \author Marian Krivos <marian.krivos@rsys.sk>
/// \date Aug 21, 2015 - 6:52:24 PM
/// \brief definicia typu
///
/// (C) Copyright 2015 R-SYS,s.r.o
/// All rights reserved.
///
#include "XMLStreamParserException.h"
#include "XMLStreamSerializer.h"
using namespace std;
namespace Poco
{
namespace XML
{
// XMLStreamSerializerException
//
XMLStreamSerializerException::~XMLStreamSerializerException() throw ()
{
}
XMLStreamSerializerException::XMLStreamSerializerException(const string& n, const string& d)
: name_(n), description_(d)
{
init();
}
XMLStreamSerializerException::XMLStreamSerializerException(const XMLStreamSerializer& s, const std::string& d)
: name_(s.outputName()), description_(d)
{
init();
}
void XMLStreamSerializerException::init()
{
if (!name_.empty())
{
what_ += name_;
what_ += ": ";
}
what_ += "error: ";
what_ += description_;
}
char const* XMLStreamSerializerException::what() const throw ()
{
return what_.c_str();
}
} /* namespace XML */
} /* namespace Poco */

394
XML/src/char-props.c Normal file
View File

@@ -0,0 +1,394 @@
/*
* 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.
*/
/*
* Construct character-properties tables for genx.
* Quite likely there's a better way.
* This version is generated semi-automatically from the source code of the
* XML specification via emacs global replace and keyboard macros
*/
#include "genx.h"
static void charProp(char * p, int c, int prop)
{
p[c] |= prop;
}
static void rangeProp(char * p, size_t start, size_t end, int prop)
{
size_t i;
for (i = start; i <= end; i++)
p[i] |= prop;
}
void genxSetCharProps(char * p)
{
size_t i;
for (i = 0; i < GENX_CHAR_TABLE_SIZE; i++)
p[i] = 0;
/* per XML 1.0 */
charProp(p, 0x9, GENX_XML_CHAR);
charProp(p, 0xa, GENX_XML_CHAR);
charProp(p, 0xd, GENX_XML_CHAR);
rangeProp(p, 0x20, 0xff, GENX_XML_CHAR);
#if GENX_CHAR_TABLE_SIZE == 0x10000
rangeProp(p, 0x0100, 0xd7ff, GENX_XML_CHAR);
rangeProp(p, 0xe000, 0xfffd, GENX_XML_CHAR);
#endif
/* Letter ::= BaseChar | Ideographic */
rangeProp(p, 0x0041, 0x005A, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0061, 0x007A, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x00C0, 0x00D6, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x00D8, 0x00F6, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x00F8, 0x00FF, GENX_LETTER|GENX_NAMECHAR);
#if GENX_CHAR_TABLE_SIZE == 0x10000
rangeProp(p, 0x0100, 0x0131, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0134, 0x013E, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0141, 0x0148, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x014A, 0x017E, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0180, 0x01C3, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x01CD, 0x01F0, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x01F4, 0x01F5, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x01FA, 0x0217, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0250, 0x02A8, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x02BB, 0x02C1, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0386, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0388, 0x038A, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x038C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x038E, 0x03A1, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x03A3, 0x03CE, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x03D0, 0x03D6, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x03DA, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x03DC, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x03DE, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x03E0, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x03E2, 0x03F3, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0401, 0x040C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x040E, 0x044F, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0451, 0x045C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x045E, 0x0481, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0490, 0x04C4, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x04C7, 0x04C8, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x04CB, 0x04CC, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x04D0, 0x04EB, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x04EE, 0x04F5, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x04F8, 0x04F9, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0531, 0x0556, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0559, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0561, 0x0586, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x05D0, 0x05EA, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x05F0, 0x05F2, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0621, 0x063A, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0641, 0x064A, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0671, 0x06B7, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x06BA, 0x06BE, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x06C0, 0x06CE, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x06D0, 0x06D3, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x06D5, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x06E5, 0x06E6, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0905, 0x0939, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x093D, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0958, 0x0961, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0985, 0x098C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x098F, 0x0990, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0993, 0x09A8, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x09AA, 0x09B0, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x09B2, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x09B6, 0x09B9, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x09DC, 0x09DD, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x09DF, 0x09E1, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x09F0, 0x09F1, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A05, 0x0A0A, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A0F, 0x0A10, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A13, 0x0A28, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A2A, 0x0A30, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A32, 0x0A33, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A35, 0x0A36, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A38, 0x0A39, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A59, 0x0A5C, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0A5E, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A72, 0x0A74, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A85, 0x0A8B, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0A8D, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A8F, 0x0A91, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A93, 0x0AA8, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0AAA, 0x0AB0, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0AB2, 0x0AB3, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0AB5, 0x0AB9, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0ABD, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0AE0, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B05, 0x0B0C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B0F, 0x0B10, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B13, 0x0B28, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B2A, 0x0B30, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B32, 0x0B33, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B36, 0x0B39, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0B3D, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B5C, 0x0B5D, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B5F, 0x0B61, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B85, 0x0B8A, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B8E, 0x0B90, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B92, 0x0B95, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B99, 0x0B9A, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0B9C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B9E, 0x0B9F, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0BA3, 0x0BA4, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0BA8, 0x0BAA, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0BAE, 0x0BB5, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0BB7, 0x0BB9, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0C05, 0x0C0C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0C0E, 0x0C10, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0C12, 0x0C28, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0C2A, 0x0C33, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0C35, 0x0C39, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0C60, 0x0C61, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0C85, 0x0C8C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0C8E, 0x0C90, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0C92, 0x0CA8, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0CAA, 0x0CB3, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0CB5, 0x0CB9, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0CDE, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0CE0, 0x0CE1, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0D05, 0x0D0C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0D0E, 0x0D10, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0D12, 0x0D28, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0D2A, 0x0D39, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0D60, 0x0D61, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0E01, 0x0E2E, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0E30, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0E32, 0x0E33, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0E40, 0x0E45, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0E81, 0x0E82, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0E84, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0E87, 0x0E88, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0E8A, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0E8D, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0E94, 0x0E97, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0E99, 0x0E9F, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0EA1, 0x0EA3, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0EA5, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0EA7, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0EAA, 0x0EAB, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0EAD, 0x0EAE, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0EB0, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0EB2, 0x0EB3, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0EBD, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0EC0, 0x0EC4, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0F40, 0x0F47, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0F49, 0x0F69, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x10A0, 0x10C5, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x10D0, 0x10F6, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1100, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1102, 0x1103, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1105, 0x1107, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1109, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x110B, 0x110C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x110E, 0x1112, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x113C, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x113E, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1140, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x114C, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x114E, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1150, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1154, 0x1155, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1159, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x115F, 0x1161, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1163, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1165, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1167, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1169, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x116D, 0x116E, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1172, 0x1173, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1175, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x119E, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x11A8, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x11AB, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x11AE, 0x11AF, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x11B7, 0x11B8, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x11BA, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x11BC, 0x11C2, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x11EB, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x11F0, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x11F9, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1E00, 0x1E9B, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1EA0, 0x1EF9, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1F00, 0x1F15, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1F18, 0x1F1D, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1F20, 0x1F45, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1F48, 0x1F4D, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1F50, 0x1F57, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1F59, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1F5B, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1F5D, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1F5F, 0x1F7D, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1F80, 0x1FB4, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1FB6, 0x1FBC, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x1FBE, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1FC2, 0x1FC4, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1FC6, 0x1FCC, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1FD0, 0x1FD3, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1FD6, 0x1FDB, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1FE0, 0x1FEC, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1FF2, 0x1FF4, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x1FF6, 0x1FFC, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x2126, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x212A, 0x212B, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x212E, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x2180, 0x2182, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x3041, 0x3094, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x30A1, 0x30FA, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x3105, 0x312C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0xAC00, 0xD7A3, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x4E00, 0x9FA5, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x3007, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x3021, 0x3029, GENX_LETTER|GENX_NAMECHAR);
#endif /* GENX_CHAR_TABLE_SIZE == 0x10000 */
/*
* NameChar ::=
* Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
*/
charProp(p, '.', GENX_NAMECHAR);
charProp(p, '-', GENX_NAMECHAR);
charProp(p, '_', GENX_NAMECHAR);
rangeProp(p, 0x0030, 0x0039, GENX_NAMECHAR);
charProp(p, 0x00B7, GENX_LETTER|GENX_NAMECHAR);
#if GENX_CHAR_TABLE_SIZE == 0x10000
rangeProp(p, 0x0660, 0x0669, GENX_NAMECHAR);
rangeProp(p, 0x06F0, 0x06F9, GENX_NAMECHAR);
rangeProp(p, 0x0966, 0x096F, GENX_NAMECHAR);
rangeProp(p, 0x09E6, 0x09EF, GENX_NAMECHAR);
rangeProp(p, 0x0A66, 0x0A6F, GENX_NAMECHAR);
rangeProp(p, 0x0AE6, 0x0AEF, GENX_NAMECHAR);
rangeProp(p, 0x0B66, 0x0B6F, GENX_NAMECHAR);
rangeProp(p, 0x0BE7, 0x0BEF, GENX_NAMECHAR);
rangeProp(p, 0x0C66, 0x0C6F, GENX_NAMECHAR);
rangeProp(p, 0x0CE6, 0x0CEF, GENX_NAMECHAR);
rangeProp(p, 0x0D66, 0x0D6F, GENX_NAMECHAR);
rangeProp(p, 0x0E50, 0x0E59, GENX_NAMECHAR);
rangeProp(p, 0x0ED0, 0x0ED9, GENX_NAMECHAR);
rangeProp(p, 0x0F20, 0x0F29, GENX_NAMECHAR);
rangeProp(p, 0x0300, 0x0345, GENX_NAMECHAR);
rangeProp(p, 0x0360, 0x0361, GENX_NAMECHAR);
rangeProp(p, 0x0483, 0x0486, GENX_NAMECHAR);
rangeProp(p, 0x0591, 0x05A1, GENX_NAMECHAR);
rangeProp(p, 0x05A3, 0x05B9, GENX_NAMECHAR);
rangeProp(p, 0x05BB, 0x05BD, GENX_NAMECHAR);
charProp(p, 0x05BF, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x05C1, 0x05C2, GENX_NAMECHAR);
charProp(p, 0x05C4, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x064B, 0x0652, GENX_NAMECHAR);
charProp(p, 0x0670, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x06D6, 0x06DC, GENX_NAMECHAR);
rangeProp(p, 0x06DD, 0x06DF, GENX_NAMECHAR);
rangeProp(p, 0x06E0, 0x06E4, GENX_NAMECHAR);
rangeProp(p, 0x06E7, 0x06E8, GENX_NAMECHAR);
rangeProp(p, 0x06EA, 0x06ED, GENX_NAMECHAR);
rangeProp(p, 0x0901, 0x0903, GENX_NAMECHAR);
charProp(p, 0x093C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x093E, 0x094C, GENX_NAMECHAR);
charProp(p, 0x094D, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0951, 0x0954, GENX_NAMECHAR);
rangeProp(p, 0x0962, 0x0963, GENX_NAMECHAR);
rangeProp(p, 0x0981, 0x0983, GENX_NAMECHAR);
charProp(p, 0x09BC, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x09BE, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x09BF, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x09C0, 0x09C4, GENX_NAMECHAR);
rangeProp(p, 0x09C7, 0x09C8, GENX_NAMECHAR);
rangeProp(p, 0x09CB, 0x09CD, GENX_NAMECHAR);
charProp(p, 0x09D7, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x09E2, 0x09E3, GENX_NAMECHAR);
charProp(p, 0x0A02, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0A3C, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0A3E, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0A3F, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0A40, 0x0A42, GENX_NAMECHAR);
rangeProp(p, 0x0A47, 0x0A48, GENX_NAMECHAR);
rangeProp(p, 0x0A4B, 0x0A4D, GENX_NAMECHAR);
rangeProp(p, 0x0A70, 0x0A71, GENX_NAMECHAR);
rangeProp(p, 0x0A81, 0x0A83, GENX_NAMECHAR);
charProp(p, 0x0ABC, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0ABE, 0x0AC5, GENX_NAMECHAR);
rangeProp(p, 0x0AC7, 0x0AC9, GENX_NAMECHAR);
rangeProp(p, 0x0ACB, 0x0ACD, GENX_NAMECHAR);
rangeProp(p, 0x0B01, 0x0B03, GENX_NAMECHAR);
charProp(p, 0x0B3C, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0B3E, 0x0B43, GENX_NAMECHAR);
rangeProp(p, 0x0B47, 0x0B48, GENX_NAMECHAR);
rangeProp(p, 0x0B4B, 0x0B4D, GENX_NAMECHAR);
rangeProp(p, 0x0B56, 0x0B57, GENX_NAMECHAR);
rangeProp(p, 0x0B82, 0x0B83, GENX_NAMECHAR);
rangeProp(p, 0x0BBE, 0x0BC2, GENX_NAMECHAR);
rangeProp(p, 0x0BC6, 0x0BC8, GENX_NAMECHAR);
rangeProp(p, 0x0BCA, 0x0BCD, GENX_NAMECHAR);
charProp(p, 0x0BD7, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0C01, 0x0C03, GENX_NAMECHAR);
rangeProp(p, 0x0C3E, 0x0C44, GENX_NAMECHAR);
rangeProp(p, 0x0C46, 0x0C48, GENX_NAMECHAR);
rangeProp(p, 0x0C4A, 0x0C4D, GENX_NAMECHAR);
rangeProp(p, 0x0C55, 0x0C56, GENX_NAMECHAR);
rangeProp(p, 0x0C82, 0x0C83, GENX_NAMECHAR);
rangeProp(p, 0x0CBE, 0x0CC4, GENX_NAMECHAR);
rangeProp(p, 0x0CC6, 0x0CC8, GENX_NAMECHAR);
rangeProp(p, 0x0CCA, 0x0CCD, GENX_NAMECHAR);
rangeProp(p, 0x0CD5, 0x0CD6, GENX_NAMECHAR);
rangeProp(p, 0x0D02, 0x0D03, GENX_NAMECHAR);
rangeProp(p, 0x0D3E, 0x0D43, GENX_NAMECHAR);
rangeProp(p, 0x0D46, 0x0D48, GENX_NAMECHAR);
rangeProp(p, 0x0D4A, 0x0D4D, GENX_NAMECHAR);
charProp(p, 0x0D57, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0E31, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0E34, 0x0E3A, GENX_NAMECHAR);
rangeProp(p, 0x0E47, 0x0E4E, GENX_NAMECHAR);
charProp(p, 0x0EB1, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0EB4, 0x0EB9, GENX_NAMECHAR);
rangeProp(p, 0x0EBB, 0x0EBC, GENX_NAMECHAR);
rangeProp(p, 0x0EC8, 0x0ECD, GENX_NAMECHAR);
rangeProp(p, 0x0F18, 0x0F19, GENX_NAMECHAR);
charProp(p, 0x0F35, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0F37, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0F39, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0F3E, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0F3F, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0F71, 0x0F84, GENX_NAMECHAR);
rangeProp(p, 0x0F86, 0x0F8B, GENX_NAMECHAR);
rangeProp(p, 0x0F90, 0x0F95, GENX_NAMECHAR);
charProp(p, 0x0F97, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x0F99, 0x0FAD, GENX_NAMECHAR);
rangeProp(p, 0x0FB1, 0x0FB7, GENX_NAMECHAR);
charProp(p, 0x0FB9, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x20D0, 0x20DC, GENX_NAMECHAR);
charProp(p, 0x20E1, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x302A, 0x302F, GENX_NAMECHAR);
charProp(p, 0x3099, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x309A, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x02D0, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x02D1, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0387, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0640, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0E46, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x0EC6, GENX_LETTER|GENX_NAMECHAR);
charProp(p, 0x3005, GENX_LETTER|GENX_NAMECHAR);
rangeProp(p, 0x3031, 0x3035, GENX_NAMECHAR);
rangeProp(p, 0x309D, 0x309E, GENX_NAMECHAR);
rangeProp(p, 0x30FC, 0x30FE, GENX_NAMECHAR);
#endif /* GENX_CHAR_TABLE_SIZE == 0x10000 */
}

2328
XML/src/genx.c Normal file

File diff suppressed because it is too large Load Diff

343
XML/src/genx.h Normal file
View File

@@ -0,0 +1,343 @@
/*
* 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);
/*
* 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 type,
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 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 type);
/*
* Start a predeclared element
* - element must have been declared
*/
genxStatus genxStartElement(genxElement e);
/*
* Write an attribute
*/
genxStatus genxAddAttributeLiteral(genxWriter w, constUtf8 xmlns,
constUtf8 name, constUtf8 value);
/*
* Start an attribute
*/
genxStatus genxStartAttributeLiteral(genxWriter w,
constUtf8 xmlns, constUtf8 name);
/*
* Write a predeclared attribute
*/
genxStatus genxAddAttribute(genxAttribute a, constUtf8 value);
/*
* Start a predeclared attribute
*/
genxStatus genxStartAttribute(genxAttribute a);
/*
* 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 */