diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2024-03-06 10:24:11 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2024-03-06 10:24:11 +0100 |
commit | 4538829ab86b5a1cd4e845e7eab165029c9d6d46 (patch) | |
tree | bbadf39aed0610c8f8f7b41fefff47773b8ac205 /xsd/examples/cxx/tree/wildcard | |
parent | 23d41842168ac1a1580111b9c5c73500ceee3d57 (diff) | |
parent | aad5ad9bf0c02aa4e79bc6b7d6c934612fff4026 (diff) |
Update upstream source from tag 'upstream/4.2.0'
Update to upstream version '4.2.0'
with Debian dir 1b38df7bbcf313223de3c50107ac0255090fe647
Diffstat (limited to 'xsd/examples/cxx/tree/wildcard')
-rw-r--r-- | xsd/examples/cxx/tree/wildcard/README | 34 | ||||
-rw-r--r-- | xsd/examples/cxx/tree/wildcard/driver.cxx | 159 | ||||
-rw-r--r-- | xsd/examples/cxx/tree/wildcard/email.xml | 31 | ||||
-rw-r--r-- | xsd/examples/cxx/tree/wildcard/email.xsd | 50 | ||||
-rw-r--r-- | xsd/examples/cxx/tree/wildcard/makefile | 102 |
5 files changed, 0 insertions, 376 deletions
diff --git a/xsd/examples/cxx/tree/wildcard/README b/xsd/examples/cxx/tree/wildcard/README deleted file mode 100644 index d451509..0000000 --- a/xsd/examples/cxx/tree/wildcard/README +++ /dev/null @@ -1,34 +0,0 @@ -This example shows how to use the optional wildcard mapping provided -by C++/Tree to parse, access, modify, and serialize the XML data -matched by XML Schema wildcards (any and anyAttribute). For an -alternative approach that employes type customization see the -custom/wildcard example. - -The example consists of the following files: - -email.xsd - XML Schema which describes a simple email format with the - extensible envelope type. - -email.xml - Sample email message. - -email.hxx -email.ixx -email.cxx - C++ types that represent the given vocabulary, a set of parsing - functions that convert XML instance documents to a tree-like in-memory - object model, and a set of serialization functions that convert the - object model back to XML. These are generated by XSD from email.xsd. - Note that the --generate-wildcard option is used to request the - wildcard mapping. - -driver.cxx - Driver for the example. It first calls one of the parsing functions - that constructs the object model from the input file. It then prints - the content of the object model to STDERR. Next the driver creates a - reply email which is then serialized to XML. - -To run the example on the sample XML instance document simply execute: - -$ ./driver email.xml diff --git a/xsd/examples/cxx/tree/wildcard/driver.cxx b/xsd/examples/cxx/tree/wildcard/driver.cxx deleted file mode 100644 index 64acfce..0000000 --- a/xsd/examples/cxx/tree/wildcard/driver.cxx +++ /dev/null @@ -1,159 +0,0 @@ -// file : examples/cxx/tree/wildcard/driver.cxx -// copyright : not copyrighted - public domain - -#include <string> -#include <memory> // std::auto_ptr -#include <cstring> // std::memcpy -#include <iostream> - -#include <xercesc/dom/DOM.hpp> -#include <xercesc/util/PlatformUtils.hpp> - -#include "email.hxx" - -// The following string class keeps us sane when working with Xerces. -// Include it after the generated header in order to get only char or -// wchar_t version depending on how you compiled your schemas. -// -#include <xsd/cxx/xml/string.hxx> - -using std::cerr; -using std::endl; -using std::string; - -int -main (int argc, char* argv[]) -{ - if (argc != 2) - { - cerr << "usage: " << argv[0] << " email.xml" << endl; - return 1; - } - - using namespace xercesc; - - int r (0); - - // The Xerces-C++ DOM objects that will be used to store the - // content matched by wildcards "out-live" the call to the - // parsing function. Therefore we need to initialize the - // Xerces-C++ runtime ourselves. - // - XMLPlatformUtils::Initialize (); - - try - { - using namespace email; - namespace xml = xsd::cxx::xml; - - // Read in the message. - // - std::auto_ptr<envelope> msg ( - message (argv[1], xml_schema::flags::dont_initialize)); - - // Print what we've got. - // - cerr << "To: " << msg->to () << endl - << "From: " << msg->from () << endl - << "Subject: " << msg->subject () << endl; - - envelope::any_sequence& body (msg->any ()); - - for (envelope::any_iterator i (body.begin ()); i != body.end (); ++i) - { - DOMElement& e (*i); - string name (xml::transcode<char> (e.getLocalName ())); - - if (name == "text") - { - // Create object representation for the text element. - // - xml_schema::string text (e); - - cerr << text << endl - << endl; - } - else if (name == "binary") - { - // Create object representation for the binary element. - // - binary bin (e); - - cerr << "binary: " << bin.name () << " type: " << bin.mime () << endl - << endl; - } - else - { - cerr << "unknown body type: " << name << endl; - } - } - - // Create a reply message. - // - envelope reply (msg->from (), msg->to (), "Re: " + msg->subject ()); - - // Copy the thread-id attribute from the original message if any. - // - envelope::any_attribute_set& as (msg->any_attribute ()); - envelope::any_attribute_iterator ti ( - as.find ("http://www.codesynthesis.com/email", "thread-id")); - - if (ti != as.end ()) - reply.any_attribute ().insert (*ti); - - // Add a text body. - // - DOMDocument& doc (reply.dom_document ()); - envelope::any_sequence& rbody (reply.any ()); - - xml_schema::string text ("Hi!\n\n" - "Indeed nice pictures. Check out mine.\n\n" - "Jane"); - - DOMElement* e ( - doc.createElementNS ( - xml::string ("http://www.codesynthesis.com/email").c_str (), - xml::string ("eml:text").c_str ())); - - *e << text; - rbody.push_back (e); - - // Add a (fake) image. - // - binary pic ("pic.jpg", "image/jpeg"); - pic.size (3); - std::memcpy (pic.data (), "123", 3); - - e = doc.createElementNS ( - xml::string ("http://www.codesynthesis.com/email").c_str (), - xml::string ("eml:binary").c_str ()); - - *e << pic; - rbody.push_back (e); - - - // Prepare namespace mapping and schema location information for - // serialization. - // - xml_schema::namespace_infomap map; - - map["eml"].name = "http://www.codesynthesis.com/email"; - map["eml"].schema = "email.xsd"; - - // Write it out. - // - message (std::cout, - reply, - map, - "UTF-8", - xml_schema::flags::dont_initialize); - } - catch (const xml_schema::exception& e) - { - cerr << e << endl; - r = 1; - } - - XMLPlatformUtils::Terminate (); - return r; -} diff --git a/xsd/examples/cxx/tree/wildcard/email.xml b/xsd/examples/cxx/tree/wildcard/email.xml deleted file mode 100644 index 9272d5c..0000000 --- a/xsd/examples/cxx/tree/wildcard/email.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0"?> - -<!-- - -file : examples/cxx/tree/wildcard/email.xml -copyright : not copyrighted - public domain - ---> - -<eml:message xmlns:eml="http://www.codesynthesis.com/email" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.codesynthesis.com/email email.xsd" - eml:thread-id="123456789"> - - <to>Jane Doe <jane@doe.com></to> - <from>John Doe <john@doe.com></from> - <subject>Surfing pictures</subject> - - <eml:text> -Hi Jane, - -Here are cool pictures of me surfing. - -Cheers, -John - </eml:text> - - <eml:binary name="pic1.jpg" mime="image/jpeg">YmFzZTY0IGJpbmFyeQ==</eml:binary> - <eml:binary name="pic2.jpg" mime="image/jpeg">YmFzZTY0IGJpbmFyeQ==</eml:binary> - -</eml:message> diff --git a/xsd/examples/cxx/tree/wildcard/email.xsd b/xsd/examples/cxx/tree/wildcard/email.xsd deleted file mode 100644 index 239cb9d..0000000 --- a/xsd/examples/cxx/tree/wildcard/email.xsd +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0"?> - -<!-- - -file : examples/cxx/tree/wildcard/email.xsd -copyright : not copyrighted - public domain - ---> - -<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" - xmlns:eml="http://www.codesynthesis.com/email" - targetNamespace="http://www.codesynthesis.com/email"> - - <!-- Predefined envolop body types. --> - - <xsd:element name="text" type="xsd:string"/> - - <xsd:complexType name="binary"> - <xsd:simpleContent> - <xsd:extension base="xsd:base64Binary"> - <xsd:attribute name="name" type="xsd:string" use="required"/> - <xsd:attribute name="mime" type="xsd:string" use="required"/> - </xsd:extension> - </xsd:simpleContent> - </xsd:complexType> - - <xsd:element name="binary" type="eml:binary"/> - - <!-- Predefined envelop attributes. --> - - <xsd:attribute name="thread-id" type="xsd:unsignedInt"/> - - - <xsd:complexType name="envelope"> - <xsd:sequence> - <xsd:element name="to" type="xsd:string"/> - <xsd:element name="from" type="xsd:string"/> - <xsd:element name="subject" type="xsd:string"/> - - <!-- Extensible envelope body. --> - - <xsd:any namespace="##targetNamespace" processContents="strict" - maxOccurs="unbounded" /> - </xsd:sequence> - <xsd:anyAttribute namespace="##targetNamespace" processContents="strict"/> - </xsd:complexType> - - <xsd:element name="message" type="eml:envelope"/> - -</xsd:schema> diff --git a/xsd/examples/cxx/tree/wildcard/makefile b/xsd/examples/cxx/tree/wildcard/makefile deleted file mode 100644 index 8c6fe52..0000000 --- a/xsd/examples/cxx/tree/wildcard/makefile +++ /dev/null @@ -1,102 +0,0 @@ -# file : examples/cxx/tree/wildcard/makefile -# copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC -# license : GNU GPL v2 + exceptions; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make - -xsd := email.xsd -cxx := driver.cxx - -obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=.o)) -dep := $(obj:.o=.o.d) - -driver := $(out_base)/driver -install := $(out_base)/.install -dist := $(out_base)/.dist -dist-win := $(out_base)/.dist-win -clean := $(out_base)/.clean - - -# Import. -# -$(call import,\ - $(scf_root)/import/libxerces-c/stub.make,\ - l: xerces_c.l,cpp-options: xerces_c.l.cpp-options) - - -# Build. -# -$(driver): $(obj) $(xerces_c.l) - -$(obj) $(dep): cpp_options := -I$(out_base) -I$(src_base) -I$(src_root)/libxsd -$(obj) $(dep): $(xerces_c.l.cpp-options) - -genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.ixx) $(xsd:.xsd=.cxx) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): xsd := $(out_root)/xsd/xsd -$(gen): xsd_options += --generate-inline --generate-wildcard \ ---generate-serialization --root-element message -$(gen): $(out_root)/xsd/xsd - -$(call include-dep,$(dep),$(obj),$(gen)) - -# Convenience alias for default target. -# -$(out_base)/: $(driver) - - -# Install & Dist. -# -dist-common := $(out_base)/.dist-common - -$(install) $(dist) $(dist-win) $(dist-common): path := $(subst $(src_root)/,,$(src_base)) - -$(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)/email.xsd,$(install_doc_dir)/xsd/$(path)/email.xsd) - $(call install-data,$(src_base)/email.xml,$(install_doc_dir)/xsd/$(path)/email.xml) - -$(dist-common): - $(call install-data,$(src_base)/driver.cxx,$(dist_prefix)/$(path)/driver.cxx) - $(call install-data,$(src_base)/email.xsd,$(dist_prefix)/$(path)/email.xsd) - $(call install-data,$(src_base)/email.xml,$(dist_prefix)/$(path)/email.xml) - -$(dist): $(dist-common) - $(call install-data,$(src_base)/README,$(dist_prefix)/$(path)/README) - -$(dist-win): $(dist-common) - $(call install-data,$(src_base)/README,$(dist_prefix)/$(path)/README.txt) - $(call message,,todos $(dist_prefix)/$(path)/README.txt) - -# Clean. -# -$(clean): $(driver).o.clean \ - $(addsuffix .cxx.clean,$(obj)) \ - $(addsuffix .cxx.clean,$(dep)) \ - $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(gen): | $(out_base)/.gitignore -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/cxx/o-e.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/install.make) -$(call include,$(scf_root)/xsd/tree/xsd-cxx.make) - -# Dependencies. -# -$(call import,$(src_root)/xsd/makefile) |