Fwd: Re: [xsd-users] Lines numbers after parsing

Jon D tyrecius13 at yahoo.com
Sun Jul 8 05:28:27 EDT 2007


--- Boris Kolpackov <boris at codesynthesis.com> wrote:

> I would definitely like this bug reported and fixed in Xerces-C++.
> I checked and it appears the DOMUserDataHandler interface is supposed
> to support cloning. Are you saying if you clone the whole tree (from
> DOMDocument) then the corresponding clone events are not triggered
> on DOMUserDataHandler? What about the current SVN version?

Below is my current minimal example which consistently reproduces the
bug on my system. Note that I have just been using the simple hello.xml
and hello.xsd files from your examples as data:

---Begin minimal.cc---
// minimal.cpp

#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLChar.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMUserDataHandler.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>

#include <xsd/cxx/xml/dom/elements.hxx>

#include <iostream>
#include <memory>

using std::cerr;
using std::endl;
using std::auto_ptr;

using namespace xercesc;
namespace xml = xsd::cxx::xml;

static XMLCh * customKey = L"CustomKey";

class CustomDataHandler : public DOMUserDataHandler {
public:
  virtual void handle(DOMOperationType operation,
                      const XMLCh *const /*key*/,
                      void * /*data*/,
                      const DOMNode * /*src*/,
                      const DOMNode * /*dst*/)
  {
    cerr << "dataHandler called" << endl;
  }
};

static CustomDataHandler dataHandler;

class CustomDOMParser : public XercesDOMParser
{
  virtual void startElement(const XMLElementDecl &elemDecl,
                            const unsigned int uriId,
                            const XMLCh *const prefixName,
                            const RefVectorOf<XMLAttr> & attrList,
                            const unsigned int attrCount,
                            const bool isEmpty,
                            const bool isRoot)
  {
    XercesDOMParser::startElement(elemDecl, uriId, prefixName,
attrList, 
                                  attrCount, isEmpty, isRoot);
    getCurrentNode()->setUserData(customKey, (void*)5, &dataHandler);
  }
};


int main()
{
  try
  {
    XMLPlatformUtils::Initialize();
    
    auto_ptr<CustomDOMParser> parser(new CustomDOMParser());
    parser->parse("hello.xml");

    xml::dom::auto_ptr<DOMDocument> original(parser->adoptDocument());

    cerr << "--- Before clone document" << endl;
    xml::dom::auto_ptr<DOMNode>
clonedDocument(original->cloneNode(true));
    cerr << "--- After clone document" << endl << endl;

    cerr << "--- Before clone element" << endl;
    xml::dom::auto_ptr<DOMNode> clonedElement
(original->getDocumentElement()->cloneNode(true));
    cerr << "--- After clone element" << endl << endl;
  }
  catch (...)
  {
    cerr << "Unknown Exception" << endl;
  }

  XMLPlatformUtils::Terminate();
  return 0;
}
---End minimal.cc---

The result I get is:

--- Before clone document
--- After clone document

--- Before clone element
dataHandler called
dataHandler called
dataHandler called
dataHandler called
dataHandler called
--- After clone element

dataHandler called
dataHandler called
dataHandler called
dataHandler called
dataHandler called

Which implies that the dataHandler is not being called when cloning the
document as a whole. I've spot tested other parts of the cloned
document (using things like getLocalName()) and they seem to be ok.

I've only tested it under Windows XP using VC++ 7.1. I will try to
reproduce it under linux and the latest SVN after I remove the last
little bits of xsd (your nifty auto_ptrs). If I can still reproduce it
I'll submit it as a bug. This behaviour seems very odd to me as well.
Let me know whether you can reproduce it and if I am doing anything
obviously incorrect here.

> Actually the upcoming version (3.0.0) will support re-using DOM trees
> without cloning. For that a new flag, xml_schema::flags::own_dom, was
> added. You can already get this functionality in the latest 3.0.0.b2.
> For more information on this flag see Chapter 3, "Parsing" in the
> C++/Tree Mapping User Manual that comes with the 3.0.0.b2 release.
> The final 3.0.0 should be released in 2-3 weeks.

That will be a handy workaround until the core bug gets fixed. Thanks.

-D



      ____________________________________________________________________________________
Shape Yahoo! in your own image.  Join our Network Research Panel today!   http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 





More information about the xsd-users mailing list