diff options
Diffstat (limited to 'xsd-tests/cxx/tree/dom-association')
-rw-r--r-- | xsd-tests/cxx/tree/dom-association/buildfile | 23 | ||||
-rw-r--r-- | xsd-tests/cxx/tree/dom-association/dom-parse.cxx | 95 | ||||
-rw-r--r-- | xsd-tests/cxx/tree/dom-association/dom-parse.hxx | 35 | ||||
-rw-r--r-- | xsd-tests/cxx/tree/dom-association/driver.cxx | 71 | ||||
-rw-r--r-- | xsd-tests/cxx/tree/dom-association/output | 0 | ||||
-rw-r--r-- | xsd-tests/cxx/tree/dom-association/test.xml | 7 | ||||
-rw-r--r-- | xsd-tests/cxx/tree/dom-association/test.xsd | 12 |
7 files changed, 243 insertions, 0 deletions
diff --git a/xsd-tests/cxx/tree/dom-association/buildfile b/xsd-tests/cxx/tree/dom-association/buildfile new file mode 100644 index 0000000..4777e1e --- /dev/null +++ b/xsd-tests/cxx/tree/dom-association/buildfile @@ -0,0 +1,23 @@ +# file : cxx/tree/dom-association/buildfile +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +import libs = libxsd%lib{xsd} +import libs += libxerces-c%lib{xerces-c} + +exe{driver}: {hxx cxx}{* -test} {hxx ixx cxx}{test} $libs + +exe{driver}: xml{test}: test.input = true +exe{driver}: file{output}: test.stdout = true + +cxx.poptions =+ "-I$out_base" + +<{hxx ixx cxx}{test}>: xsd{test} $xsd +{{ + diag xsd ($<[0]) # @@ TMP + + $xsd cxx-tree $xsd_cxx_std \ + --generate-inline \ + --generate-ostream \ + --output-dir $out_base \ + $path($<[0]) +}} diff --git a/xsd-tests/cxx/tree/dom-association/dom-parse.cxx b/xsd-tests/cxx/tree/dom-association/dom-parse.cxx new file mode 100644 index 0000000..e54f6c5 --- /dev/null +++ b/xsd-tests/cxx/tree/dom-association/dom-parse.cxx @@ -0,0 +1,95 @@ +// file : cxx/tree/dom-association/dom-parse.cxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include "dom-parse.hxx" + +#include <istream> + +#include <xercesc/dom/DOM.hpp> +#include <xercesc/util/XMLUniDefs.hpp> // chLatin_* +#include <xercesc/framework/Wrapper4InputSource.hpp> + +#include <libxsd/cxx/xml/sax/std-input-source.hxx> +#include <libxsd/cxx/xml/dom/bits/error-handler-proxy.hxx> + +#include <libxsd/cxx/tree/exceptions.hxx> +#include <libxsd/cxx/tree/error-handler.hxx> + +using namespace xercesc; +namespace xml = xsd::cxx::xml; +namespace tree = xsd::cxx::tree; + +XSD_DOM_AUTO_PTR<DOMDocument> +parse (std::istream& is, + const std::string& id, + bool validate) +{ + const XMLCh ls_id [] = {chLatin_L, chLatin_S, chNull}; + + // Get an implementation of the Load-Store (LS) interface. + // + DOMImplementation* impl ( + DOMImplementationRegistry::getDOMImplementation (ls_id)); + + XSD_DOM_AUTO_PTR<DOMLSParser> parser ( + impl->createLSParser (DOMImplementationLS::MODE_SYNCHRONOUS, 0)); + + DOMConfiguration* conf (parser->getDomConfig ()); + + // Discard comment nodes in the document. + // + conf->setParameter (XMLUni::fgDOMComments, false); + + // Enable datatype normalization. + // + conf->setParameter (XMLUni::fgDOMDatatypeNormalization, true); + + // Do not create EntityReference nodes in the DOM tree. No + // EntityReference nodes will be created, only the nodes + // corresponding to their fully expanded substitution text + // will be created. + // + conf->setParameter (XMLUni::fgDOMEntities, false); + + // Perform namespace processing. + // + conf->setParameter (XMLUni::fgDOMNamespaces, true); + + // Do not include ignorable whitespace in the DOM tree. + // + conf->setParameter (XMLUni::fgDOMElementContentWhitespace, false); + + // Enable/Disable validation. + // + conf->setParameter (XMLUni::fgDOMValidate, validate); + conf->setParameter (XMLUni::fgXercesSchema, validate); + conf->setParameter (XMLUni::fgXercesSchemaFullChecking, false); + + // Xerces-C++ 3.1.0 is the first version with working multi import + // support. + // +#if _XERCES_VERSION >= 30100 + conf->setParameter (XMLUni::fgXercesHandleMultipleImports, true); +#endif + + // We will release the DOM document ourselves. + // + conf->setParameter (XMLUni::fgXercesUserAdoptsDOMDocument, true); + + // Set error handler. + // + tree::error_handler<char> eh; + xml::dom::bits::error_handler_proxy<char> ehp (eh); + conf->setParameter (XMLUni::fgDOMErrorHandler, &ehp); + + // Prepare input stream. + // + xml::sax::std_input_source isrc (is, id); + Wrapper4InputSource wrap (&isrc, false); + + XSD_DOM_AUTO_PTR<DOMDocument> doc (parser->parse (&wrap)); + + eh.throw_if_failed<tree::parsing<char> > (); + + return doc; +} diff --git a/xsd-tests/cxx/tree/dom-association/dom-parse.hxx b/xsd-tests/cxx/tree/dom-association/dom-parse.hxx new file mode 100644 index 0000000..74ef2ad --- /dev/null +++ b/xsd-tests/cxx/tree/dom-association/dom-parse.hxx @@ -0,0 +1,35 @@ +// file : cxx/tree/dom-association/dom-parse.hxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef DOM_PARSE +#define DOM_PARSE + +#include <string> +#include <iosfwd> + +#include <xercesc/dom/DOMDocument.hpp> + +// Define XSD_CXX11 since we include libxsd headers directly. +// +#ifdef _MSC_VER +# if _MSC_VER >= 1600 // VC++10 and later have C++11 always enabled. +# define XSD_CXX11 +# endif +#else +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# define XSD_CXX11 +# endif +#endif + +#include <libxsd/cxx/xml/dom/auto-ptr.hxx> + +// Parse an XML document from the standard input stream with an +// optional resource id. Resource id is used in diagnostics as +// well as to locate schemas referenced from inside the document. +// +XSD_DOM_AUTO_PTR<xercesc::DOMDocument> +parse (std::istream& is, + const std::string& id, + bool validate); + +#endif // DOM_PARSE diff --git a/xsd-tests/cxx/tree/dom-association/driver.cxx b/xsd-tests/cxx/tree/dom-association/driver.cxx new file mode 100644 index 0000000..d85e105 --- /dev/null +++ b/xsd-tests/cxx/tree/dom-association/driver.cxx @@ -0,0 +1,71 @@ +// file : cxx/tree/dom-association/driver.cxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test DOM association/ownership. +// + +#include <memory> // std::auto_ptr/unique_ptr +#include <fstream> +#include <iostream> + +#include <xercesc/dom/DOM.hpp> + +#include "dom-parse.hxx" +#include "test.hxx" + +using namespace std; +using namespace test; +using namespace xercesc; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + int r (0); + + XMLPlatformUtils::Initialize (); + + try + { + ifstream ifs; + ifs.exceptions (ifstream::badbit | ifstream::failbit); + ifs.open (argv[1]); + + DOMDocument* ptr; + +#ifdef XSD_CXX11 + xml_schema::dom::unique_ptr<DOMDocument> doc (parse (ifs, argv[1], true)); + ptr = doc.get (); + unique_ptr<type> r ( + root (std::move (doc), + xml_schema::flags::keep_dom | xml_schema::flags::own_dom)); +#else + xml_schema::dom::auto_ptr<DOMDocument> doc (parse (ifs, argv[1], true)); + ptr = doc.get (); + auto_ptr<type> r ( + root (doc, + xml_schema::flags::keep_dom | xml_schema::flags::own_dom)); +#endif + + assert (doc.get () == 0); + assert (r->_node ()->getOwnerDocument () == ptr); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + r = 1; + } + catch (const std::ios_base::failure&) + { + cerr << argv[1] << ": unable to open or read failure" << endl; + r = 1; + } + + XMLPlatformUtils::Terminate (); + return r; +} diff --git a/xsd-tests/cxx/tree/dom-association/output b/xsd-tests/cxx/tree/dom-association/output new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/xsd-tests/cxx/tree/dom-association/output diff --git a/xsd-tests/cxx/tree/dom-association/test.xml b/xsd-tests/cxx/tree/dom-association/test.xml new file mode 100644 index 0000000..624a80c --- /dev/null +++ b/xsd-tests/cxx/tree/dom-association/test.xml @@ -0,0 +1,7 @@ +<t:root xmlns:t="test" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="test test.xsd"> + + <a>a</a> + +</t:root> diff --git a/xsd-tests/cxx/tree/dom-association/test.xsd b/xsd-tests/cxx/tree/dom-association/test.xsd new file mode 100644 index 0000000..07bebc7 --- /dev/null +++ b/xsd-tests/cxx/tree/dom-association/test.xsd @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="type"> + <sequence> + <element name="a" type="string"/> + </sequence> + </complexType> + + <element name="root" type="t:type"/> + +</schema> |