From d71611d5fb575078bdf573c35257bb86bb7054e0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 3 Dec 2009 17:02:56 +0200 Subject: Implement automatic mapping for urn-style XML namespaces --- xsd/cxx/elements.cxx | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'xsd/cxx/elements.cxx') diff --git a/xsd/cxx/elements.cxx b/xsd/cxx/elements.cxx index 3cd5e9e..fd23fc0 100644 --- a/xsd/cxx/elements.cxx +++ b/xsd/cxx/elements.cxx @@ -144,6 +144,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_), @@ -352,22 +354,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 ()); } } } -- cgit v1.1