Boost logo

Boost-Commit :

From: stefan_at_[hidden]
Date: 2007-07-06 11:06:46


Author: stefan
Date: 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
New Revision: 7375
URL: http://svn.boost.org/trac/boost/changeset/7375

Log:
Rework source layout and build system to conform to boost standard.

Added:
   sandbox/xml/Jamfile
   sandbox/xml/LICENSE_1_0.txt
   sandbox/xml/boost-build.jam
   sandbox/xml/libs/
   sandbox/xml/libs/xml/
   sandbox/xml/libs/xml/build/
   sandbox/xml/libs/xml/example/
   sandbox/xml/libs/xml/example/Jamfile
   sandbox/xml/libs/xml/example/README
      - copied, changed from r7019, /sandbox/xml/tests/README
   sandbox/xml/libs/xml/example/article.xml
   sandbox/xml/libs/xml/example/config.cpp
   sandbox/xml/libs/xml/example/config.xml
   sandbox/xml/libs/xml/example/dom.cpp
   sandbox/xml/libs/xml/example/reader.cpp
   sandbox/xml/libs/xml/example/string.hpp
   sandbox/xml/libs/xml/example/traverse.cpp
   sandbox/xml/libs/xml/example/validate_dtd.cpp
   sandbox/xml/libs/xml/example/xi-book.xml
   sandbox/xml/libs/xml/example/xi-chapter1.xml
   sandbox/xml/libs/xml/example/xi-chapter2.xml
   sandbox/xml/libs/xml/example/xi-section1.xml
   sandbox/xml/libs/xml/example/xinclude.cpp
   sandbox/xml/libs/xml/src/
   sandbox/xml/libs/xml/src/Jamfile
   sandbox/xml/libs/xml/src/dom.cpp
   sandbox/xml/libs/xml/test/
   sandbox/xml/project-root.jam
Removed:
   sandbox/xml/tests/
Text files modified:
   sandbox/xml/boost/xml/dom/detail.hpp | 39 ++-------------------------------------
   sandbox/xml/boost/xml/dom/element.hpp | 6 +++---
   sandbox/xml/boost/xml/dom/parser.hpp | 15 +++------------
   sandbox/xml/boost/xml/dom/validate_dtd.hpp | 3 ++-
   sandbox/xml/libs/xml/example/README | 2 +-
   5 files changed, 11 insertions(+), 54 deletions(-)

Added: sandbox/xml/Jamfile
==============================================================================
--- (empty file)
+++ sandbox/xml/Jamfile 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,13 @@
+# Copyright 2007 Stefan Seefeld.
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+
+use-project boost
+ : $(BOOST_ROOT)
+ ;
+
+project boost/xml
+ : build-dir bin.v2
+ ;
\ No newline at end of file

Added: sandbox/xml/LICENSE_1_0.txt
==============================================================================
--- (empty file)
+++ sandbox/xml/LICENSE_1_0.txt 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,23 @@
+Boost Software License - Version 1.0 - August 17th, 2003
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.

Added: sandbox/xml/boost-build.jam
==============================================================================
--- (empty file)
+++ sandbox/xml/boost-build.jam 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,11 @@
+# Copyright 2007 Stefan Seefeld.
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+
+# Set the BOOST_ROOT environment variable on your command-line or in the
+# environment to point at the root of your regular Boost installation.
+
+JAMFILE = [Jj]amfile ;
+boost-build $(BOOST_ROOT)/tools/build/v2 ;

