diff -urN libxml++-1.0.5/libxml++/document.h libxml++/libxml++/document.h --- libxml++-1.0.5/libxml++/document.h 2005-02-12 00:13:28.000000000 +0100 +++ libxml++/libxml++/document.h 2007-03-22 17:46:29.000000000 +0100 @@ -17,13 +17,13 @@ #include #include -#include +#include #ifndef DOXYGEN_SHOULD_SKIP_THIS extern "C" { struct _xmlDoc; struct _xmlEntity; -} +}; #endif //DOXYGEN_SHOULD_SKIP_THIS namespace xmlpp diff -urN libxml++-1.0.5/libxml++/io/ostreamoutputbuffer.h libxml++/libxml++/io/ostreamoutputbuffer.h --- libxml++-1.0.5/libxml++/io/ostreamoutputbuffer.h 2004-03-03 15:09:43.000000000 +0100 +++ libxml++/libxml++/io/ostreamoutputbuffer.h 2007-03-22 17:46:29.000000000 +0100 @@ -13,7 +13,7 @@ #include #include -#include +#include namespace xmlpp { diff -urN libxml++-1.0.5/libxml++/nodes/element.cc libxml++/libxml++/nodes/element.cc --- libxml++-1.0.5/libxml++/nodes/element.cc 2004-02-16 11:53:51.000000000 +0100 +++ libxml++/libxml++/nodes/element.cc 2007-03-26 16:00:06.000000000 +0200 @@ -10,6 +10,9 @@ #include +#include + + namespace xmlpp { @@ -93,6 +96,14 @@ return 0; } +Attribute* Element::set_attribute(const std::string& name, const unsigned int value, + const std::string& ns_prefix) +{ + std::ostringstream valueStream; + valueStream << value; + return set_attribute(name, valueStream.str(), ns_prefix); +} + void Element::remove_attribute(const std::string& name, const std::string& ns_prefix) { if (ns_prefix.empty()) diff -urN libxml++-1.0.5/libxml++/nodes/element.h libxml++/libxml++/nodes/element.h --- libxml++-1.0.5/libxml++/nodes/element.h 2004-03-03 15:09:45.000000000 +0100 +++ libxml++/libxml++/nodes/element.h 2007-03-26 16:00:06.000000000 +0200 @@ -58,6 +58,17 @@ Attribute* set_attribute(const std::string& name, const std::string& value, const std::string& ns_prefix = std::string()); + /** Set the value of the attribute with this name, and optionally with this namespace. + * A matching attribute will be added if no matching attribute already exists. + * For finer control, you might want to use get_attribute() and use the methods of the Attribute class. + * @param name The name of the attribute whose value will change. + * @param value The new value for the attribute + * @param ns_prefix Namespace prefix. If the prefix has not been declared then this method will throw an exception. + * @return The attribute that was changed, or 0 is no suitable Attribute was found. + */ + Attribute* set_attribute(const std::string& name, const unsigned int value, + const std::string& ns_prefix = std::string()); + /** Remove the attribute with this name, and optionally with this namespace. * @param name The name of the attribute to be removed * @param ns_prefix Namespace prefix. If specified, the attribute will be removed only if the attribute has this namespace. diff -urN libxml++-1.0.5/libxml++/nodes/node.cc libxml++/libxml++/nodes/node.cc --- libxml++-1.0.5/libxml++/nodes/node.cc 2005-02-12 00:31:49.000000000 +0100 +++ libxml++/libxml++/nodes/node.cc 2007-03-22 17:46:29.000000000 +0100 @@ -10,6 +10,8 @@ #include #include +#include + #include namespace xmlpp @@ -145,9 +147,21 @@ return retn; } + + NodeSet Node::find(const std::string& xpath) const { + return find(xpath, "", ""); +} + +NodeSet Node::find(const std::string& xpath, const std::string & prefix, const std::string & ns_uri) const +{ xmlXPathContext* ctxt = xmlXPathNewContext(impl_->doc); + + if((0 < prefix.size()) && (0 < ns_uri.size())) { + xmlXPathRegisterNs(ctxt, (const xmlChar*)prefix.c_str(),(const xmlChar*)ns_uri.c_str()); + } + ctxt->node = impl_; xmlXPathObject* result = xmlXPathEval((const xmlChar*)xpath.c_str(), ctxt); diff -urN libxml++-1.0.5/libxml++/nodes/node.h libxml++/libxml++/nodes/node.h --- libxml++-1.0.5/libxml++/nodes/node.h 2005-02-12 00:13:29.000000000 +0100 +++ libxml++/libxml++/nodes/node.h 2007-03-22 17:46:29.000000000 +0100 @@ -103,6 +103,9 @@ /** Find nodes from a XPath expression */ NodeSet find(const std::string& xpath) const; + /** Find node from a XPath expression usinng a given name space */ + NodeSet find(const std::string& xpath, const std::string & prefix, const std::string & ns_uri) const; + ///Access the underlying libxml implementation. _xmlNode* cobj(); diff -urN libxml++-1.0.5/libxml++/parsers/parser.cc libxml++/libxml++/parsers/parser.cc --- libxml++-1.0.5/libxml++/parsers/parser.cc 2004-08-13 23:08:43.000000000 +0200 +++ libxml++/libxml++/parsers/parser.cc 2007-03-22 17:46:29.000000000 +0100 @@ -10,6 +10,8 @@ #include //For va_list. +#include //For std::auto_ptr + namespace xmlpp { Parser::Parser() diff -urN libxml++-1.0.5/libxml++/parsers/parser.h libxml++/libxml++/parsers/parser.h --- libxml++-1.0.5/libxml++/parsers/parser.h 2005-02-12 00:13:29.000000000 +0100 +++ libxml++/libxml++/parsers/parser.h 2007-03-22 17:46:29.000000000 +0100 @@ -16,7 +16,7 @@ #include #include -#include +#include #ifdef WIN32 //TODO: Why do we do this? murrayc. #define vsnprintf _vsnprintf @@ -25,7 +25,7 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS extern "C" { struct _xmlParserCtxt; -} +}; #endif //DOXYGEN_SHOULD_SKIP_THIS namespace xmlpp { diff -urN libxml++-1.0.5/libxml++/parsers/textreader.cc libxml++/libxml++/parsers/textreader.cc --- libxml++-1.0.5/libxml++/parsers/textreader.cc 1970-01-01 01:00:00.000000000 +0100 +++ libxml++/libxml++/parsers/textreader.cc 2007-03-22 17:46:29.000000000 +0100 @@ -0,0 +1,372 @@ +#include +#include + +#include + +namespace xmlpp +{ + + struct TextReader::PropertyReader + { + TextReader & owner_; + PropertyReader(TextReader & owner) + : owner_(owner) + {} + + int Int(int value); + bool Bool(int value); + char Char(int value); + Glib::ustring String(xmlChar * value, bool free = false); + Glib::ustring String(xmlChar const * value); + }; + +TextReader::TextReader( + const Glib::ustring& URI) + : propertyreader(new PropertyReader(*this)), impl_( xmlNewTextReaderFilename(URI.c_str()) ) +{ + if( ! impl_ ) + throw internal_error("Cannot instantiate underlying libxml2 structure"); +} + +TextReader::~TextReader() +{ + xmlFreeTextReader(impl_); +} + +bool TextReader::read() +{ + return propertyreader->Bool( + xmlTextReaderRead(impl_)); +} + +Glib::ustring TextReader::read_inner_xml() +{ + return propertyreader->String( + xmlTextReaderReadInnerXml(impl_), true); +} + +Glib::ustring TextReader::read_outer_xml() +{ + return propertyreader->String( + xmlTextReaderReadOuterXml(impl_), true); +} + +Glib::ustring TextReader::read_string() +{ + return propertyreader->String( + xmlTextReaderReadString(impl_), true); +} + +bool TextReader::read_attribute_value() +{ + return propertyreader->Bool( + xmlTextReaderReadAttributeValue(impl_)); +} + +int TextReader::get_attribute_count() const +{ + return propertyreader->Int( + xmlTextReaderAttributeCount(impl_)); +} + +Glib::ustring TextReader::get_base_uri() const +{ + return propertyreader->String( + xmlTextReaderBaseUri(impl_)); +} + +int TextReader::get_depth() const +{ + return propertyreader->Int( + xmlTextReaderDepth(impl_)); +} + +bool TextReader::has_attributes() const +{ + return propertyreader->Bool( + xmlTextReaderHasAttributes(impl_)); +} + +bool TextReader::has_value() const +{ + return propertyreader->Bool( + xmlTextReaderHasValue(impl_)); +} + +bool TextReader::is_default() const +{ + return propertyreader->Bool( + xmlTextReaderIsDefault(impl_)); +} + +bool TextReader::is_empty_element() const +{ + return propertyreader->Bool( + xmlTextReaderIsEmptyElement(impl_)); +} + +Glib::ustring TextReader::get_local_name() const +{ + return propertyreader->String( + xmlTextReaderLocalName(impl_)); +} + +Glib::ustring TextReader::get_name() const +{ + return propertyreader->String( + xmlTextReaderName(impl_)); +} + +Glib::ustring TextReader::get_namespace_uri() const +{ + return propertyreader->String( + xmlTextReaderNamespaceUri(impl_)); +} + +TextReader::xmlNodeType TextReader::get_node_type() const +{ + int result = xmlTextReaderNodeType(impl_); + if(result == -1) + check_for_exceptions(); + return (xmlNodeType)result; +} + +Glib::ustring TextReader::get_prefix() const +{ + return propertyreader->String( + xmlTextReaderPrefix(impl_)); +} + +char TextReader::get_quote_char() const +{ + return propertyreader->Char( + xmlTextReaderQuoteChar(impl_)); +} + +Glib::ustring TextReader::get_value() const +{ + return propertyreader->String( + xmlTextReaderValue(impl_), true); +} + +Glib::ustring TextReader::get_xml_lang() const +{ + return propertyreader->String( + xmlTextReaderXmlLang(impl_)); +} + +TextReader::xmlReadState TextReader::get_read_state() const +{ + int result = xmlTextReaderReadState(impl_); + if(result == -1) + check_for_exceptions(); + return (xmlReadState)result; +} + +void TextReader::close() +{ + if(xmlTextReaderClose(impl_) == -1) + check_for_exceptions(); +} + +Glib::ustring TextReader::get_attribute(int number) const +{ + return propertyreader->String( + xmlTextReaderGetAttributeNo(impl_, number), true); +} + +Glib::ustring TextReader::get_attribute( + const Glib::ustring& name) const +{ + return propertyreader->String( + xmlTextReaderGetAttribute(impl_, (const xmlChar *)name.c_str()), true); +} + +Glib::ustring TextReader::get_attribute( + const Glib::ustring& localName, + const Glib::ustring& namespaceURI) const +{ + return propertyreader->String( + xmlTextReaderGetAttributeNs(impl_, (const xmlChar *)localName.c_str(), (const xmlChar *)namespaceURI.c_str()), true); +} + +Glib::ustring TextReader::lookup_namespace( + const Glib::ustring& prefix) const +{ + return propertyreader->String( + xmlTextReaderLookupNamespace(impl_, (const xmlChar *)prefix.c_str()), true); +} + +bool TextReader::move_to_attribute(int number) +{ + return propertyreader->Bool( + xmlTextReaderMoveToAttributeNo(impl_, number)); +} + +bool TextReader::move_to_attribute( + const Glib::ustring& name) +{ + return propertyreader->Bool( + xmlTextReaderMoveToAttribute(impl_, (const xmlChar *)name.c_str())); +} + +bool TextReader::move_to_attribute( + const Glib::ustring& localName, + const Glib::ustring& namespaceURI) +{ + return propertyreader->Bool( + xmlTextReaderMoveToAttributeNs(impl_, (const xmlChar *)localName.c_str(), (const xmlChar *)namespaceURI.c_str())); +} + +bool TextReader::move_to_first_attribute() +{ + return propertyreader->Bool( + xmlTextReaderMoveToFirstAttribute(impl_)); +} + +bool TextReader::move_to_next_attribute() +{ + return propertyreader->Bool( + xmlTextReaderMoveToNextAttribute(impl_)); +} + +bool TextReader::move_to_element() +{ + return propertyreader->Bool( + xmlTextReaderMoveToElement(impl_)); +} + +bool TextReader::get_normalization() const +{ + return propertyreader->Bool( + xmlTextReaderNormalization(impl_)); +} + +bool TextReader::get_parser_property( + ParserProperties property) const +{ + return propertyreader->Bool( + xmlTextReaderGetParserProp(impl_, (int)property)); +} + +void TextReader::set_parser_property( + ParserProperties property, + bool value) +{ + if(xmlTextReaderSetParserProp(impl_, (int)property, value?1:0)) + check_for_exceptions(); +} + +Node* TextReader::get_current_node() +{ + xmlNodePtr node = xmlTextReaderCurrentNode(impl_); + if(node) + return static_cast(node->_private); + + check_for_exceptions(); + return 0; +} + +const Node* TextReader::get_current_node() const +{ + xmlNodePtr node = xmlTextReaderCurrentNode(impl_); + if(node) + return static_cast(node->_private); + + check_for_exceptions(); + return 0; +} + +/* +TODO: add a private constructor to Document. +Document* TextReader::CurrentDocument() +{ + xmlDocPtr doc = xmlTextReaderCurrentDoc(impl_); + if(doc) + return new Document(doc); +} +*/ + +Node* TextReader::expand() +{ + xmlNodePtr node = xmlTextReaderExpand(impl_); + if(node) + return static_cast(node->_private); + + check_for_exceptions(); + return 0; +} + +bool TextReader::next() +{ + return propertyreader->Bool( + xmlTextReaderNext(impl_)); +} + +bool TextReader::is_valid() const +{ + return propertyreader->Bool( + xmlTextReaderIsValid(impl_)); +} + + + + +int TextReader::PropertyReader::Int( + int value) +{ + if(value == -1) + owner_.check_for_exceptions(); + return value; +} + +bool TextReader::PropertyReader::Bool( + int value) +{ + if(value == -1) + owner_.check_for_exceptions(); + + return value; +} + +char TextReader::PropertyReader::Char( + int value) +{ + owner_.check_for_exceptions(); + return value; +} + +Glib::ustring TextReader::PropertyReader::String( + xmlChar * value, + bool free) +{ + owner_.check_for_exceptions(); + + if(value == (xmlChar *)0) + return Glib::ustring(); + + Glib::ustring result = (char *)value; + + if(free) + xmlFree(value); + + return result; +} + +Glib::ustring TextReader::PropertyReader::String( + xmlChar const * value) +{ + owner_.check_for_exceptions(); + + if(value == (xmlChar *)0) + return Glib::ustring(); + + return (const char *)value; +} + +void TextReader::check_for_exceptions() const +{ + //TODO: Shouldn't we do something here? murrayc. +} + +} // namespace xmlpp diff -urN libxml++-1.0.5/libxml++/parsers/textreader.h libxml++/libxml++/parsers/textreader.h --- libxml++-1.0.5/libxml++/parsers/textreader.h 1970-01-01 01:00:00.000000000 +0100 +++ libxml++/libxml++/parsers/textreader.h 2007-03-22 17:46:29.000000000 +0100 @@ -0,0 +1,186 @@ +/* xml++.h + * libxml++ and this file are copyright (C) 2000 by Ari Johnson, and + * are covered by the GNU Lesser General Public License, which should be + * included with libxml++ as the file COPYING. + */ + +#ifndef __LIBXMLPP_XMLREADER_H +#define __LIBXMLPP_XMLREADER_H + +#include +#include + +#include + +extern "C" +{ + struct _xmlTextReader; +} + +namespace xmlpp +{ + +class TextReader: NonCopyable +{ + public: + enum xmlNodeType { + Attribute = 2, + CDATA = 4, + Comment = 8, + Document = 9, + DocumentFragment = 11, + DocumentType = 10, + Element = 1, + EndElement = 15, + EndEntity = 16, + Entity = 6, + EntityReference = 5, + None = 0, + Notation = 12, + ProcessingInstruction = 7, + SignificantWhitespace = 14, + Text = 3, + Whitespace = 13, + XmlDeclaration = 17 + }; + + enum xmlReadState + { + Closed = 4, + EndOfFile = 3, + Error = 2, + Initial = 0, + Interactive = 1 + }; + + enum ParserProperties + { + LoadDtd = 1, + DefaultAttrs = 2, + Validate = 3, + SubstEntities = 4 + }; + + public: + // TextReader(InputBuffer) + TextReader(const Glib::ustring& URI); + ~TextReader(); + + /** Moves the position of the current instance to the next node in the stream, exposing its properties. + * @return true if the node was read successfully, false if there is no more nodes to read. + */ + bool read(); + + /** Reads the contents of the current node, including child nodes and markup. + * @return A Glib::ustring containing the XML content, or and empty Glib::ustring if the current node is neither an element nor attribute, or has no child nodes. + */ + Glib::ustring read_inner_xml(); + + /** Reads the current node and its contents, including child nodes and markup. + * @return A Glib::ustring containing the XML content, or an empty Glib::ustring if the current node is neither an element nor attribute. + */ + Glib::ustring read_outer_xml(); + + /** Reads the contents of an element or a text node as a string. + * @return A Glib::ustring containing the contents of the Element or Text node, or an empty Glib::ustring if the reader is positioned on any other type of node. + */ + Glib::ustring read_string(); + + /** Parses an attribute value into one or more Text and EntityReference nodes. + * @return A bool where true indicates the attribute value was parsed, and false indicates the reader was not positioned on an attribute node or all the attribute values have been read. + */ + bool read_attribute_value(); + + /** Gets the number of attributes on the current node. + * @return The number of attributes on the current node, or zero if the current node does not support attributes. + */ + int get_attribute_count() const; + + /** Gets the base Uniform Resource Identifier (URI) of the current node. + * @return The base URI of the current node or an empty Glib::ustring if not available. + */ + Glib::ustring get_base_uri() const; + + /** Gets the depth of the current node in the XML document. + * @return The depth of the current node in the XML document. + */ + int get_depth() const; + + /** Gets a value indicating whether the current node has any attributes. + * @return true if the current has attributes, false otherwise. + */ + bool has_attributes() const; + + /** Whether the node can have a text value. + * @return true if the current node can have an associated text value, false otherwise. + */ + bool has_value() const; + + /** Whether an Attribute node was generated from the default value defined in the DTD or schema. + * @return true if defaulted, false otherwise. + */ + bool is_default() const; + + /** Check if the current node is empty + * @return true if empty, false otherwise. + */ + bool is_empty_element() const; + + Glib::ustring get_local_name() const; + Glib::ustring get_name() const; + Glib::ustring get_namespace_uri() const; + + xmlNodeType get_node_type() const; + + Glib::ustring get_prefix() const; + char get_quote_char() const; + + Glib::ustring get_value() const; + Glib::ustring get_xml_lang() const; + + xmlReadState get_read_state() const; + + void close(); + + Glib::ustring get_attribute(int number) const; + Glib::ustring get_attribute(const Glib::ustring& name) const; + Glib::ustring get_attribute(const Glib::ustring& local_name, const Glib::ustring& ns_uri) const; + + // TODO InputBuffer GetRemainder; + + Glib::ustring lookup_namespace(const Glib::ustring& prefix) const; + + bool move_to_attribute(int number); + bool move_to_attribute(const Glib::ustring& name); + bool move_to_attribute(const Glib::ustring& local_name, const Glib::ustring& ns_uri); + bool move_to_first_attribute(); + bool move_to_next_attribute(); + bool move_to_element(); + + bool get_normalization() const; + void set_normalization(bool value); + + bool get_parser_property(ParserProperties property) const; + void set_parser_property(ParserProperties property, bool value); + + Node* get_current_node(); + const Node* get_current_node() const; +// Document* CurrentDocument(); + Node* expand(); + + bool next(); + bool is_valid() const; + + private: + struct PropertyReader; + friend struct PropertyReader; + + std::auto_ptr propertyreader; + void check_for_exceptions() const; + + _xmlTextReader* impl_; +}; + +} + +#endif