mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 08:31:43 +02:00
Added XMLStream API tests
This commit is contained in:
@@ -23,49 +23,35 @@ namespace XML
|
||||
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)
|
||||
{
|
||||
}
|
||||
QName();
|
||||
QName(const std::string& name);
|
||||
QName(const std::string& ns, const std::string& name);
|
||||
QName(const std::string& ns, const std::string& name, const std::string& prefix);
|
||||
|
||||
const std::string& namespace_() const
|
||||
{
|
||||
return ns_;
|
||||
return _ns;
|
||||
}
|
||||
const std::string& name() const
|
||||
{
|
||||
return name_;
|
||||
return _name;
|
||||
}
|
||||
const std::string& prefix() const
|
||||
{
|
||||
return prefix_;
|
||||
return _prefix;
|
||||
}
|
||||
|
||||
std::string& namespace_()
|
||||
{
|
||||
return ns_;
|
||||
return _ns;
|
||||
}
|
||||
std::string& name()
|
||||
{
|
||||
return name_;
|
||||
return _name;
|
||||
}
|
||||
std::string& prefix()
|
||||
{
|
||||
return prefix_;
|
||||
return _prefix;
|
||||
}
|
||||
|
||||
// Printable representation in the [<namespace>#]<name> form.
|
||||
@@ -77,12 +63,12 @@ public:
|
||||
public:
|
||||
friend bool operator<(const QName& x, const QName& y)
|
||||
{
|
||||
return x.ns_ < y.ns_ || (x.ns_ == y.ns_ && x.name_ < y.name_);
|
||||
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_;
|
||||
return x._ns == y._ns && x._name == y._name;
|
||||
}
|
||||
|
||||
friend bool operator!=(const QName& x, const QName& y)
|
||||
@@ -91,9 +77,9 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::string ns_;
|
||||
std::string name_;
|
||||
std::string prefix_;
|
||||
std::string _ns;
|
||||
std::string _name;
|
||||
std::string _prefix;
|
||||
};
|
||||
|
||||
XML_API std::ostream& operator<<(std::ostream&, const QName&);
|
||||
|
@@ -2,8 +2,8 @@
|
||||
// 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
|
||||
#ifndef POCO_XML_XMLSTREAMPARSER_H
|
||||
#define POCO_XML_XMLSTREAMPARSER_H
|
||||
|
||||
// We only support UTF-8 expat.
|
||||
//
|
||||
@@ -31,6 +31,21 @@ namespace XML
|
||||
class XML_API XMLStreamParser
|
||||
{
|
||||
public:
|
||||
/// Parsing events.
|
||||
enum EventType
|
||||
{
|
||||
// If adding new events, also update the stream insertion operator.
|
||||
//
|
||||
StartElement,
|
||||
EndElement,
|
||||
StartAttribute,
|
||||
EndAttribute,
|
||||
Characters,
|
||||
StartNamespaceDecl,
|
||||
EndNamespaceDecl,
|
||||
Eof
|
||||
};
|
||||
|
||||
typedef unsigned short FeatureType;
|
||||
|
||||
// If both receive_attributes_event and receive_attributes_map are
|
||||
@@ -58,28 +73,8 @@ public:
|
||||
//
|
||||
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
|
||||
@@ -103,6 +98,11 @@ public:
|
||||
return event_;
|
||||
}
|
||||
|
||||
const std::string& inputName() const
|
||||
{
|
||||
return iname_;
|
||||
}
|
||||
|
||||
// Event data.
|
||||
//
|
||||
const QName& qname() const
|
||||
@@ -160,8 +160,7 @@ public:
|
||||
// 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;
|
||||
const std::string& attribute(const std::string& name) const;
|
||||
|
||||
template<typename T>
|
||||
T attribute(const std::string& name) const;
|
||||
@@ -316,7 +315,8 @@ private:
|
||||
{
|
||||
std::istream* is;
|
||||
const void* buf;
|
||||
}data_;
|
||||
}
|
||||
data_;
|
||||
|
||||
std::size_t size_;
|
||||
|
||||
@@ -329,7 +329,8 @@ private:
|
||||
enum
|
||||
{
|
||||
state_next, state_peek
|
||||
}state_;
|
||||
}
|
||||
state_;
|
||||
EventType event_;
|
||||
EventType queue_;
|
||||
|
||||
@@ -399,7 +400,7 @@ private:
|
||||
|
||||
const ElementEntry* get_element_() const;
|
||||
|
||||
void pop_element();
|
||||
void popElement();
|
||||
};
|
||||
|
||||
XML_API std::ostream& operator<<(std::ostream&, XMLStreamParser::EventType);
|
||||
@@ -608,6 +609,7 @@ T XMLStreamParser::element(const QName& qn, const T& dv)
|
||||
|
||||
return dv;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -31,36 +31,20 @@ public:
|
||||
|
||||
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_;
|
||||
}
|
||||
|
||||
const char* name() const throw();
|
||||
Poco::UInt64 line() const;
|
||||
Poco::UInt64 column() const;
|
||||
const std::string& description() const;
|
||||
virtual const char* what() const throw ();
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
std::string name_;
|
||||
Poco::UInt64 line_;
|
||||
Poco::UInt64 column_;
|
||||
std::string description_;
|
||||
std::string what_;
|
||||
std::string _name;
|
||||
Poco::UInt64 _line;
|
||||
Poco::UInt64 _column;
|
||||
std::string _description;
|
||||
std::string _what;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -2,8 +2,8 @@
|
||||
// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC
|
||||
// license : MIT; see accompanying LICENSE file
|
||||
|
||||
#ifndef POCO_XML_XMLSERIALIZER
|
||||
#define POCO_XML_XMLSERIALIZER
|
||||
#ifndef POCO_XML_XMLSERIALIZER_H
|
||||
#define POCO_XML_XMLSERIALIZER_H
|
||||
|
||||
#include "QName.h"
|
||||
#include "ValueTraits.h"
|
||||
@@ -17,7 +17,6 @@ namespace Poco
|
||||
{
|
||||
namespace XML
|
||||
{
|
||||
class XMLStreamSerializer;
|
||||
|
||||
class XML_API XMLStreamSerializer
|
||||
{
|
||||
@@ -32,13 +31,13 @@ public:
|
||||
// Otherwise, those are reported as the XMLStreamSerializerException exception.
|
||||
//
|
||||
XMLStreamSerializer(std::ostream&, const std::string& output_name, unsigned short indentation = 2);
|
||||
~XMLStreamSerializer();
|
||||
|
||||
const std::string& outputName() const
|
||||
{
|
||||
return oname_;
|
||||
return _oname;
|
||||
}
|
||||
|
||||
~XMLStreamSerializer();
|
||||
|
||||
void startElement(const QName& qname);
|
||||
|
||||
@@ -128,13 +127,13 @@ private:
|
||||
|
||||
void handleError(genxStatus);
|
||||
|
||||
std::ostream& os_;
|
||||
std::ostream::iostate os_state_;// Original exception state.
|
||||
const std::string oname_;
|
||||
std::ostream& _outputStream;
|
||||
std::ostream::iostate _osState_;// Original exception state.
|
||||
const std::string _oname;
|
||||
|
||||
genxWriter s_;
|
||||
genxSender sender_;
|
||||
std::size_t depth_;
|
||||
genxWriter _writer;
|
||||
genxSender _sender;
|
||||
std::size_t _depth;
|
||||
};
|
||||
|
||||
inline void XMLStreamSerializer::startElement(const QName& qname)
|
||||
|
@@ -36,10 +36,9 @@ struct XML_API XMLStreamSerializerException:
|
||||
private:
|
||||
void init();
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::string description_;
|
||||
std::string what_;
|
||||
std::string _name;
|
||||
std::string _description;
|
||||
std::string _what;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user