From db7f618d0a94315ae9ed51a9b1d4ef9ba832827e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 3 Dec 2009 17:03:53 +0200 Subject: Implement automatic mapping for urn-style XML namespaces --- NEWS | 3 +++ xsde/cxx/elements.cxx | 27 ++++++++++++++++++++++----- xsde/cxx/elements.hxx | 4 ++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 9dfb006..323ea50 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,9 @@ Version 3.2.0 for the same namespace. Before, all subsequent imports for a namespace were ignored which caused error in some schemas. + * Automatic mapping for the urn-style XML namespaces. The last component + in the urn name is used to derive the C++ namespace name. + C++/Hybrid * String-based types that use XML Schema restriction by enumeration are diff --git a/xsde/cxx/elements.cxx b/xsde/cxx/elements.cxx index a94e772..30b51d5 100644 --- a/xsde/cxx/elements.cxx +++ b/xsde/cxx/elements.cxx @@ -148,6 +148,8 @@ namespace CXX cxx_id_expr_ (L"^(::)?([a-zA-Z_]\\w*)(::[a-zA-Z_]\\w*)*$"), cxx_id_expr (cxx_id_expr_), trace_namespace_regex (trace_namespace_regex_), + urn_mapping_ (L"#^urn.*:([a-zA-Z_].*)$#$1#"), + urn_mapping (urn_mapping_), nsr_mapping (nsr_mapping_), nsm_mapping (nsm_mapping_), include_mapping (include_mapping_), @@ -356,22 +358,37 @@ namespace CXX if (!found) { + String const& n (ns.name ()); + // Check if the name is valid by itself. // - if (ns.name ().empty ()) + if (n.empty ()) { // Empty name denotes a no-namespace case. // - tmp = ns.name (); + tmp = n; } else { - tmp = colon.merge (ns.name ()); // replace `/' with `::' + tmp = colon.merge (n); // replace `/' with `::' if (!cxx_id_expr.match (tmp)) { - throw NoNamespaceMapping ( - ns.file (), ns.line (), ns.column (), ns.name ()); + // See if this is a urn-style namespace. + // + if (urn_mapping.match (n)) + { + Regex filter (L"#[.:-]#_#"); + tmp = urn_mapping.merge (n); + tmp = filter.merge (tmp); + + if (!cxx_id_expr.match (tmp)) + throw NoNamespaceMapping ( + ns.file (), ns.line (), ns.column (), ns.name ()); + } + else + throw NoNamespaceMapping ( + ns.file (), ns.line (), ns.column (), ns.name ()); } } } diff --git a/xsde/cxx/elements.hxx b/xsde/cxx/elements.hxx index 6504ac2..10d7470 100644 --- a/xsde/cxx/elements.hxx +++ b/xsde/cxx/elements.hxx @@ -152,6 +152,7 @@ namespace CXX xs_ns_ (c.xs_ns_), cxx_id_expr (c.cxx_id_expr), trace_namespace_regex (c.trace_namespace_regex), + urn_mapping (c.urn_mapping), nsr_mapping (c.nsr_mapping), nsm_mapping (c.nsm_mapping), include_mapping (c.include_mapping), @@ -177,6 +178,7 @@ namespace CXX xs_ns_ (c.xs_ns_), cxx_id_expr (c.cxx_id_expr), trace_namespace_regex (c.trace_namespace_regex), + urn_mapping (c.urn_mapping), nsr_mapping (c.nsr_mapping), nsm_mapping (c.nsm_mapping), include_mapping (c.include_mapping), @@ -327,8 +329,10 @@ namespace CXX RegexPat const cxx_id_expr_; RegexPat const& cxx_id_expr; Boolean trace_namespace_regex; + Regex urn_mapping_; RegexMapping nsr_mapping_; MapMapping nsm_mapping_; + Regex const& urn_mapping; RegexMapping const& nsr_mapping; MapMapping const& nsm_mapping; MappingCache ns_mapping_cache_; -- cgit v1.1