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 668745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:04:30+00:00 2026-05-14T00:04:30+00:00

I have a single xml file and every new thread of the program (BHO)

  • 0

I have a single xml file and every new thread of the program (BHO) is using the same Tinyxml file.

every time a new window is open in the program, it runs this code:

const char * xmlFileName = "C:\\browsarityXml.xml";
TiXmlDocument doc(xmlFileName);
doc.LoadFile();
//some new lines in the xml.. and than save:
doc.SaveFile(xmlFileName);

The problem is that after the first window is adding new data to the xml and saves it, the next window can’t add to it. although the next one can read the data in the xml, it can’t write to it.

I thought about two possibilities to make it work, but I don’t know how to implement them:

  1. Destroy the doc object when I’m done with it.
  2. Some function in Tinyxml library to unload the file.

Any help or better understanding of the problem will be great.
Thanks.

  • 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-14T00:04:30+00:00Added an answer on May 14, 2026 at 12:04 am

    Update based on comments (scrap previous answer):

    OK, I didn’t see much in the TinyXml documentation that tells us how to open a document without restriction to other threads.

    What you should do in this case is declare only one instance to the TiXmlDocument and share it between threads. Whenever a thread writes to the file it will enter a critical section, write what it needs to write, save the file, then exit the critical section.

    I don’t see another workaround.

    Update per comments:
    Since you’re using MFC threads your code should look something like this:

    class SafeTinyXmlDocWrapper
    {
    private:
        static bool m_isAlive = FALSE;
        static CCriticalSection m_criticalSection;
        char* m_xmlFileName;
        TiXmlDocument m_doc;
    
    public:
    
        SafeTinyXmlDocWrapper()
        {
            m_xmlFileName = "C:\\browsarityXml.xml";
            m_doc = TiXmlDocument(m_xmlFileName);
            m_doc.LoadFile();
            m_isAlive = TRUE;
        }
    
        ~SafeTinyXmlDocWrapper()
        {
            CSingleLock lock(&m_criticalSection);
            lock.Lock(); // only one thread can lock
    
            m_isAlive = FALSE;
    
            // cleanup and dispose of the document
    
            lock.Unlock();
        }
    
        void WriteBatch(BatchJob& job)
        {
            CSingleLock lock(&m_criticalSection);
            lock.Lock(); // only one thread can lock
            if(m_isAlive) // extra protection in case the destructor was called
            {
                // write the batch job to the xml document
    
                // save the xml document
                m_doc.SaveFile(m_xmlFileName);
            }
            lock.Unlock(); // the thread unlocks once it's done
        }
    }
    

    I have not written C++ in some time now, but it should be roughly what you’re looking for. Bells and whistles cost extra :).

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

Sidebar

Related Questions

I parse an xml file containing books, for each new node I go: Book
my ASP.NET application reads an xml file to determine which environment it's currently in
Background: I am parsing a 330 meg xml file into a DB (netflix catalog)
My aim is to create nested resources via one REST request. The REST requests
I am currently working on a little application: The structure follows in some way
I got back from the weekend to discover that somebody ****ahem**** had missed a
I am trying to model entity's attachments in REST. Let's say a defect entity
First off here is my code. IEnumerable<XElement> targetDirectory = from XElement e in workingXmlDocument.Descendants(wixNS
If that title did not make sense (which I'm expecting =)) here is what

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.