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

  • Home
  • SEARCH
  • 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 3699076
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:03:33+00:00 2026-05-19T05:03:33+00:00

I questioned before about a similar problem in RapidXml, I want to know, now,

  • 0

I questioned before about a similar problem in RapidXml, I want to know, now, the same but using Xerces-C.

I am working on a c++ application that needs to parse xml.

Consider the following:

xml file: file1.xml

<root>
   <node1>value1</node1>
   <node2>value2</node2>
</root>

xml file: file2.xml

<anotherroot>
   <anothernode1>anothervalue1</anothernode1>
   <anothernode2>anothervalue2</anothernode2>
</anotherroot>

my cpp file

using namespace xercesc;
// First tree
XercesDOMParser* parser1 = new XercesDOMParser();
parser1->parse("file1.xml"); // Loading xml and building tree (XercesDOMParser owns the document)
DOMDocument* doc1 = parser1->getDocument();
DOMElement* el1 = doc1->getDocumentElement(); // Getting root
// Second tree
XercesDOMParser* parser2 = new XercesDOMParser();
parser2->parse("file2.xml"); // Loading xml and building tree (XercesDOMParser owns the document)
DOMDocument* doc2 = parser2->getDocument();
DOMElement* el2 = doc2->getDocumentElement(); // Getting root

I would like to do this:

el2->appendChild(el1);

So that the final xml in the document doc2 is

<anotherroot>
   <anothernode1>anothervalue1</anothernode1>
   <anothernode2>anothervalue2</anothernode2>
   <root>
      <node1>value1</node1>
      <node2>value2</node2>
   </root>
</anotherroot>

But when doing so I get:

terminate called after throwing an
instance of
‘xercesc_3_1::DOMException’ Aborted

I guess because the element I want to attach belongs to another tree. How can I achieve this result? The problem, basically, is that I have a tree and a string containing an xml segment.
I NEED TO PARSE THE STRING get a DOM object representing that xml and attaching to a node of the other tree.
The most important thing is that I have the string with the xml inside… I cannot bypass this important requirement. From a string, getting the dom and attaching it.
It seems to be something impossible… possible?

How can I do this???
I really cannot accept the fact that Xerces-C programmers never figured such a scenario and did not provide a reasonable functionality to achieve such solution.

Maybe it would be enough even if I coult tell me whether there is a way of CHANGING THE NODE OWNERSHIP os a node or an element. You see, there is the WRONG_DOCUMENT_ERR which is raised when what I tried before is performed. Well, If the library provided a way to change the ownership of a node so that it belongs to another document, I would be all right and my problem would be solved!

Thankyou

  • 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-19T05:03:34+00:00Added an answer on May 19, 2026 at 5:03 am

    DOMDocument::importNode is a DOM Level 2 function that was designed to solve this exact problem:

    DOMElement * el1Imported = doc2->importNode(el1, true);
    el2->appendChild(el1Imported); // element is now in right document
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've asked a very similar question before, but this time is not about VB
Note: I know there was disscussion about similar questions before, like in: link text
There was a question about using stripslashes and mysql_real_escape_string on a password before hashing
I have asked a similar question before, but I didn't have a firm grasp
Today I meet a similar problem and it reminds me about this thread. In
A similar question was asked and answered about a year ago, but was either
Question is similar to this (unanswered) and this one (same problem not involving Git).
I'm working on a web application using a pretty heavy amount of javascript. On
Before you all get pissy about me posting this question again, let me explain
Before answering, it is not as easy question as you might have thought about

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.