[xsd-users] namespace clash: suggestion for improvement
Jaume Dominguez Faus
jaume.faus at vianova.no
Fri Jul 17 01:05:15 EDT 2015
Hi, list.
I am just upgrading to XSD 4.0 and I stumbled into this.
In file serialization.txx lines 98 to 116 we find this code
if (!x.null_content () && x.dom_content ().present ())
{
// Clone the contents of the element.
//
using namespace xercesc;
DOMDocument& doc (*e.getOwnerDocument ());
const DOMElement& se (x.dom_content ().get ());
DOMNamedNodeMap& sa (*se.getAttributes ());
for (XMLSize_t i (0), n (sa.getLength ()); i != n; ++i)
e.setAttributeNode (
static_cast<DOMAttr*> (doc.importNode (sa.item (i), true)));
for (DOMNode* sn (se.getFirstChild ());
sn != 0;
sn = sn->getNextSibling ())
e.appendChild (doc.importNode (sn, true));
}
Which is fine in non-windows operating systems (I successfully upgraded in Linux and Mac). But it happens that in Windows this might cause a name clash with MS xml library (as follows) if another library includes it or similar.
D:\SDKs\xsd-4.0.0\include\xsd/cxx/tree/serialization.txx(104) : error C2872: 'DOMDocument' : ambiguous symbol
could be 'c:\program files (x86)\windows kits\8.1\include\um\msxml.h(183) : DOMDocument'
or 'D:\SDKs\xerces-c-3.1.1\win64-vc-120\include\xercesc/dom/DOMDocument.hpp(64) : xercesc_3_1::DOMDocument'
Since XSD is basically a header-only library and it is suggested that using namespace should be avoided in includeable files, maybe it is a good idea to remove the using namespace xercesc statement in line 102 and use it in all the types like this instead
if (!x.null_content () && x.dom_content ().present ())
{
// Clone the contents of the element.
//
xercesc::DOMDocument& doc (*e.getOwnerDocument ());
const xercesc::DOMElement& se (x.dom_content ().get ());
xercesc::DOMNamedNodeMap& sa (*se.getAttributes ());
for (XMLSize_t i (0), n (sa.getLength ()); i != n; ++i)
e.setAttributeNode (
static_cast<xercesc::DOMAttr*> (doc.importNode (sa.item (i), true)));
for (xercesc::DOMNode* sn (se.getFirstChild ());
sn != 0;
sn = sn->getNextSibling ())
e.appendChild (doc.importNode (sn, true));
}
Doing like that I can build without problems (except for the fact I could need to "hack" if newer versions don't consider this).
Just a suggestion.
Regards.
More information about the xsd-users
mailing list