Giter Club home page Giter Club logo

Comments (3)

jima80525 avatar jima80525 commented on August 26, 2024

Isn't that because the doc has already been destructed? If you make the
doc a member of the class so it has not been freed, it will work.
Change the class to:

class myxmltool
{
public:
string filename;
xml_node root;
xml_document doc;

    myxmltool(string fname)
    {
        doc.load_file(fname.c_str());
        root = xml_node(doc.root()); //root is created and has contents
    }

};

jima

On Fri, Dec 4, 2015 at 8:39 AM, changshen [email protected] wrote:

class myxmltool
{
public:
string filename;
xml_node root;
myxmltool(string fname)
{
xml_document doc;
doc.load_file(fname.c_str());
root = xml_node(doc.root()); //root is created and has contents
}

};

void main()
{
myxmltool tool = myxmltool("c:\myxmlfile.xml");
xml_node rootnode = tool.root; //root was not there. it was distroyed
already

}


Reply to this email directly or view it on GitHub
#71.

from pugixml.

zeux avatar zeux commented on August 26, 2024

xml_document object controls the lifetime of the tree; xml_node objects are just handles to nodes of that tree. Destroying the xml_document object leads to the entire tree being destroyed; it's invalid to use the nodes from the tree after that. This is described in more detail in this section of the manual: http://pugixml.org/docs/manual.html#dom.cpp.

from pugixml.

changshen avatar changshen commented on August 26, 2024

Thanks zeux and jima
I thought of this and tried to have xml_document as a member of extended class. But compiler complained :
Error 2 error C2248: 'pugi::xml_document::xml_document' : cannot access private member declared in class 'pugi::xml_document'
even with empty constructor
myxmltool(string fname){}

from pugixml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.