[111] | 1 | // file : xsd/cxx/tree/parsing.txx |
---|
| 2 | // author : Boris Kolpackov <boris@codesynthesis.com> |
---|
| 3 | // copyright : Copyright (c) 2005-2008 Code Synthesis Tools CC |
---|
| 4 | // license : GNU GPL v2 + exceptions; see accompanying LICENSE file |
---|
| 5 | |
---|
| 6 | #include <string> |
---|
| 7 | |
---|
| 8 | #include <xsd/cxx/ro-string.hxx> // trim |
---|
| 9 | |
---|
| 10 | #include <xsd/cxx/xml/string.hxx> // xml::{string, transcode} |
---|
| 11 | #include <xsd/cxx/xml/elements.hxx> // xml::{prefix, uq_name} |
---|
| 12 | #include <xsd/cxx/xml/bits/literals.hxx> // xml::bits::{xml_prefix, |
---|
| 13 | // xml_namespace} |
---|
| 14 | |
---|
| 15 | #include <xsd/cxx/tree/exceptions.hxx> // no_prefix_mapping |
---|
| 16 | #include <xsd/cxx/tree/elements.hxx> |
---|
| 17 | #include <xsd/cxx/tree/types.hxx> |
---|
| 18 | #include <xsd/cxx/tree/list.hxx> |
---|
| 19 | #include <xsd/cxx/tree/text.hxx> // text_content |
---|
| 20 | |
---|
| 21 | namespace xsd |
---|
| 22 | { |
---|
| 23 | namespace cxx |
---|
| 24 | { |
---|
| 25 | namespace tree |
---|
| 26 | { |
---|
| 27 | // Note that most of the types implemented here (except string, |
---|
| 28 | // (normalizedString, and base64Binary) cannot have whitespaces |
---|
| 29 | // in the value. As result we don't need to waste time collapsing |
---|
| 30 | // whitespaces. All we need to do is trim the string representation |
---|
| 31 | // which can be done without copying. |
---|
| 32 | // |
---|
| 33 | |
---|
| 34 | // type |
---|
| 35 | // |
---|
| 36 | inline _type:: |
---|
| 37 | _type (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 38 | : dom_info_ (0), container_ (c) |
---|
| 39 | { |
---|
| 40 | if (f & flags::keep_dom) |
---|
| 41 | { |
---|
| 42 | std::auto_ptr<dom_info> r ( |
---|
| 43 | dom_info_factory::create (e, *this, c == 0)); |
---|
| 44 | dom_info_ = r; |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | inline _type:: |
---|
| 49 | _type (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 50 | : dom_info_ (0), container_ (c) |
---|
| 51 | { |
---|
| 52 | if (f & flags::keep_dom) |
---|
| 53 | { |
---|
| 54 | std::auto_ptr<dom_info> r (dom_info_factory::create (a, *this)); |
---|
| 55 | dom_info_ = r; |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | template <typename C> |
---|
| 60 | inline _type:: |
---|
| 61 | _type (const std::basic_string<C>&, |
---|
| 62 | const xercesc::DOMElement*, |
---|
| 63 | flags, |
---|
| 64 | container* c) |
---|
| 65 | : dom_info_ (0), // List elements don't have associated DOM nodes. |
---|
| 66 | container_ (c) |
---|
| 67 | { |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | // simple_type |
---|
| 71 | // |
---|
| 72 | template <typename B> |
---|
| 73 | inline simple_type<B>:: |
---|
| 74 | simple_type (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 75 | : B (e, f, c) |
---|
| 76 | { |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | template <typename B> |
---|
| 80 | inline simple_type<B>:: |
---|
| 81 | simple_type (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 82 | : B (a, f, c) |
---|
| 83 | { |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | template <typename B> |
---|
| 87 | template <typename C> |
---|
| 88 | inline simple_type<B>:: |
---|
| 89 | simple_type (const std::basic_string<C>& s, |
---|
| 90 | const xercesc::DOMElement* e, |
---|
| 91 | flags f, |
---|
| 92 | container* c) |
---|
| 93 | : B (s, e, f, c) |
---|
| 94 | { |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | // fundamental_base |
---|
| 98 | // |
---|
| 99 | template <typename X, typename C, typename B> |
---|
| 100 | fundamental_base<X, C, B>:: |
---|
| 101 | fundamental_base (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 102 | : B (e, f, c), |
---|
| 103 | x_ (traits<X, C>::create (e, f, c)) |
---|
| 104 | { |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | template <typename X, typename C, typename B> |
---|
| 108 | fundamental_base<X, C, B>:: |
---|
| 109 | fundamental_base (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 110 | : B (a, f, c), |
---|
| 111 | x_ (traits<X, C>::create (a, f, c)) |
---|
| 112 | { |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | template <typename X, typename C, typename B> |
---|
| 116 | fundamental_base<X, C, B>:: |
---|
| 117 | fundamental_base (const std::basic_string<C>& s, |
---|
| 118 | const xercesc::DOMElement* e, |
---|
| 119 | flags f, |
---|
| 120 | container* c) |
---|
| 121 | : B (s, e, f, c), |
---|
| 122 | x_ (traits<X, C>::create (s, e, f, c)) |
---|
| 123 | { |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | // Parsing c-tors for list. |
---|
| 128 | // |
---|
| 129 | |
---|
| 130 | namespace bits |
---|
| 131 | { |
---|
| 132 | // Find first non-space character. |
---|
| 133 | // |
---|
| 134 | template <typename C> |
---|
| 135 | typename std::basic_string<C>::size_type |
---|
| 136 | find_ns (const C* s, |
---|
| 137 | typename std::basic_string<C>::size_type size, |
---|
| 138 | typename std::basic_string<C>::size_type pos) |
---|
| 139 | { |
---|
| 140 | while (pos < size && |
---|
| 141 | (s[pos] == C (0x20) || // space |
---|
| 142 | s[pos] == C (0x0D) || // carriage return |
---|
| 143 | s[pos] == C (0x09) || // tab |
---|
| 144 | s[pos] == C (0x0A))) |
---|
| 145 | ++pos; |
---|
| 146 | |
---|
| 147 | return pos < size ? pos : std::basic_string<C>::npos; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | // Find first space character. |
---|
| 151 | // |
---|
| 152 | template <typename C> |
---|
| 153 | typename std::basic_string<C>::size_type |
---|
| 154 | find_s (const C* s, |
---|
| 155 | typename std::basic_string<C>::size_type size, |
---|
| 156 | typename std::basic_string<C>::size_type pos) |
---|
| 157 | { |
---|
| 158 | while (pos < size && |
---|
| 159 | s[pos] != C (0x20) && // space |
---|
| 160 | s[pos] != C (0x0D) && // carriage return |
---|
| 161 | s[pos] != C (0x09) && // tab |
---|
| 162 | s[pos] != C (0x0A)) |
---|
| 163 | ++pos; |
---|
| 164 | |
---|
| 165 | return pos < size ? pos : std::basic_string<C>::npos; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | // Individual items of the list have no DOM association. Therefore |
---|
| 170 | // I clear keep_dom from flags. |
---|
| 171 | // |
---|
| 172 | |
---|
| 173 | template <typename X, typename C> |
---|
| 174 | list<X, C, false>:: |
---|
| 175 | list (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 176 | : sequence<X> (flags (f & ~flags::keep_dom), c) // ambiguous |
---|
| 177 | { |
---|
| 178 | init (text_content<C> (e), &e); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | template <typename X, typename C> |
---|
| 182 | list<X, C, false>:: |
---|
| 183 | list (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 184 | : sequence<X> (flags (f & ~flags::keep_dom), c) // ambiguous |
---|
| 185 | { |
---|
| 186 | init (xml::transcode<C> (a.getValue ()), a.getOwnerElement ()); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | template <typename X, typename C> |
---|
| 190 | list<X, C, false>:: |
---|
| 191 | list (const std::basic_string<C>& s, |
---|
| 192 | const xercesc::DOMElement* e, |
---|
| 193 | flags f, |
---|
| 194 | container* c) |
---|
| 195 | : sequence<X> (flags (f & ~flags::keep_dom), c) // ambiguous |
---|
| 196 | { |
---|
| 197 | init (s, e); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | template <typename X, typename C> |
---|
| 201 | void list<X, C, false>:: |
---|
| 202 | init (const std::basic_string<C>& s, const xercesc::DOMElement* parent) |
---|
| 203 | { |
---|
| 204 | if (s.size () == 0) |
---|
| 205 | return; |
---|
| 206 | |
---|
| 207 | using std::basic_string; |
---|
| 208 | typedef typename sequence<X>::ptr ptr; |
---|
| 209 | typedef typename basic_string<C>::size_type size_type; |
---|
| 210 | |
---|
| 211 | const C* data (s.c_str ()); |
---|
| 212 | size_type size (s.size ()); |
---|
| 213 | |
---|
| 214 | // Traverse the data while logically collapsing spaces. |
---|
| 215 | // |
---|
| 216 | for (size_type i (bits::find_ns<C> (data, size, 0)); |
---|
| 217 | i != basic_string<C>::npos;) |
---|
| 218 | { |
---|
| 219 | size_type j (bits::find_s (data, size, i)); |
---|
| 220 | |
---|
| 221 | if (j != basic_string<C>::npos) |
---|
| 222 | { |
---|
| 223 | ptr r ( |
---|
| 224 | new X (basic_string<C> (data + i, j - i), |
---|
| 225 | parent, |
---|
| 226 | this->flags_, |
---|
| 227 | this->container_)); |
---|
| 228 | |
---|
| 229 | this->v_.push_back (r); |
---|
| 230 | |
---|
| 231 | i = bits::find_ns (data, size, j); |
---|
| 232 | } |
---|
| 233 | else |
---|
| 234 | { |
---|
| 235 | // Last element. |
---|
| 236 | // |
---|
| 237 | ptr r ( |
---|
| 238 | new X (basic_string<C> (data + i, size - i), |
---|
| 239 | parent, |
---|
| 240 | this->flags_, |
---|
| 241 | this->container_)); |
---|
| 242 | |
---|
| 243 | this->v_.push_back (r); |
---|
| 244 | |
---|
| 245 | break; |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | template <typename X, typename C> |
---|
| 251 | list<X, C, true>:: |
---|
| 252 | list (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 253 | : sequence<X> (flags (f & ~flags::keep_dom), c) // ambiguous |
---|
| 254 | { |
---|
| 255 | init (text_content<C> (e), &e); |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | template <typename X, typename C> |
---|
| 259 | inline list<X, C, true>:: |
---|
| 260 | list (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 261 | : sequence<X> (flags (f & ~flags::keep_dom), c) // ambiguous |
---|
| 262 | { |
---|
| 263 | init (xml::transcode<C> (a.getValue ()), a.getOwnerElement ()); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | template <typename X, typename C> |
---|
| 267 | inline list<X, C, true>:: |
---|
| 268 | list (const std::basic_string<C>& s, |
---|
| 269 | const xercesc::DOMElement* parent, |
---|
| 270 | flags f, |
---|
| 271 | container* c) |
---|
| 272 | : sequence<X> (flags (f & ~flags::keep_dom), c) // ambiguous |
---|
| 273 | { |
---|
| 274 | init (s, parent); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | template <typename X, typename C> |
---|
| 278 | inline void list<X, C, true>:: |
---|
| 279 | init (const std::basic_string<C>& s, const xercesc::DOMElement* parent) |
---|
| 280 | { |
---|
| 281 | if (s.size () == 0) |
---|
| 282 | return; |
---|
| 283 | |
---|
| 284 | using std::basic_string; |
---|
| 285 | typedef typename basic_string<C>::size_type size_type; |
---|
| 286 | |
---|
| 287 | const C* data (s.c_str ()); |
---|
| 288 | size_type size (s.size ()); |
---|
| 289 | |
---|
| 290 | // Traverse the data while logically collapsing spaces. |
---|
| 291 | // |
---|
| 292 | for (size_type i (bits::find_ns<C> (data, size, 0)); |
---|
| 293 | i != basic_string<C>::npos;) |
---|
| 294 | { |
---|
| 295 | size_type j (bits::find_s (data, size, i)); |
---|
| 296 | |
---|
| 297 | if (j != basic_string<C>::npos) |
---|
| 298 | { |
---|
| 299 | push_back ( |
---|
| 300 | traits<X, C>::create ( |
---|
| 301 | basic_string<C> (data + i, j - i), parent, 0, 0)); |
---|
| 302 | |
---|
| 303 | i = bits::find_ns (data, size, j); |
---|
| 304 | } |
---|
| 305 | else |
---|
| 306 | { |
---|
| 307 | // Last element. |
---|
| 308 | // |
---|
| 309 | push_back ( |
---|
| 310 | traits<X, C>::create ( |
---|
| 311 | basic_string<C> (data + i, size - i), parent, 0, 0)); |
---|
| 312 | |
---|
| 313 | break; |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | |
---|
| 319 | // Parsing c-tors for built-in types. |
---|
| 320 | // |
---|
| 321 | |
---|
| 322 | |
---|
| 323 | // string |
---|
| 324 | // |
---|
| 325 | template <typename C, typename B> |
---|
| 326 | string<C, B>:: |
---|
| 327 | string (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 328 | : B (e, f, c), |
---|
| 329 | base_type (text_content<C> (e)) |
---|
| 330 | { |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | template <typename C, typename B> |
---|
| 334 | string<C, B>:: |
---|
| 335 | string (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 336 | : B (a, f, c), |
---|
| 337 | base_type (xml::transcode<C> (a.getValue ())) |
---|
| 338 | { |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | template <typename C, typename B> |
---|
| 342 | string<C, B>:: |
---|
| 343 | string (const std::basic_string<C>& s, |
---|
| 344 | const xercesc::DOMElement* e, |
---|
| 345 | flags f, |
---|
| 346 | container* c) |
---|
| 347 | : B (s, e, f, c), base_type (s) |
---|
| 348 | { |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | |
---|
| 352 | // normalized_string |
---|
| 353 | // |
---|
| 354 | template <typename C, typename B> |
---|
| 355 | normalized_string<C, B>:: |
---|
| 356 | normalized_string (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 357 | : base_type (e, f, c) |
---|
| 358 | { |
---|
| 359 | normalize (); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | template <typename C, typename B> |
---|
| 363 | normalized_string<C, B>:: |
---|
| 364 | normalized_string (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 365 | : base_type (a, f, c) |
---|
| 366 | { |
---|
| 367 | normalize (); |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | template <typename C, typename B> |
---|
| 371 | normalized_string<C, B>:: |
---|
| 372 | normalized_string (const std::basic_string<C>& s, |
---|
| 373 | const xercesc::DOMElement* e, |
---|
| 374 | flags f, |
---|
| 375 | container* c) |
---|
| 376 | : base_type (s, e, f, c) |
---|
| 377 | { |
---|
| 378 | normalize (); |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | template <typename C, typename B> |
---|
| 382 | void normalized_string<C, B>:: |
---|
| 383 | normalize () |
---|
| 384 | { |
---|
| 385 | typedef typename std::basic_string<C>::size_type size_type; |
---|
| 386 | |
---|
| 387 | size_type size (this->size ()); |
---|
| 388 | |
---|
| 389 | for (size_type i (0); i < size; ++i) |
---|
| 390 | { |
---|
| 391 | C& c ((*this)[i]); |
---|
| 392 | |
---|
| 393 | if (c == C (0x0D) || // carriage return |
---|
| 394 | c == C (0x09) || // tab |
---|
| 395 | c == C (0x0A)) |
---|
| 396 | c = C (0x20); |
---|
| 397 | } |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | |
---|
| 401 | // token |
---|
| 402 | // |
---|
| 403 | template <typename C, typename B> |
---|
| 404 | token<C, B>:: |
---|
| 405 | token (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 406 | : base_type (e, f, c) |
---|
| 407 | { |
---|
| 408 | collapse (); |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | template <typename C, typename B> |
---|
| 412 | token<C, B>:: |
---|
| 413 | token (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 414 | : base_type (a, f, c) |
---|
| 415 | { |
---|
| 416 | collapse (); |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | template <typename C, typename B> |
---|
| 420 | token<C, B>:: |
---|
| 421 | token (const std::basic_string<C>& s, |
---|
| 422 | const xercesc::DOMElement* e, |
---|
| 423 | flags f, |
---|
| 424 | container* c) |
---|
| 425 | : base_type (s, e, f, c) |
---|
| 426 | { |
---|
| 427 | collapse (); |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | template <typename C, typename B> |
---|
| 431 | void token<C, B>:: |
---|
| 432 | collapse () |
---|
| 433 | { |
---|
| 434 | // We have all whitespace normilized by our base. We just |
---|
| 435 | // need to collapse them. |
---|
| 436 | // |
---|
| 437 | typedef typename std::basic_string<C>::size_type size_type; |
---|
| 438 | |
---|
| 439 | size_type size (this->size ()), j (0); |
---|
| 440 | bool subs (false), trim (true); |
---|
| 441 | |
---|
| 442 | for (size_type i (0); i < size; ++i) |
---|
| 443 | { |
---|
| 444 | C c ((*this)[i]); |
---|
| 445 | |
---|
| 446 | if (c == C (0x20)) |
---|
| 447 | { |
---|
| 448 | subs = true; |
---|
| 449 | } |
---|
| 450 | else |
---|
| 451 | { |
---|
| 452 | if (subs) |
---|
| 453 | { |
---|
| 454 | subs = false; |
---|
| 455 | |
---|
| 456 | if (!trim) |
---|
| 457 | (*this)[j++] = C (0x20); |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | if (trim) |
---|
| 461 | trim = false; |
---|
| 462 | |
---|
| 463 | (*this)[j++] = c; |
---|
| 464 | } |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | this->resize (j); |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | |
---|
| 471 | // nmtoken |
---|
| 472 | // |
---|
| 473 | template <typename C, typename B> |
---|
| 474 | nmtoken<C, B>:: |
---|
| 475 | nmtoken (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 476 | : base_type (e, f, c) |
---|
| 477 | { |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | template <typename C, typename B> |
---|
| 481 | nmtoken<C, B>:: |
---|
| 482 | nmtoken (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 483 | : base_type (a, f, c) |
---|
| 484 | { |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | template <typename C, typename B> |
---|
| 488 | nmtoken<C, B>:: |
---|
| 489 | nmtoken (const std::basic_string<C>& s, |
---|
| 490 | const xercesc::DOMElement* e, |
---|
| 491 | flags f, |
---|
| 492 | container* c) |
---|
| 493 | : base_type (s, e, f, c) |
---|
| 494 | { |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | |
---|
| 498 | // nmtokens |
---|
| 499 | // |
---|
| 500 | template <typename C, typename B, typename nmtoken> |
---|
| 501 | nmtokens<C, B, nmtoken>:: |
---|
| 502 | nmtokens (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 503 | : B (e, f, c), base_type (e, f, c) |
---|
| 504 | { |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | template <typename C, typename B, typename nmtoken> |
---|
| 508 | nmtokens<C, B, nmtoken>:: |
---|
| 509 | nmtokens (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 510 | : B (a, f, c), base_type (a, f, c) |
---|
| 511 | { |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | template <typename C, typename B, typename nmtoken> |
---|
| 515 | nmtokens<C, B, nmtoken>:: |
---|
| 516 | nmtokens (const std::basic_string<C>& s, |
---|
| 517 | const xercesc::DOMElement* e, |
---|
| 518 | flags f, |
---|
| 519 | container* c) |
---|
| 520 | : B (s, e, f, c), base_type (s, e, f, c) |
---|
| 521 | { |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | |
---|
| 525 | // name |
---|
| 526 | // |
---|
| 527 | template <typename C, typename B> |
---|
| 528 | name<C, B>:: |
---|
| 529 | name (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 530 | : base_type (e, f, c) |
---|
| 531 | { |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | template <typename C, typename B> |
---|
| 535 | name<C, B>:: |
---|
| 536 | name (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 537 | : base_type (a, f, c) |
---|
| 538 | { |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | template <typename C, typename B> |
---|
| 542 | name<C, B>:: |
---|
| 543 | name (const std::basic_string<C>& s, |
---|
| 544 | const xercesc::DOMElement* e, |
---|
| 545 | flags f, |
---|
| 546 | container* c) |
---|
| 547 | : base_type (s, e, f, c) |
---|
| 548 | { |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | |
---|
| 552 | // ncname |
---|
| 553 | // |
---|
| 554 | template <typename C, typename B> |
---|
| 555 | ncname<C, B>:: |
---|
| 556 | ncname (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 557 | : base_type (e, f, c) |
---|
| 558 | { |
---|
| 559 | } |
---|
| 560 | |
---|
| 561 | template <typename C, typename B> |
---|
| 562 | ncname<C, B>:: |
---|
| 563 | ncname (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 564 | : base_type (a, f, c) |
---|
| 565 | { |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | template <typename C, typename B> |
---|
| 569 | ncname<C, B>:: |
---|
| 570 | ncname (const std::basic_string<C>& s, |
---|
| 571 | const xercesc::DOMElement* e, |
---|
| 572 | flags f, |
---|
| 573 | container* c) |
---|
| 574 | : base_type (s, e, f, c) |
---|
| 575 | { |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | |
---|
| 579 | // language |
---|
| 580 | // |
---|
| 581 | template <typename C, typename B> |
---|
| 582 | language<C, B>:: |
---|
| 583 | language (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 584 | : base_type (e, f, c) |
---|
| 585 | { |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | template <typename C, typename B> |
---|
| 589 | language<C, B>:: |
---|
| 590 | language (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 591 | : base_type (a, f, c) |
---|
| 592 | { |
---|
| 593 | } |
---|
| 594 | |
---|
| 595 | template <typename C, typename B> |
---|
| 596 | language<C, B>:: |
---|
| 597 | language (const std::basic_string<C>& s, |
---|
| 598 | const xercesc::DOMElement* e, |
---|
| 599 | flags f, |
---|
| 600 | container* c) |
---|
| 601 | : base_type (s, e, f, c) |
---|
| 602 | { |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | |
---|
| 606 | // id |
---|
| 607 | // |
---|
| 608 | template <typename C, typename B> |
---|
| 609 | id<C, B>:: |
---|
| 610 | id (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 611 | : base_type (e, f, c), identity_ (*this) |
---|
| 612 | { |
---|
| 613 | register_id (); |
---|
| 614 | } |
---|
| 615 | |
---|
| 616 | template <typename C, typename B> |
---|
| 617 | id<C, B>:: |
---|
| 618 | id (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 619 | : base_type (a, f, c), identity_ (*this) |
---|
| 620 | { |
---|
| 621 | register_id (); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | template <typename C, typename B> |
---|
| 625 | id<C, B>:: |
---|
| 626 | id (const std::basic_string<C>& s, |
---|
| 627 | const xercesc::DOMElement* e, |
---|
| 628 | flags f, |
---|
| 629 | container* c) |
---|
| 630 | : base_type (s, e, f, c), identity_ (*this) |
---|
| 631 | { |
---|
| 632 | register_id (); |
---|
| 633 | } |
---|
| 634 | |
---|
| 635 | |
---|
| 636 | // idref |
---|
| 637 | // |
---|
| 638 | template <typename X, typename C, typename B> |
---|
| 639 | idref<X, C, B>:: |
---|
| 640 | idref (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 641 | : base_type (e, f, c), identity_ (*this) |
---|
| 642 | { |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | template <typename X, typename C, typename B> |
---|
| 646 | idref<X, C, B>:: |
---|
| 647 | idref (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 648 | : base_type (a, f , c), identity_ (*this) |
---|
| 649 | { |
---|
| 650 | } |
---|
| 651 | |
---|
| 652 | template <typename X, typename C, typename B> |
---|
| 653 | idref<X, C, B>:: |
---|
| 654 | idref (const std::basic_string<C>& s, |
---|
| 655 | const xercesc::DOMElement* e, |
---|
| 656 | flags f, |
---|
| 657 | container* c) |
---|
| 658 | : base_type (s, e, f, c), identity_ (*this) |
---|
| 659 | { |
---|
| 660 | } |
---|
| 661 | |
---|
| 662 | |
---|
| 663 | |
---|
| 664 | // idrefs |
---|
| 665 | // |
---|
| 666 | template <typename C, typename B, typename idref> |
---|
| 667 | idrefs<C, B, idref>:: |
---|
| 668 | idrefs (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 669 | : B (e, f, c), base_type (e, f, c) |
---|
| 670 | { |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | template <typename C, typename B, typename idref> |
---|
| 674 | idrefs<C, B, idref>:: |
---|
| 675 | idrefs (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 676 | : B (a, f, c), base_type (a, f, c) |
---|
| 677 | { |
---|
| 678 | } |
---|
| 679 | |
---|
| 680 | template <typename C, typename B, typename idref> |
---|
| 681 | idrefs<C, B, idref>:: |
---|
| 682 | idrefs (const std::basic_string<C>& s, |
---|
| 683 | const xercesc::DOMElement* e, |
---|
| 684 | flags f, |
---|
| 685 | container* c) |
---|
| 686 | : B (s, e, f, c), base_type (s, e, f, c) |
---|
| 687 | { |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | |
---|
| 691 | // uri |
---|
| 692 | // |
---|
| 693 | template <typename C, typename B> |
---|
| 694 | uri<C, B>:: |
---|
| 695 | uri (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 696 | : B (e, f, c), |
---|
| 697 | base_type (trim (text_content<C> (e))) |
---|
| 698 | { |
---|
| 699 | } |
---|
| 700 | |
---|
| 701 | template <typename C, typename B> |
---|
| 702 | uri<C, B>:: |
---|
| 703 | uri (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 704 | : B (a, f, c), |
---|
| 705 | base_type (trim (xml::transcode<C> (a.getValue ()))) |
---|
| 706 | { |
---|
| 707 | } |
---|
| 708 | |
---|
| 709 | template <typename C, typename B> |
---|
| 710 | uri<C, B>:: |
---|
| 711 | uri (const std::basic_string<C>& s, |
---|
| 712 | const xercesc::DOMElement* e, |
---|
| 713 | flags f, |
---|
| 714 | container* c) |
---|
| 715 | : B (s, e, f, c), base_type (trim (s)) |
---|
| 716 | { |
---|
| 717 | } |
---|
| 718 | |
---|
| 719 | |
---|
| 720 | // qname |
---|
| 721 | // |
---|
| 722 | template <typename C, typename B, typename uri, typename ncname> |
---|
| 723 | qname<C, B, uri, ncname>:: |
---|
| 724 | qname (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 725 | : B (e, f, c) |
---|
| 726 | { |
---|
| 727 | std::basic_string<C> v (trim (text_content<C> (e))); |
---|
| 728 | ns_ = resolve (v, &e); |
---|
| 729 | name_ = xml::uq_name (v); |
---|
| 730 | } |
---|
| 731 | |
---|
| 732 | template <typename C, typename B, typename uri, typename ncname> |
---|
| 733 | qname<C, B, uri, ncname>:: |
---|
| 734 | qname (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 735 | : B (a, f, c) |
---|
| 736 | { |
---|
| 737 | std::basic_string<C> v (trim (xml::transcode<C> (a.getValue ()))); |
---|
| 738 | ns_ = resolve (v, a.getOwnerElement ()); |
---|
| 739 | name_ = xml::uq_name (v); |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | template <typename C, typename B, typename uri, typename ncname> |
---|
| 743 | qname<C, B, uri, ncname>:: |
---|
| 744 | qname (const std::basic_string<C>& s, |
---|
| 745 | const xercesc::DOMElement* e, |
---|
| 746 | flags f, |
---|
| 747 | container* c) |
---|
| 748 | : B (s, e, f, c) |
---|
| 749 | { |
---|
| 750 | std::basic_string<C> v (trim (s)); |
---|
| 751 | ns_ = resolve (v, e); |
---|
| 752 | name_ = xml::uq_name (v); |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | template <typename C, typename B, typename uri, typename ncname> |
---|
| 756 | uri qname<C, B, uri, ncname>:: |
---|
| 757 | resolve (const std::basic_string<C>& s, const xercesc::DOMElement* e) |
---|
| 758 | { |
---|
| 759 | std::basic_string<C> p (xml::prefix (s)); |
---|
| 760 | |
---|
| 761 | if (e) |
---|
| 762 | { |
---|
| 763 | // This code is copied verbatim from xml/dom/elements.hxx. |
---|
| 764 | // |
---|
| 765 | |
---|
| 766 | // 'xml' prefix requires special handling and Xerces folks refuse |
---|
| 767 | // to handle this in DOM so I have to do it myself. |
---|
| 768 | // |
---|
| 769 | if (p == xml::bits::xml_prefix<C> ()) |
---|
| 770 | return xml::bits::xml_namespace<C> (); |
---|
| 771 | |
---|
| 772 | const XMLCh* xns ( |
---|
| 773 | e->lookupNamespaceURI ( |
---|
| 774 | p.empty () ? 0 : xml::string (p).c_str ())); |
---|
| 775 | |
---|
| 776 | if (xns != 0) |
---|
| 777 | return xml::transcode<C> (xns); |
---|
| 778 | } |
---|
| 779 | |
---|
| 780 | throw no_prefix_mapping<C> (p); |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | |
---|
| 784 | // base64_binary |
---|
| 785 | // |
---|
| 786 | // We are not doing whitespace collapsing since the decode |
---|
| 787 | // functions can handle it like this. |
---|
| 788 | // |
---|
| 789 | template <typename C, typename B> |
---|
| 790 | base64_binary<C, B>:: |
---|
| 791 | base64_binary (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 792 | : B (e, f, c) |
---|
| 793 | { |
---|
| 794 | // This implementation is not optimal. |
---|
| 795 | // |
---|
| 796 | std::basic_string<C> str (trim (text_content<C> (e))); |
---|
| 797 | decode (xml::string (str).c_str ()); |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | template <typename C, typename B> |
---|
| 801 | base64_binary<C, B>:: |
---|
| 802 | base64_binary (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 803 | : B (a, f, c) |
---|
| 804 | { |
---|
| 805 | std::basic_string<C> str (trim (xml::transcode<C> (a.getValue ()))); |
---|
| 806 | decode (xml::string (str).c_str ()); |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | template <typename C, typename B> |
---|
| 810 | base64_binary<C, B>:: |
---|
| 811 | base64_binary (const std::basic_string<C>& s, |
---|
| 812 | const xercesc::DOMElement* e, |
---|
| 813 | flags f, |
---|
| 814 | container* c) |
---|
| 815 | : B (s, e, f, c) |
---|
| 816 | { |
---|
| 817 | std::basic_string<C> str (trim (s)); |
---|
| 818 | decode (xml::string (str).c_str ()); |
---|
| 819 | } |
---|
| 820 | |
---|
| 821 | |
---|
| 822 | // hex_binary |
---|
| 823 | // |
---|
| 824 | template <typename C, typename B> |
---|
| 825 | hex_binary<C, B>:: |
---|
| 826 | hex_binary (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 827 | : B (e, f, c) |
---|
| 828 | { |
---|
| 829 | // This implementation is not optimal. |
---|
| 830 | // |
---|
| 831 | std::basic_string<C> str (trim (text_content<C> (e))); |
---|
| 832 | decode (xml::string (str).c_str ()); |
---|
| 833 | } |
---|
| 834 | |
---|
| 835 | template <typename C, typename B> |
---|
| 836 | hex_binary<C, B>:: |
---|
| 837 | hex_binary (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 838 | : B (a, f, c) |
---|
| 839 | { |
---|
| 840 | std::basic_string<C> str (trim (xml::transcode<C> (a.getValue ()))); |
---|
| 841 | decode (xml::string (str).c_str ()); |
---|
| 842 | } |
---|
| 843 | |
---|
| 844 | template <typename C, typename B> |
---|
| 845 | hex_binary<C, B>:: |
---|
| 846 | hex_binary (const std::basic_string<C>& s, |
---|
| 847 | const xercesc::DOMElement* e, |
---|
| 848 | flags f, |
---|
| 849 | container* c) |
---|
| 850 | : B (s, e, f, c) |
---|
| 851 | { |
---|
| 852 | std::basic_string<C> str (trim (s)); |
---|
| 853 | decode (xml::string (str).c_str ()); |
---|
| 854 | } |
---|
| 855 | |
---|
| 856 | // entity |
---|
| 857 | // |
---|
| 858 | template <typename C, typename B> |
---|
| 859 | entity<C, B>:: |
---|
| 860 | entity (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 861 | : base_type (e, f, c) |
---|
| 862 | { |
---|
| 863 | } |
---|
| 864 | |
---|
| 865 | template <typename C, typename B> |
---|
| 866 | entity<C, B>:: |
---|
| 867 | entity (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 868 | : base_type (a, f, c) |
---|
| 869 | { |
---|
| 870 | } |
---|
| 871 | |
---|
| 872 | template <typename C, typename B> |
---|
| 873 | entity<C, B>:: |
---|
| 874 | entity (const std::basic_string<C>& s, |
---|
| 875 | const xercesc::DOMElement* e, |
---|
| 876 | flags f, |
---|
| 877 | container* c) |
---|
| 878 | : base_type (s, e, f, c) |
---|
| 879 | { |
---|
| 880 | } |
---|
| 881 | |
---|
| 882 | |
---|
| 883 | // entities |
---|
| 884 | // |
---|
| 885 | template <typename C, typename B, typename entity> |
---|
| 886 | entities<C, B, entity>:: |
---|
| 887 | entities (const xercesc::DOMElement& e, flags f, container* c) |
---|
| 888 | : B (e, f, c), base_type (e, f, c) |
---|
| 889 | { |
---|
| 890 | } |
---|
| 891 | |
---|
| 892 | template <typename C, typename B, typename entity> |
---|
| 893 | entities<C, B, entity>:: |
---|
| 894 | entities (const xercesc::DOMAttr& a, flags f, container* c) |
---|
| 895 | : B (a, f, c), base_type (a, f, c) |
---|
| 896 | { |
---|
| 897 | } |
---|
| 898 | |
---|
| 899 | template <typename C, typename B, typename entity> |
---|
| 900 | entities<C, B, entity>:: |
---|
| 901 | entities (const std::basic_string<C>& s, |
---|
| 902 | const xercesc::DOMElement* e, |
---|
| 903 | flags f, |
---|
| 904 | container* c) |
---|
| 905 | : B (s, e, f, c), base_type (s, e, f, c) |
---|
| 906 | { |
---|
| 907 | } |
---|
| 908 | } |
---|
| 909 | } |
---|
| 910 | } |
---|