Modified: sandbox/xml/boost/xml/dom/detail.hpp
==============================================================================
--- sandbox/xml/boost/xml/dom/detail.hpp (original)
+++ sandbox/xml/boost/xml/dom/detail.hpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -25,45 +25,10 @@
 namespace detail
 {
 
-char const *node_type_names[] =
-{
- "internal node",
- "element",
- "attribute",
- "text node",
- "cdata block",
- "processing instruction",
- "comment"
-};
-
-
+extern char const *node_type_names[7];
 //. node_type_table maps libxml2 node types to node_type.
 //. Mask all node types not part of the public API.
-node_type node_type_table[] =
-{
- INTERNAL,
- ELEMENT, //XML_ELEMENT_NODE
- ATTRIBUTE, //XML_ATTRIBUTE_NODE
- TEXT, //XML_TEXT_NODE
- CDATA, //XML_CDATA_SECTION_NODE
- INTERNAL, //XML_ENTITY_REF_NODE
- INTERNAL, //XML_ENTITY_NODE
- PI, //XML_PI_NODE
- COMMENT, //XML_COMMENT_NODE
- INTERNAL, //XML_DOCUMENT_NODE
- INTERNAL, //XML_DOCUMENT_TYPE_NODE
- INTERNAL, //XML_DOCUMENT_FRAG_NODE
- INTERNAL, //XML_NOTATION_NODE
- INTERNAL, //XML_HTML_DOCUMENT_NODE
- INTERNAL, //XML_DTD_NODE
- INTERNAL, //XML_ELEMENT_DECL
- INTERNAL, //XML_ATTRIBUTE_DECL
- INTERNAL, //XML_ENTITY_DECL
- INTERNAL, //XML_NAMESPACE_DECL
- INTERNAL, //XML_XINCLUDE_START
- INTERNAL, //XML_XINCLUDE_END
- INTERNAL, //XML_DOCB_DOCUMENT_NODE
-};
+extern node_type node_type_table[22];
 
 //. Helper types used for cast<>()
 template <typename N> struct target {};

Modified: sandbox/xml/boost/xml/dom/element.hpp
==============================================================================
--- sandbox/xml/boost/xml/dom/element.hpp (original)
+++ sandbox/xml/boost/xml/dom/element.hpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -118,7 +118,7 @@
   for(xmlAttr *attr = this->impl()->properties; attr; attr = attr->next)
   {
     if(xmlStrEqual(attr->name, n))
- return dom::attribute<S>(attr);
+ return dom::attribute<S>((xmlNode *)attr);
   }
   return dom::attribute<S>(0);
 }
@@ -130,7 +130,7 @@
   for(xmlAttr *attr = this->impl()->properties; attr; attr = attr->next)
   {
     if(xmlStrEqual(attr->name, n))
- return dom::attribute<S>(attr);
+ return dom::attribute<S>((xmlNode *)attr);
   }
   return dom::attribute<S>(0);
 }
@@ -331,7 +331,7 @@
 typename element<S>::child_iterator
 element<S>::find(node_ptr<node<S> const> n)
 {
- xmlNode *child = impl(*n);
+ // xmlNode *child = impl(*n);
   for (child_iterator i = begin_children(); i != end_children(); ++i)
     if (**i == *n) return i;
   return end_children();

Modified: sandbox/xml/boost/xml/dom/parser.hpp
==============================================================================
--- sandbox/xml/boost/xml/dom/parser.hpp (original)
+++ sandbox/xml/boost/xml/dom/parser.hpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -57,26 +57,17 @@
   std::string error_msg_;
 };
 
-namespace detail
-{
-extern "C" void xml_error_callback(void *closure, xmlError *error)
-{
- parser *p = reinterpret_cast<parser *>(closure);
- p->error_callback(*error);
-}
-}
-
-parser::parser()
+inline parser::parser()
 {
   xmlSetStructuredErrorFunc(this, detail::xml_error_callback);
 }
 
-parser::~parser()
+inline parser::~parser()
 {
   xmlSetStructuredErrorFunc(0, 0);
 }
 
