// file : xsd/cxx/parser/xerces/elements.hxx // author : Boris Kolpackov // copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_PARSER_XERCES_ELEMENTS_HXX #define XSD_CXX_PARSER_XERCES_ELEMENTS_HXX #include // std::auto_ptr #include #include #include #include #include #include #include #include #include #include #include #include namespace xsd { namespace cxx { namespace parser { namespace xerces { // // struct flags { // Use the following flags to modify the default behavior // of the parsing functions. // // Do not try to validate instance documents. // static const unsigned long dont_validate = 0x00000001; // Do not initialize the Xerces-C++ runtime. // static const unsigned long dont_initialize = 0x00000002; // Disable handling of subsequent imports for the same namespace // in Xerces-C++ 3.1.0 and later. // static const unsigned long no_multiple_imports = 0x00000004; public: flags (unsigned long x = 0) : x_ (x) { } operator unsigned long () const { return x_; } private: unsigned long x_; }; // Parsing properties. Refer to xsd/cxx/xml/elements.hxx for // XML-related properties. // template class properties: public xml::properties { }; // // template struct document: cxx::parser::document // VC 7.1 likes it qualified { public: document (parser_base& root, const C* root_element_name, bool polymorphic = false); document (parser_base& root, const std::basic_string& root_element_name, bool polymorphic = false); document (parser_base& root, const C* root_element_namespace, const C* root_element_name, bool polymorphic = false); document (parser_base& root, const std::basic_string& root_element_namespace, const std::basic_string& root_element_name, bool polymorphic = false); protected: explicit document (bool polymorphic = false); public: // Parse URI or a local file. We have to overload it for const C* // bacause xercesc::InputSource has an implicit constructor that // takes const char*. // void parse (const std::basic_string& uri, flags = 0, const properties& = properties ()); void parse (const C* uri, flags = 0, const properties& = properties ()); // Parse URI or a local file with a user-provided error_handler // object. // void parse (const std::basic_string& uri, xml::error_handler&, flags = 0, const properties& = properties ()); void parse (const C* uri, xml::error_handler&, flags = 0, const properties& = properties ()); // Parse URI or a local file with a user-provided ErrorHandler // object. Note that you must initialize the Xerces-C++ runtime // before calling these functions. // void parse (const std::basic_string& uri, xercesc::ErrorHandler&, flags = 0, const properties& = properties ()); void parse (const C* uri, xercesc::ErrorHandler&, flags = 0, const properties& = properties ()); // Parse URI or a local file using a user-provided SAX2XMLReader // object. Note that you must initialize the Xerces-C++ runtime // before calling these functions. // void parse (const std::basic_string& uri, xercesc::SAX2XMLReader&, flags = 0, const properties& = properties ()); void parse (const C* uri, xercesc::SAX2XMLReader&, flags = 0, const properties& = properties ()); public: // System id is a "system" identifier of the resources (e.g., // URI or a full file path). Public id is a "public" identifier // of the resource (e.g., an application-specific name or a // relative file path). System id is used to resolve relative // paths. In diagnostics messages system id is used if public // id is not available. Otherwise public id is used. // // Parse std::istream. // void parse (std::istream&, flags = 0, const properties& = properties ()); // Parse std::istream with a user-provided error_handler object. // void parse (std::istream&, xml::error_handler&, flags = 0, const properties& = properties ()); // Parse std::istream with a user-provided ErrorHandler object. // Note that you must initialize the Xerces-C++ runtime before // calling this function. // void parse (std::istream&, xercesc::ErrorHandler&, flags = 0, const properties& = properties ()); // Parse std::istream using a user-provided SAX2XMLReader object. // Note that you must initialize the Xerces-C++ runtime before // calling this function. // void parse (std::istream&, xercesc::SAX2XMLReader&, flags = 0, const properties& = properties ()); public: // Parse std::istream with a system id. // void parse (std::istream&, const std::basic_string& system_id, flags = 0, const properties& = properties ()); // Parse std::istream with a system id and a user-provided // error_handler object. // void parse (std::istream&, const std::basic_string& system_id, xml::error_handler&, flags = 0, const properties& = properties ()); // Parse std::istream with a system id and a user-provided // ErrorHandler object. Note that you must initialize the // Xerces-C++ runtime before calling this function. // void parse (std::istream&, const std::basic_string& system_id, xercesc::ErrorHandler&, flags = 0, const properties& = properties ()); // Parse std::istream with a system id using a user-provided // SAX2XMLReader object. Note that you must initialize the // Xerces-C++ runtime before calling this function. // void parse (std::istream&, const std::basic_string& system_id, xercesc::SAX2XMLReader&, flags = 0, const properties& = properties ()); public: // Parse std::istream with system and public ids. // void parse (std::istream&, const std::basic_string& system_id, const std::basic_string& public_id, flags = 0, const properties& = properties ()); // Parse std::istream with system and public ids and a user-provided // error_handler object. // void parse (std::istream&, const std::basic_string& system_id, const std::basic_string& public_id, xml::error_handler&, flags = 0, const properties& = properties ()); // Parse std::istream with system and public ids and a user-provided // ErrorHandler object. Note that you must initialize the Xerces-C++ // runtime before calling this function. // void parse (std::istream&, const std::basic_string& system_id, const std::basic_string& public_id, xercesc::ErrorHandler&, flags = 0, const properties& = properties ()); // Parse std::istream with system and public ids using a user- // provided SAX2XMLReader object. Note that you must initialize // the Xerces-C++ runtime before calling this function. // void parse (std::istream&, const std::basic_string& system_id, const std::basic_string& public_id, xercesc::SAX2XMLReader&, flags = 0, const properties& = properties ()); public: // Parse InputSource. Note that you must initialize the Xerces-C++ // runtime before calling this function. // void parse (const xercesc::InputSource&, flags = 0, const properties& = properties ()); // Parse InputSource with a user-provided error_handler object. // Note that you must initialize the Xerces-C++ runtime before // calling this function. // void parse (const xercesc::InputSource&, xml::error_handler&, flags = 0, const properties& = properties ()); // Parse InputSource with a user-provided ErrorHandler object. // Note that you must initialize the Xerces-C++ runtime before // calling this function. // void parse (const xercesc::InputSource&, xercesc::ErrorHandler&, flags = 0, const properties& = properties ()); // Parse InputSource using a user-provided SAX2XMLReader object. // Note that you must initialize the Xerces-C++ runtime before // calling this function. // void parse (const xercesc::InputSource&, xercesc::SAX2XMLReader&, flags = 0, const properties& = properties ()); private: void parse (const std::basic_string& uri, xercesc::ErrorHandler&, xercesc::SAX2XMLReader&, flags, const properties&); void parse (const xercesc::InputSource&, xercesc::ErrorHandler&, xercesc::SAX2XMLReader&, flags, const properties&); private: std::auto_ptr create_sax_ (flags, const properties&); private: bool polymorphic_; }; // // template struct event_router: xercesc::DefaultHandler { event_router (cxx::parser::document&, bool polymorphic); // I know, some of those consts are stupid. But that's what // Xerces folks put into their interfaces and VC 7.1 thinks // there are different signatures if one strips this fluff off. // virtual void setDocumentLocator (const xercesc::Locator* const); virtual void startElement (const XMLCh* const uri, const XMLCh* const lname, const XMLCh* const qname, const xercesc::Attributes& attributes); virtual void endElement (const XMLCh* const uri, const XMLCh* const lname, const XMLCh* const qname); #if _XERCES_VERSION >= 30000 virtual void characters (const XMLCh* const s, const XMLSize_t length); #else virtual void characters (const XMLCh* const s, const unsigned int length); #endif virtual void startPrefixMapping (const XMLCh* const prefix, const XMLCh* const uri); virtual void endPrefixMapping (const XMLCh* const prefix); private: void set_location (schema_exception&); private: const xercesc::Locator* loc_; cxx::parser::document& consumer_; bool polymorphic_; // Last element name cache. // bool last_valid_; std::basic_string last_ns_; std::basic_string last_name_; // Namespace-prefix mapping. Only maintained in the polymorphic // case. // struct ns_decl { ns_decl (const std::basic_string& p, const std::basic_string& n) : prefix (p), ns (n) { } std::basic_string prefix; std::basic_string ns; }; typedef std::vector ns_decls; ns_decls ns_decls_; }; } } } } #include #endif // XSD_CXX_PARSER_XERCES_ELEMENTS_HXX