[xsd-users] <any> and xerces cloneNode

Ray Lischner rlischner at proteus-technologies.com
Mon Dec 8 15:57:50 EST 2008


I need to handle an <any> element. To make it easier, I defined a new complex type whose sole content is <any>, so I have only this type to customize. I customized the type to store the any content in a a DOMNode.
 
The default constructor stores a null pointer, of course. The copy constructor and assignment operator call cloneNode(source, true) to make a deep copy of the <any> element and its subelements. I overload operator<<(DOMElement&, MyType) to call importNode so I can copy the <any> element into the destination DOM.
 
But it doesn't work. I keep getting memory errors. I commented out all calls to release(), just to make sure I didn't have a logic error that resulted in a double-free. So I should have some memory leaks, but no other problems. Still, I get segfaults from inside cloneNode(). What am I doing wrong? (I'm still using Code Synthesis 2.3.1, with Xerces 2.7.)
 
The class looks something like this:
 
class Any : public AnyBase {
public:
   Any() : AnyBase(), any_(0) {}
  ~Any() {}
  Any(const xercesc::DOMElement& dom, xml_schema::flags f=0, xml_schema::type* c=0)
  : AnyBase(dom, f, c), any_(dom.getFirstChild())
  {}
  Any(Any const& other, xml_schema::flags f=0, xml_schema::type* c=0)
  : Any(other, f, c), any_(other.any())
  {}
  Any& operator=(Any const& other) {
    static_cast<AnyBase&>(*this) = other;
    any(other.any());
    return *this;
  }
  virtual Any* _clone(xml_schema::flags f=0, xml_schema::type* c = 0) const { return new Any(*this, f, c); }
 
  xercesc::DOMNode* any() { return any_; }
  xercesc::DOMNode const* any() const { return any_; }
  void any(xercesc::DOMNode const* any) { any_ = any ? any->cloneNode() : 0; }
private:
  xercesc::DOMNode* any_;
};
 
void operator<<(xercesc::DOMElement& e, Any& a)
{
  e << static_cast<AnyBase const&>(a);
  if (a.any() != 0) {
    xercesc::DOMNode* n = e.getOwnerDocument()->importNode(a.any());
    e.appendChild(n);
  }
}
 
Ray Lischner,
Senior Member of Technical Staff
133 National Business Pkwy, Ste 150      t. 443.539.3448
Annapolis Junction, MD 20701                c. 410.854.5170
rlischner at proteus-technologies.com         f. 443.539.3370
 
This electronic message and any files transmitted with it contain information
which may be privileged and/or proprietary. The information is intended for use
solely by the intended recipient(s). If you are not the intended recipient, be
aware that any disclosure, copying, distribution or use of this information is
prohibited. If you have received this electronic message in error, please advise
the sender by reply email or by telephone (443.539.3400) and delete the message. 



More information about the xsd-users mailing list