summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/cxx/tree/xpath/README18
-rw-r--r--examples/cxx/tree/xpath/driver-2.cxx139
-rw-r--r--examples/cxx/tree/xpath/makefile2
3 files changed, 7 insertions, 152 deletions
diff --git a/examples/cxx/tree/xpath/README b/examples/cxx/tree/xpath/README
index 48d40d6..1187743 100644
--- a/examples/cxx/tree/xpath/README
+++ b/examples/cxx/tree/xpath/README
@@ -30,17 +30,13 @@ dom-parse.cxx
XML document to a DOM document.
driver.cxx
- Driver for Xerces-C++ 3.x.y/XQilla 2.2.x. It first calls the above
- parse() function to parse the input file to a DOM document using
- XQilla-provided DOM Implementation with support for XPath 2. It
- then parses the DOM document to the object model. Finally, it
- prepares and executes an XPath query on the underlying DOM
- document and then handles the result by getting back from the
- returned DOM nodes to object model nodes.
-
-driver-2.cxx
- Driver for Xerces-C++ 2.x.y/XQilla 2.1.x. It performs the same set
- of actions as driver.cxx above.
+ Driver for the example. It first calls the above parse() function to
+ parse the input file to a DOM document using XQilla-provided DOM
+ Implementation with support for XPath 2. It then parses the DOM
+ document to the object model. Finally, it prepares and executes
+ an XPath query on the underlying DOM document and then handles
+ the result by getting back from the returned DOM nodes to object
+ model nodes.
To run the example on the sample XML document simply execute:
diff --git a/examples/cxx/tree/xpath/driver-2.cxx b/examples/cxx/tree/xpath/driver-2.cxx
deleted file mode 100644
index ccbdd7c..0000000
--- a/examples/cxx/tree/xpath/driver-2.cxx
+++ /dev/null
@@ -1,139 +0,0 @@
-// file : examples/cxx/tree/xpath/driver.cxx
-// author : Boris Kolpackov <boris@codesynthesis.com>
-// copyright : not copyrighted - public domain
-
-#include <memory> // std::auto_ptr
-#include <string>
-#include <fstream>
-#include <iostream>
-
-#include <xercesc/dom/DOM.hpp>
-
-#include <xqilla/xqilla-dom3.hpp>
-
-#include <xsd/cxx/xml/string.hxx> // xml::string, xml::transcode
-
-#include "dom-parse.hxx"
-
-#include "people.hxx"
-
-using namespace std;
-using namespace xercesc;
-namespace xml = xsd::cxx::xml;
-
-int
-main (int argc, char* argv[])
-{
- if (argc != 2)
- {
- cerr << "usage: " << argv[0] << " people.xml" << endl;
- return 1;
- }
-
- int r (0);
-
- // Initialise Xerces-C++ and XQilla.
- //
- XQillaPlatformUtils::initialize();
-
- // Get the XQilla DOMImplementation object with support for XPath.
- //
- DOMImplementation* impl (
- DOMImplementationRegistry::getDOMImplementation(
- xml::string ("XPath2 3.0").c_str ()));
-
- try
- {
- using namespace people;
-
- ifstream ifs;
- ifs.exceptions (ifstream::badbit | ifstream::failbit);
- ifs.open (argv[1]);
-
- // Parse the XML file to DOM using the XQilla DOMImplementation.
- //
- xml_schema::dom::auto_ptr<xercesc::DOMDocument> dom (
- parse (ifs, argv[1], true, impl));
-
- // Parse the DOM document to the object model. We also request that
- // the DOM document to be associated with the object model.
- //
- std::auto_ptr<directory> d (
- directory_ (dom,
- xml_schema::flags::keep_dom | xml_schema::flags::own_dom));
-
- // Obtain the root element and document corresponding to the
- // directory object.
- //
- DOMElement* root (static_cast<DOMElement*> (d->_node ()));
- DOMDocument* doc (root->getOwnerDocument ());
-
- // Obtain namespace resolver.
- //
- xml_schema::dom::auto_ptr<XQillaNSResolver> resolver (
- (XQillaNSResolver*)doc->createNSResolver (root));
-
- // Set the namespace prefix for the people namespace that we can
- // use reliably in XPath expressions regardless of what is used
- // in XML documents.
- //
- resolver->addNamespaceBinding (
- xml::string ("p").c_str (),
- xml::string ("http://www.codesynthesis.com/people").c_str ());
-
- // Create XPath expression.
- //
- xml_schema::dom::auto_ptr<const XQillaExpression> expr (
- static_cast<const XQillaExpression*> (
- doc->createExpression (
- xml::string ("p:directory/person[age > 30]").c_str (),
- resolver.get ())));
-
- // Execute the query.
- //
- xml_schema::dom::auto_ptr<XPath2Result> r (
- static_cast<XPath2Result*> (
- expr->evaluate (doc, XPath2Result::ITERATOR_RESULT, 0)));
-
- // Iterate over the result.
- //
- cout << "Records matching the query:" << endl;
-
- while (r->iterateNext ())
- {
- const DOMNode* n (r->asNode ());
-
- // Obtain the object model node corresponding to this DOM node.
- //
- person* p (
- static_cast<person*> (
- n->getUserData (xml_schema::dom::tree_node_key)));
-
- // Print the data using the object model.
- //
- cout << endl
- << "First : " << p->first_name () << endl
- << "Last : " << p->last_name () << endl
- << "Gender : " << p->gender () << endl
- << "Age : " << p->age () << endl;
- }
- }
- catch(const DOMException& e)
- {
- cerr << xml::transcode<char> (e.getMessage ()) << std::endl;
- r = 1;
- }
- catch (const xml_schema::exception& e)
- {
- cerr << e << endl;
- r = 1;
- }
- catch (const std::ios_base::failure&)
- {
- cerr << argv[1] << ": unable to open or read failure" << endl;
- r = 1;
- }
-
- XQillaPlatformUtils::terminate();
- return r;
-}
diff --git a/examples/cxx/tree/xpath/makefile b/examples/cxx/tree/xpath/makefile
index aaa8e3b..5290f0e 100644
--- a/examples/cxx/tree/xpath/makefile
+++ b/examples/cxx/tree/xpath/makefile
@@ -59,7 +59,6 @@ $(install) $(dist) $(dist-win) $(dist-common): path := $(subst $(src_root)/,,$(s
$(install):
$(call install-data,$(src_base)/README,$(install_doc_dir)/xsd/$(path)/README)
$(call install-data,$(src_base)/driver.cxx,$(install_doc_dir)/xsd/$(path)/driver.cxx)
- $(call install-data,$(src_base)/driver-2.cxx,$(install_doc_dir)/xsd/$(path)/driver-2.cxx)
$(call install-data,$(src_base)/people.xsd,$(install_doc_dir)/xsd/$(path)/people.xsd)
$(call install-data,$(src_base)/people.xml,$(install_doc_dir)/xsd/$(path)/people.xml)
$(call install-data,$(src_base)/dom-parse.hxx,$(install_doc_dir)/xsd/$(path)/dom-parse.hxx)
@@ -67,7 +66,6 @@ $(install):
$(dist-common):
$(call install-data,$(src_base)/driver.cxx,$(dist_prefix)/$(path)/driver.cxx)
- $(call install-data,$(src_base)/driver-2.cxx,$(dist_prefix)/$(path)/driver-2.cxx)
$(call install-data,$(src_base)/people.xsd,$(dist_prefix)/$(path)/people.xsd)
$(call install-data,$(src_base)/people.xml,$(dist_prefix)/$(path)/people.xml)
$(call install-data,$(src_base)/dom-parse.hxx,$(dist_prefix)/$(path)/dom-parse.hxx)