// file : xsd/cxx/xml/dom/serialization-header.txx // author : Boris Kolpackov // copyright : Copyright (c) 2005-2008 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include #include #include #include #include #include #include #include #include namespace xsd { namespace cxx { namespace xml { namespace dom { // // template std::basic_string prefix (const C* ns, const xercesc::DOMElement& e) { string xns (ns); #if _XERCES_VERSION >= 30000 const XMLCh* p (e.lookupPrefix (xns.c_str ())); if (p == 0) { // 'xml' prefix requires special handling and Xerces folks // refuse to handle this in DOM so I have to do it myself. // if (std::basic_string (ns) == xml::bits::xml_namespace ()) return xml::bits::xml_prefix (); throw no_prefix (); } #else const XMLCh* p (e.lookupNamespacePrefix (xns.c_str (), false)); if (p == 0) { if (e.isDefaultNamespace (xns.c_str ())) { return std::basic_string (); } else { // 'xml' prefix requires special handling and Xerces folks // refuse to handle this in DOM so I have to do it myself. // if (std::basic_string (ns) == xml::bits::xml_namespace ()) return xml::bits::xml_prefix (); throw no_prefix (); } } #endif return transcode (p); } // // template void clear (xercesc::DOMElement& e) { // HP aCC cannot handle using namespace xercesc; // using xercesc::DOMNode; using xercesc::DOMAttr; using xercesc::DOMNamedNodeMap; using xercesc::XMLString; using xercesc::SchemaSymbols; // Remove child nodes. // while (xercesc::DOMNode* n = e.getFirstChild ()) { e.removeChild (n); n->release (); } // Remove attributes. // DOMNamedNodeMap* att_map (e.getAttributes ()); XMLSize_t n (att_map->getLength ()); if (n != 0) { std::vector atts; // Collect all attributes to be removed while filtering // out special cases (xmlns & xsi). // for (XMLSize_t i (0); i != n; ++i) { DOMAttr* a (static_cast (att_map->item (i))); const XMLCh* ns (a->getNamespaceURI ()); if (ns != 0) { if (XMLString::equals (ns, xercesc::XMLUni::fgXMLNSURIName)) continue; if (XMLString::equals (ns, SchemaSymbols::fgURI_XSI)) { const XMLCh* name (a->getLocalName ()); if (XMLString::equals ( name, SchemaSymbols::fgXSI_SCHEMALOCACTION) || XMLString::equals ( name, SchemaSymbols::fgXSI_NONAMESPACESCHEMALOCACTION)) continue; } } atts.push_back (a); } for (std::vector::iterator i (atts.begin ()), end (atts.end ()); i != end; ++i) { e.removeAttributeNode (*i); (*i)->release (); } } } } } } }