Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3279210
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:34:01+00:00 2026-05-17T19:34:01+00:00

I want to wrap part of the TinyXML library in some custom classes in

  • 0

I want to wrap part of the TinyXML library in some custom classes in my project because I only need some of its functionality and I do not wish to expose everything.

I have a problem where my XMLDocument::AddNode(...) function is basically doing the same thing that my XMLNode class is meant for. I wondered if anyone could give me some design tips on how to wrap the TinyXML library so I don’t break encapsulation and my wrapper classes don’t expose the TinyXML library to the rest of my code.

class XMLNode
    {
    public:
        XMLNode::XMLNode();
        XMLNode::XMLNode(const std::string& element);  // Creates a TiXMLElement object
        XMLNode::XMLNode(XMLNode& nodycopy);
        XMLNode::~XMLNode();

        XMLNode GetFirstChild();
        XMLNode GetNextSibling();

        std::string GetNodeValue();
        std::string GetNodeName();

        void AddNodeText(const std::string& text);
        void AddNodeAttribute();

    private:
        std::string value;
        std::string nodename;

        TiXmlElement* thisnode;
    };

//These functions do the same as my AddNode does from XMLDocument, it seems rather silly...
    XMLNode::XMLNode(const std::string& str_element) 
{
    thisnode = new TiXmlElement(str_element.c_str());
    nodename = str_element;
}

void XMLNode::AddNodeText(const std::string& nodetext)
{
    TiXmlText* text = new TiXmlText(nodetext.c_str());
    thisnode->LinkEndChild(text);
    value = nodetext;
}


class XMLDocument
    {
    public:
        XMLDocument::XMLDocument(const std::string& documentname);
        XMLDocument::~XMLDocument();

        void SaveToFile(std::string filename);
        std::string basicXML(std::string rootnode);

        void AddNode(XMLNode& node);
        XMLNode GetXPathNode(const std::string& node);
        void AppendCloneNodeAsChild(XMLNode& nodetoappend); 

        void SetRoot(XMLNode& rootnode);
    private:
        TiXmlDocument document;
        TiXmlElement root;
        TiXmlElement currentelement;

    };

void XMLDocument::AddNode(XMLNode& node)  // This function does over what XMLNode class is actually for... I just want to add the node to the XMLDocument
{
    std::string val = node.GetNodeName();
    TiXmlElement* el = new TiXmlElement(val.c_str());
    TiXmlText * txt = new TiXmlText(node.GetNodeValue().c_str());
    el->LinkEndChild(txt);
    document.LinkEndChild(el);
}

Can anybody give me some suggestions on how to wrap this properly and only expose the functionality of TinyXML that I want?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:34:02+00:00Added an answer on May 17, 2026 at 7:34 pm

    You already encapsulate the TinyXml document – now you just need to delegate to it where you want, to expose only a subset of the function it provides.

    Replace this

    void XMLDocument::AddNode(XMLNode& node)  // This function does over what XMLNode class is actually for... I just want to add the node to the XMLDocument
    {
        std::string val = node.GetNodeName();
        TiXmlElement* el = new TiXmlElement(val.c_str());
        TiXmlText * txt = new TiXmlText(node.GetNodeValue().c_str());
        el->LinkEndChild(txt);
        document.LinkEndChild(el);
    }
    

    with this

    void XMLDocument::AddNode(XMLNode& node) 
    {
        document.AddNode(node);
    }
    

    This is perfectly legitimate since you don’t want to expose the full TiXmlDocument to your class’s clients. Think of how std::queue and std::stack act as adapters on underlying containers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to wrap some queries in a SharedDbConnectionScope and execute them under a
in a project we want to wrap the Boost Asio socket in a way,
I want to display some div's in a wrap. The div have same class
I want to wrap an existing click event in some extra code. Basically I
I want to wrap around a list/vector in C++ like in Python. Basically I
i am generating html control dynamically and now i want to wrap the html
These 4 queries produce the desired result, however I want to wrap these queries
Javascript can't handle my longs, so I want RestEasy to wrap them with quotation
Should I wrap all the files I want to install in individual components? What
i want to loop trough all my delicious.com bookmarks and wrap a link arround

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.