-void parser::error_callback(xmlError const &error)
+inline void parser::error_callback(xmlError const &error)
 {
   std::ostringstream oss;
   oss << "error in "

Modified: sandbox/xml/boost/xml/dom/validate_dtd.hpp
==============================================================================
--- sandbox/xml/boost/xml/dom/validate_dtd.hpp (original)
+++ sandbox/xml/boost/xml/dom/validate_dtd.hpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -49,7 +49,8 @@
   {
     int elements = xmlValidGetValidElements(node->prev, node,
                                             &*names.begin(), names.size());
- if (elements < names.size())
+ // FIXME: check for errors.
+ if (static_cast<unsigned>(elements) < names.size())
     {
       names.resize(elements);
       break;

Added: sandbox/xml/libs/xml/example/Jamfile
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/Jamfile 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,23 @@
+# Copyright 2007 Stefan Seefeld.
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+
+use-project /boost/xml : ../src ;
+
+lib libxml2 : : <name>xml2 <search>/usr/lib/ ;
+
+project : requirements
+ <include>/usr/include/libxml2
+ <include>../../..
+ <library>libxml2
+ <library>/boost/xml//boost_xml
+ ;
+
+exe reader : reader.cpp ;
+exe dom : dom.cpp dom2.cpp ;
+exe config : config.cpp ;
+exe xinclude : xinclude.cpp ;
+exe traverse : traverse.cpp ;
+exe validate_dtd : validate_dtd.cpp ;

Copied: sandbox/xml/libs/xml/example/README (from r7019, /sandbox/xml/tests/README)
==============================================================================
--- /sandbox/xml/tests/README (original)
+++ sandbox/xml/libs/xml/example/README 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -12,7 +12,7 @@
 
 validate_dtd: Test simple DTD-based validation.
 
-xinclude: Demonstrate simple XInclude processing (use './xinclude book.xml)
+xinclude: Demonstrate simple XInclude processing (use './xinclude xi-book.xml xi-book-out.xml)
 
 
 reader

Added: sandbox/xml/libs/xml/example/article.xml
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/article.xml 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+"http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd">
+<article>
+ <title>An Article</title>
+ <section id="section1">
+ <title>A section</title>
+ <para>This is a paragraph.</para>
+ </section>
+ <section id="section2">
+ <title>Another section</title>
+ <section id="section3">
+ <title>A sub-section</title>
+ <para>This paragraph refers to <xref linkend="section1"/>,
+ <xref linkend="section2"/>, and <xref linkend="section4"/>.</para>
+ </section>
+ </section>
+</article>
\ No newline at end of file

Added: sandbox/xml/libs/xml/example/config.cpp
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/config.cpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,25 @@
+// Copyright 2007 Stefan Seefeld.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/xml/dom.hpp>
+#include "string.hpp"
+#include <iostream>
+
+namespace dom = boost::xml::dom;
+
+int main(int argc, char **argv)
+{
+ try
+ {
+ document_ptr document(new dom::document<std::string>());
+ element_ptr root = document->create_root("config");
+ dtd_ptr doc_type = document->create_internal_subset("foo", "bar", "baz");
+ document->write_to_file("config.xml");
+ }
+ catch (std::exception const &e)
+ {
+ std::cerr << "Error : " << e.what() << std::endl;
+ }
+}

Added: sandbox/xml/libs/xml/example/config.xml
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/config.xml 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<!DOCTYPE foo PUBLIC "bar" "baz">
+<config/>

Added: sandbox/xml/libs/xml/example/dom.cpp
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/dom.cpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,106 @@
+// Copyright 2007 Stefan Seefeld.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/xml/dom.hpp>
+#include "string.hpp"
+#include <iostream>
+
+namespace dom = boost::xml::dom;
+
+int main(int argc, char **argv)
+{
+ if (argc != 2)
+ {
+ std::cerr << "Usage: example <xml-file>" << std::endl;
+ return -1;
+ }
+ try
+ {
+ // create a document from a file
+ document_ptr document = dom::parse_file<std::string>(argv[1], false);
+ element_ptr root = document->root();
+ std::cout << "the root node " << root->name()
+ << " has the following child nodes:" << std::endl;
+ for (element::child_iterator i = root->begin_children();
+ i != root->end_children();
+ ++i)
+ {
+ std::cout << " " << (*i)->name() << std::endl;
+ }
+ // find all sections, no matter where...
+ {
+ xpath path("//section");
+ std::cout << "searching with xpath '" << path.string() << "' in root node: ";
+ node_set set = path.find(root);
+ std::cout << set.size() << " nodes have been found:" << std::endl;
+ for (node_set::iterator i = set.begin(); i != set.end(); ++i)
+ {
+ //...and print their structural path
+ std::cout << " " << (*i)->path() << std::endl;
+ }
+ }
+ // find the title node (if there is one)
+ xpath path("title");
+ node_set set = path.find(root);
+ node_ptr title;
+ if (set.size()) title = set[0];
+ else { std::cout << "no title found !" << std::endl;}
+ // now insert an 'articleinfo' node
+ std::cout << "inserting 'articleinfo' element..." << std::endl;
+ element_ptr info = root->insert_element(root->begin_children(), "articleinfo");
+ if (title)
+ {
+ info->insert(info->begin_children(), title);
+ info->insert_comment(info->begin_children(), "This title was moved");
+ }
+ element_ptr author = info->append_element("author");
+ element_ptr firstname = author->append_element("firstname");
+ firstname->set_content("Joe");
+ element_ptr surname = author->append_element("surname");
+ surname->set_content("Random");
+ // and finally test whether intra-document links are well-formed
+ {
+ // to be well-formed, the 'linkend' attribute has to refer to
+ // an element in terms of its 'id'.
+ // find out whether there are linkend attributes that don't have
+ // corresponding 'id's
+ std::cout << "searching for unresolved internal references "
+ << "(see docbook manual):" << std::endl;
+ xpath linkend("//xref/@linkend");
+ node_set xrefs = linkend.find(root);
+ for (node_set::iterator i = xrefs.begin(); i != xrefs.end(); ++i)
+ {
+ attribute_ptr attribute = dom::cast<attribute_ptr>(*i);
+ xpath id("//*[@id=\"" + attribute->value() + "\"]");
+ node_set target = id.find(root);
+ if (!target.size())
+ {
+ std::cout << " document has reference to non-existing id '"
+ << attribute->value() << '\'' << std::endl;
+ std::cout << "removing invalid reference..." << std::endl;
+ // We are looking at a 'linkend' attribute, and we want to remove
+ // the 'xref' parent element from its parent, so we need to go two
+ // levels up.
+ element_ptr xref = (*i)->parent();
+ element_ptr parent = xref->parent();
+ // For simplicity's sake, assume the content is text only.
+ std::string content = xref->content();
+ element::child_iterator j = parent->find(xref);
+ if (j != parent->end_children())
+ {
+ parent->insert_text(j, content);
+ parent->remove(j);
+ }
+ }
+ }
+ }
+ std::cout << "writing modified document to 'article2.xml'..." << std::endl;
+ document->write_to_file("article2.xml");
+ }
+ catch (std::exception const &e)
+ {
+ std::cerr << "Error : " << e.what() << std::endl;
+ }
+}

Added: sandbox/xml/libs/xml/example/reader.cpp
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/reader.cpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,26 @@
+// Copyright 2007 Stefan Seefeld.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/xml/reader.hpp>
+
+using namespace boost::xml::reader;
+
+int main(int, char **)
+{
+ try
+ {
+ parser<std::string> parser("article.xml");
+ while (parser.next())
+ {
+ token_base<std::string> const &current = parser.get_token();
+ std::cout << current.depth() << ' ' << current.name() << ' ' << current.value() << ' '
+ << '(' << current.type() << ')' << std::endl;
+ }
+ }
+ catch (std::exception &e)
+ {
+ std::cerr << "Error: " << e.what() << std::endl;
+ }
+}

Added: sandbox/xml/libs/xml/example/string.hpp
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/string.hpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,44 @@
+#include <boost/xml/dom.hpp>
+#include <string>
+
+namespace boost
+{
+namespace xml
+{
+namespace dom
+{
+template <>
+struct converter<std::string>
+{
+ static xmlChar *in(std::string const &buffer)
+ {
+ return (xmlChar *)buffer.c_str();
+ }
+ static std::string out(xmlChar const *buffer)
+ {
+ return buffer ? std::string((char *)buffer) : std::string();
+ }
+};
+}
+}
+}
+
+typedef boost::xml::dom::node_ptr<boost::xml::dom::node<std::string> > node_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::node<std::string> const> const_node_ptr;
+typedef boost::xml::dom::element<std::string> element;
+typedef boost::xml::dom::node_ptr<element> element_ptr;
+typedef boost::xml::dom::node_ptr<element const> const_element_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::attribute<std::string> > attribute_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::attribute<std::string> const> const_attribute_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::text<std::string> > text_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::text<std::string> const> const_text_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::pi<std::string> > pi_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::pi<std::string> const> const_pi_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::comment<std::string> > comment_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::comment<std::string> const> const_comment_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::cdata<std::string> > cdata_ptr;
+typedef boost::xml::dom::node_ptr<boost::xml::dom::cdata<std::string> const> const_cdata_ptr;
+typedef std::auto_ptr<boost::xml::dom::document<std::string> > document_ptr;
+typedef boost::xml::dom::dtd_ptr<std::string> dtd_ptr;
+typedef boost::xml::dom::node_set<std::string> node_set;
+typedef boost::xml::dom::xpath<std::string> xpath;

Added: sandbox/xml/libs/xml/example/traverse.cpp
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/traverse.cpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,93 @@
+// Copyright 2007 Stefan Seefeld.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/xml/dom.hpp>
+#include "string.hpp"
+#include <iostream>
+
+namespace dom = boost::xml::dom;
+
+class traversal
+{
+public:
+ traversal() : indent_(0) {}
+ void traverse(node_ptr node)
+ {
+ if (!node) return;
+ switch (node->type())
+ {
+ case dom::ELEMENT: traverse(dom::cast<element_ptr>(node)); break;
+ case dom::ATTRIBUTE: traverse(dom::cast<attribute_ptr>(node)); break;
+ case dom::TEXT: traverse(dom::cast<text_ptr>(node)); break;
+ case dom::COMMENT: traverse(dom::cast<comment_ptr>(node)); break;
+ case dom::PI: traverse(dom::cast<pi_ptr>(node)); break;
+ case dom::CDATA: traverse(dom::cast<cdata_ptr>(node)); break;
+ default: break; // all other node types are ignored
+ }
+ }
+ void traverse(element_ptr node)
+ {
+ std::cout << indent() << "element: " << node->name() << std::endl;
+
+ ++indent_;
+ for (element::attribute_iterator i = node->begin_attributes();
+ i != node->end_attributes();
+ ++i)
+ traverse(*i);
+ for (element::child_iterator i = node->begin_children();
+ i != node->end_children();
+ ++i)
+ traverse(*i);
+ --indent_;
+ }
+ void traverse(attribute_ptr node)
+ {
+ std::cout << indent() << "attribute: "
+ << node->name() << "=\"" << node->value() << '"' << std::endl;
+ }
+ void traverse(text_ptr node)
+ {
+ std::cout << indent() << "text: '" << node->content() << '\'' << std::endl;
+ }
+ void traverse(comment_ptr node)
+ {
+ std::cout << indent() << "comment: '" << node->content() << '\'' << std::endl;
+ }
+ void traverse(pi_ptr node)
+ {
+ std::cout << indent() << "processing instruction: '"
+ << node->name() << ' ' << node->content() << '\'' << std::endl;
+ }
+ void traverse(cdata_ptr node)
+ {
+ std::cout << indent() << "cdata: '" << node->content() << '\'' << std::endl;
+ }
+
+private:
+ std::string indent() { return std::string(indent_, ' ');}
+
+ size_t indent_;
+};
+
+
+int main(int argc, char **argv)
+{
+ if (argc != 2)
+ {
+ std::cerr << "Usage: example <xml-file>" << std::endl;
+ return -1;
+ }
+ try
+ {
+ // create a document from a file
+ document_ptr document = dom::parse_file<std::string>(argv[1], false);
+ traversal t;
+ t.traverse(document->root());
+ }
+ catch (std::exception const &e)
+ {
+ std::cerr << "Error : " << e.what() << std::endl;
+ }
+}

Added: sandbox/xml/libs/xml/example/validate_dtd.cpp
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/validate_dtd.cpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,35 @@
+// Copyright 2007 Stefan Seefeld.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/xml/dom.hpp>
+#include "string.hpp"
+#include <iostream>
+
+namespace dom = boost::xml::dom;
+
+int main(int argc, char **argv)
+{
+ if (argc != 2)
+ {
+ std::cerr << "Usage: example <xml-file>" << std::endl;
+ return -1;
+ }
+ try
+ {
+ // create a document from a file
+ document_ptr document = dom::parse_file<std::string>(argv[1], true);
+ const_element_ptr root = document->root();
+ std::vector<std::string> children = dom::valid_elements(root, root->begin_children());
+ std::cout << "root may have these children:" << std::endl;
+ for (std::vector<std::string>::iterator i = children.begin();
+ i != children.end();
+ ++i)
+ std::cout << ' ' << *i << std::endl;
+ }
+ catch (std::exception const &e)
+ {
+ std::cerr << "Error : " << e.what() << std::endl;
+ }
+}

Added: sandbox/xml/libs/xml/example/xi-book.xml
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/xi-book.xml 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+"http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd">
+<book xmlns:xi="http://www.w3.org/2003/XInclude">
+ <title>A book</title>
+ <xi:include href="xi-chapter1.xml"/>
+ <xi:include href="xi-chapter2.xml"/>
+</book>

Added: sandbox/xml/libs/xml/example/xi-chapter1.xml
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/xi-chapter1.xml 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+"http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd">
+<chapter>
+ <title>A chapter</title>
+ <para>This is a paragraph.</para>
+</chapter>

Added: sandbox/xml/libs/xml/example/xi-chapter2.xml
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/xi-chapter2.xml 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+"http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd">
+<chapter xmlns:xi="http://www.w3.org/2003/XInclude">
+ <title>Another chapter</title>
+ <xi:include href="xi-section1.xml"/>
+</chapter>

Added: sandbox/xml/libs/xml/example/xi-section1.xml
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/xi-section1.xml 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+"http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd">
+<section>
+ <title>A section</title>
+ <para>A paragraph.</para>
+</section>

Added: sandbox/xml/libs/xml/example/xinclude.cpp
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/example/xinclude.cpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,52 @@
+// Copyright 2007 Stefan Seefeld.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/xml/dom.hpp>
+#include "string.hpp"
+#include <iostream>
+
+namespace dom = boost::xml::dom;
+
+int main(int argc, char **argv)
+{
+ if (argc != 3)
+ {
+ std::cerr << "Usage: " << argv[0] << " <xml-file> <output>" << std::endl;
+ return -1;
+ }
+ try
+ {
+ // create a document from a file
+ document_ptr document = dom::parse_file<std::string>(argv[1], false);
+ element_ptr root = document->root();
+ {
+ xpath path("//xi:include");
+ path.declare_namespace("xi", "http://www.w3.org/2003/XInclude");
+ std::cout << "searching for xi:include nodes: ";
+ node_set set = path.find(root);
+ std::cout << set.size() << " nodes have been found." << std::endl;
+ }
+ // process xinclude nodes in-place
+ std::cout << "process xinclude: " << std::endl;
+ dom::process_xinclude(*document);
+ {
+ xpath path("//section");
+ std::cout << "searching for sections: ";
+ node_set set = path.find(root);
+ std::cout << set.size() << " nodes have been found." << std::endl;
+ for (node_set::iterator i = set.begin(); i != set.end(); ++i)
+ {
+ //...and print their structural path
+ std::cout << " " << (*i)->path() << std::endl;
+ }
+ }
+ std::cout << "writing modified document to 'xi-book2.xml'..." << std::endl;
+ document->write_to_file(argv[2]);
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << "Error : " << e.what() << std::endl;
+ }
+}

Added: sandbox/xml/libs/xml/src/Jamfile
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/src/Jamfile 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,18 @@
+# Copyright 2007 Stefan Seefeld.
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+lib libxml2 : : <name>xml2 <search>/usr/lib/ ;
+
+project boost/xml
+ : requirements
+ <include>/usr/include/libxml2
+ <include>../../..
+ <library>libxml2
+ <link>shared:<define>BOOST_ALL_DYN_LINK=1
+ ;
+
+lib boost_xml
+ : dom.cpp
+ ;

Added: sandbox/xml/libs/xml/src/dom.cpp
==============================================================================
--- (empty file)
+++ sandbox/xml/libs/xml/src/dom.cpp 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,59 @@
+#include <boost/xml/dom/parser.hpp>
+#include <boost/xml/dom/detail.hpp>
+
+namespace boost
+{
+namespace xml
+{
+namespace dom
+{
+namespace detail
+{
+
+extern "C" void xml_error_callback(void *closure, xmlError *error)
+{
+ parser *p = reinterpret_cast<parser *>(closure);
+ p->error_callback(*error);
+}
+
+char const *node_type_names[7] =
+{
+ "internal node",
+ "element",
+ "attribute",
+ "text node",
+ "cdata block",
+ "processing instruction",
+ "comment"
+};
+
+node_type node_type_table[22] =
+{
+ INTERNAL,
+ ELEMENT, //XML_ELEMENT_NODE
+ ATTRIBUTE, //XML_ATTRIBUTE_NODE
+ TEXT, //XML_TEXT_NODE
+ CDATA, //XML_CDATA_SECTION_NODE
+ INTERNAL, //XML_ENTITY_REF_NODE
+ INTERNAL, //XML_ENTITY_NODE
+ PI, //XML_PI_NODE
+ COMMENT, //XML_COMMENT_NODE
+ INTERNAL, //XML_DOCUMENT_NODE
+ INTERNAL, //XML_DOCUMENT_TYPE_NODE
+ INTERNAL, //XML_DOCUMENT_FRAG_NODE
+ INTERNAL, //XML_NOTATION_NODE
+ INTERNAL, //XML_HTML_DOCUMENT_NODE
+ INTERNAL, //XML_DTD_NODE
+ INTERNAL, //XML_ELEMENT_DECL
+ INTERNAL, //XML_ATTRIBUTE_DECL
+ INTERNAL, //XML_ENTITY_DECL
+ INTERNAL, //XML_NAMESPACE_DECL
+ INTERNAL, //XML_XINCLUDE_START
+ INTERNAL, //XML_XINCLUDE_END
+ INTERNAL, //XML_DOCB_DOCUMENT_NODE
+};
+
+} // namespace boost::xml::dom::detail
+} // namespace boost::xml::dom
+} // namespace boost::xml
+} // namespace boost

Added: sandbox/xml/project-root.jam
==============================================================================
--- (empty file)
+++ sandbox/xml/project-root.jam 2007-07-06 11:06:42 EDT (Fri, 06 Jul 2007)
@@ -0,0 +1,9 @@
+# Copyright 2007 Stefan Seefeld.
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+
+import os ;
+
+path-constant BOOST_ROOT : [ os.environ BOOST_ROOT ] ;
\ No newline at end of file


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk