<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[tinyxml - triviales problem?!]]></title><description><![CDATA[<p>Hallo liebe c++ experten,<br />
ich hab heute schon den ganzen tag mit der suche nach einem problem verbracht,<br />
was auf den ersten blick recht simpel zu sein scheint, aber ich hab überhaupt nichts dazu gefunden - deswegen jetzt hier ein thread dazu:</p>
<p>Die Idee ist folgende: ich hab ein Xml-file beliebiger &quot;Tiefe&quot;.<br />
es interessiert mich eigentlich nicht, wie das Xml-file aufgebaut ist,<br />
sondern ich weiß, dass es &quot;valid&quot; ist und alles andere ist mir egal.</p>
<p>Jetzt möchte ich mit &quot;Tinyxml&quot; , die Xml-datei einlesen und anschließend<br />
alles was sich im &quot;root-element&quot; der datei befindet<br />
( andere knoten,attribute, text etc ...) einfach in einen neuen mit &quot;tinyxml&quot; erstellten element-baum mit</p>
<pre><code>LinkEndChild(...)
</code></pre>
<p>einhängen!</p>
<p>hier mein c++ -code zum testen:</p>
<pre><code>buildTree()
</code></pre>
<p>erzeugt einfach nur das xml-dokument, das später eingehängt werden soll.</p>
<pre><code>appendTree()
</code></pre>
<p>erzeugt einen neuen &quot;baum&quot;, in den dann das rootelement mit inhalt eingehängt werden soll<br />
ich schaffe es bis jetzt nur, das dokument einzulesen und den namen des root-elements einzuhängen,<br />
was muss ich machen, dass alles was im rootelement drin steht eingehängt wird?</p>
<pre><code class="language-cpp">/*
 * Test.cpp
 *
 *  Created on: 09.04.2010
 *      Author: blulining
 */
#include &quot;tinyxml.h&quot;
#include &quot;tinystr.h&quot;

#include &lt;vector&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;
using namespace std;

void appendTree() {
	TiXmlDocument doc;
	doc.LoadFile(&quot;TestFile.xml&quot;);

	doc.Print();
	TiXmlElement* rootElement = doc.RootElement();

	TiXmlDocument newDocument;
	TiXmlDeclaration * decl = new TiXmlDeclaration(&quot;1.0&quot;, &quot;&quot;, &quot;&quot;);
	TiXmlElement * element = new TiXmlElement(&quot;NewRoot&quot;);
	newDocument.LinkEndChild(decl);
	newDocument.LinkEndChild(element);

	element-&gt;LinkEndChild(new TiXmlElement(rootElement-&gt;Value()));

	newDocument.SaveFile(&quot;NeuesFile.xml&quot;);

}
void buildTree() {
	TiXmlDocument doc;
	TiXmlDeclaration * decl = new TiXmlDeclaration(&quot;1.0&quot;, &quot;&quot;, &quot;&quot;);
	TiXmlElement * element = new TiXmlElement(&quot;root&quot;);

	doc.LinkEndChild(decl);
	doc.LinkEndChild(element);
	vector&lt;TiXmlElement*&gt; children;
	string name;
	for (int i = 0; i &lt; 3; i++) {
		string s = &quot;child&quot;;
		stringstream out;
		out &lt;&lt; i + 1;
		s += out.str();
		children.push_back(new TiXmlElement(s.c_str()));
		element-&gt;LinkEndChild(children.back());
		string name2;
		for (int j = 0; j &lt; 2; j++) {
			string s2 = &quot;grandchild&quot;;
			stringstream out2;
			out2 &lt;&lt; j + 1;
			s2 += out2.str();
			TiXmlElement* grandchild=new TiXmlElement(s2.c_str());
			children.back()-&gt;LinkEndChild(grandchild);
			grandchild-&gt;LinkEndChild(new TiXmlText(out2.str().c_str()));

		}
	}
	doc.SaveFile(&quot;TestFile.xml&quot;);
}

int main() {

	buildTree();
	appendTree();

	return 0;
}
</code></pre>
<p>vergesst nicht nach dem ausführen von</p>
<pre><code>main()
</code></pre>
<p>F5 zu drücken, sonst werden die neu erstellten xml-files nicht angezeigt!<br />
Danke im vor raus für eure hilfe! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
best regards<br />
blulining</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/264597/tinyxml-triviales-problem</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 13:30:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/264597.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Apr 2010 18:53:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to tinyxml - triviales problem?! on Fri, 09 Apr 2010 18:53:42 GMT]]></title><description><![CDATA[<p>Hallo liebe c++ experten,<br />
ich hab heute schon den ganzen tag mit der suche nach einem problem verbracht,<br />
was auf den ersten blick recht simpel zu sein scheint, aber ich hab überhaupt nichts dazu gefunden - deswegen jetzt hier ein thread dazu:</p>
<p>Die Idee ist folgende: ich hab ein Xml-file beliebiger &quot;Tiefe&quot;.<br />
es interessiert mich eigentlich nicht, wie das Xml-file aufgebaut ist,<br />
sondern ich weiß, dass es &quot;valid&quot; ist und alles andere ist mir egal.</p>
<p>Jetzt möchte ich mit &quot;Tinyxml&quot; , die Xml-datei einlesen und anschließend<br />
alles was sich im &quot;root-element&quot; der datei befindet<br />
( andere knoten,attribute, text etc ...) einfach in einen neuen mit &quot;tinyxml&quot; erstellten element-baum mit</p>
<pre><code>LinkEndChild(...)
</code></pre>
<p>einhängen!</p>
<p>hier mein c++ -code zum testen:</p>
<pre><code>buildTree()
</code></pre>
<p>erzeugt einfach nur das xml-dokument, das später eingehängt werden soll.</p>
<pre><code>appendTree()
</code></pre>
<p>erzeugt einen neuen &quot;baum&quot;, in den dann das rootelement mit inhalt eingehängt werden soll<br />
ich schaffe es bis jetzt nur, das dokument einzulesen und den namen des root-elements einzuhängen,<br />
was muss ich machen, dass alles was im rootelement drin steht eingehängt wird?</p>
<pre><code class="language-cpp">/*
 * Test.cpp
 *
 *  Created on: 09.04.2010
 *      Author: blulining
 */
#include &quot;tinyxml.h&quot;
#include &quot;tinystr.h&quot;

#include &lt;vector&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;
using namespace std;

void appendTree() {
	TiXmlDocument doc;
	doc.LoadFile(&quot;TestFile.xml&quot;);

	doc.Print();
	TiXmlElement* rootElement = doc.RootElement();

	TiXmlDocument newDocument;
	TiXmlDeclaration * decl = new TiXmlDeclaration(&quot;1.0&quot;, &quot;&quot;, &quot;&quot;);
	TiXmlElement * element = new TiXmlElement(&quot;NewRoot&quot;);
	newDocument.LinkEndChild(decl);
	newDocument.LinkEndChild(element);

	element-&gt;LinkEndChild(new TiXmlElement(rootElement-&gt;Value()));

	newDocument.SaveFile(&quot;NeuesFile.xml&quot;);

}
void buildTree() {
	TiXmlDocument doc;
	TiXmlDeclaration * decl = new TiXmlDeclaration(&quot;1.0&quot;, &quot;&quot;, &quot;&quot;);
	TiXmlElement * element = new TiXmlElement(&quot;root&quot;);

	doc.LinkEndChild(decl);
	doc.LinkEndChild(element);
	vector&lt;TiXmlElement*&gt; children;
	string name;
	for (int i = 0; i &lt; 3; i++) {
		string s = &quot;child&quot;;
		stringstream out;
		out &lt;&lt; i + 1;
		s += out.str();
		children.push_back(new TiXmlElement(s.c_str()));
		element-&gt;LinkEndChild(children.back());
		string name2;
		for (int j = 0; j &lt; 2; j++) {
			string s2 = &quot;grandchild&quot;;
			stringstream out2;
			out2 &lt;&lt; j + 1;
			s2 += out2.str();
			TiXmlElement* grandchild=new TiXmlElement(s2.c_str());
			children.back()-&gt;LinkEndChild(grandchild);
			grandchild-&gt;LinkEndChild(new TiXmlText(out2.str().c_str()));

		}
	}
	doc.SaveFile(&quot;TestFile.xml&quot;);
}

int main() {

	buildTree();
	appendTree();

	return 0;
}
</code></pre>
<p>vergesst nicht nach dem ausführen von</p>
<pre><code>main()
</code></pre>
<p>F5 zu drücken, sonst werden die neu erstellten xml-files nicht angezeigt!<br />
Danke im vor raus für eure hilfe! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
best regards<br />
blulining</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1880247</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1880247</guid><dc:creator><![CDATA[blulining]]></dc:creator><pubDate>Fri, 09 Apr 2010 18:53:42 GMT</pubDate></item><item><title><![CDATA[Reply to tinyxml - triviales problem?! on Mon, 12 Apr 2010 09:18:18 GMT]]></title><description><![CDATA[<p>nach ewig viel rumprobieren hab ichs jetz endlich hinbekommen...<br />
so funktionierts:</p>
<pre><code class="language-cpp">void appendTree() {
    TiXmlDocument doc;
    doc.LoadFile(&quot;TestFile.xml&quot;);

    TiXmlElement* rootElement = doc.RootElement();

    TiXmlDocument newDocument;
    TiXmlDeclaration * decl = new TiXmlDeclaration(&quot;1.0&quot;, &quot;&quot;, &quot;&quot;);
    TiXmlElement * element = new TiXmlElement(&quot;NewRoot&quot;);
    newDocument.LinkEndChild(decl);
    newDocument.LinkEndChild(element);
    element-&gt;LinkEndChild(rootElement-&gt;Clone());

    newDocument.SaveFile(&quot;NeuesFile.xml&quot;);
}
</code></pre>
<p>die entscheidende änderung liegt in</p>
<pre><code class="language-cpp">element-&gt;LinkEndChild(rootElement-&gt;Clone());
</code></pre>
<p>ohne das Clone() gibt es immer segmentation-violation fehler etc...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1881431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1881431</guid><dc:creator><![CDATA[blulining]]></dc:creator><pubDate>Mon, 12 Apr 2010 09:18:18 GMT</pubDate></item><item><title><![CDATA[Reply to tinyxml - triviales problem?! on Mon, 25 Oct 2010 14:28:57 GMT]]></title><description><![CDATA[<p>hallo ich habe das gleiche Problem wie der Vorposter nur will ich nicht die ganze Datei kopieren sondern nur die ersten childs in seperate Dateien machen.</p>
<pre><code class="language-cpp">bool chopper::element_to_document(TiXmlElement * element,const char*name)
{
    if(element ==0)
    {
        qDebug()&lt;&lt; element;
        return false ;
    }
    else
    {
        TiXmlDocument * new_doku;
        TiXmlElement * basis = new TiXmlElement(&quot;NewRoot&quot;);
        basis-&gt;LinkEndChild(element);
        if (new_doku-&gt;SaveFile(name))
        {
            return true;
        }
    }
</code></pre>
<p>und der aufruf</p>
<pre><code class="language-cpp">void chopper::make_small_xml(TiXmlDocument doku)
{
//doc.Parse()

    TiXmlHandle docHandle(&amp;doku);
    TiXmlElement* projectElement;
int i = 1;
    projectElement = docHandle.FirstChildElement().Element();
    TiXmlHandle projectHandle(projectElement);
    // ----------------------------------------------------------------------------------------
    for(TiXmlElement* operatorElement = projectHandle.FirstChild(&quot;operator&quot;).ToElement();
                            operatorElement;
                            operatorElement = operatorElement-&gt;NextSiblingElement(&quot;operator&quot;) )
    {
        std::string operator_name;
        if(operatorElement-&gt;Attribute(&quot;name&quot;) != 0)
        {
            operator_name = operatorElement-&gt;Attribute(&quot;name&quot;);
            QString halter = QString::fromStdString(operator_name);
            qDebug()&lt;&lt;&quot;Name:&quot;&lt;&lt; halter;
           if(this-&gt;element_to_document(projectElement,&quot;Test&quot;)==true)
           {
                qDebug()&lt;&lt;&quot;Spalten sollte funktionieren ! &quot;;
           }

        }
</code></pre>
<p>der Fehler ist : Shell_Haddop: tinyXML/tinyxml.cpp:188: TiXmlNode* TiXmlNode::LinkEndChild(TiXmlNode*): Assertion `node-&gt;parent == 0 || node-&gt;parent == this' failed.<br />
Das Programm ist abgestürzt.<br />
ich komme nicht drauf was falsch ist ....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1970398</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1970398</guid><dc:creator><![CDATA[mount &#x2F;dev0]]></dc:creator><pubDate>Mon, 25 Oct 2010 14:28:57 GMT</pubDate></item><item><title><![CDATA[Reply to tinyxml - triviales problem?! on Mon, 25 Oct 2010 18:40:16 GMT]]></title><description><![CDATA[<p>hi mount /dev0,<br />
ich glaub das ist die gleiche fehlermeldung die ich auch hatte damals...<br />
du verwendest nirgends ein Clone() ...<br />
versuch das mal einzubauen, vll gehts dann!<br />
ich würds entweder mal so versuchen:</p>
<pre><code class="language-cpp">else
    {
        TiXmlDocument * new_doku;
        TiXmlElement * basis = new TiXmlElement(&quot;NewRoot&quot;);
        basis-&gt;LinkEndChild(element-&gt;Clone());
        if (new_doku-&gt;SaveFile(name))
        {
            return true;
        }
    }
</code></pre>
<p>oder wenn das nicht funktioniert würd ich das jeweilige element schon in der aufrufmethode clonen....<br />
abgesehen davon willst du doch bestimmt immer den namen des jeweiligen elements als dateinamen oder?<br />
weil hier speicherst du s ja immer unter dem gleichen namen ab (&quot;Test&quot;):</p>
<pre><code class="language-cpp">this-&gt;element_to_document(projectElement,&quot;Test&quot;)
</code></pre>
<p>jepp hoffe das hilft irgendwie weiter... :-?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1970565</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1970565</guid><dc:creator><![CDATA[blulining_not_logged_in]]></dc:creator><pubDate>Mon, 25 Oct 2010 18:40:16 GMT</pubDate></item><item><title><![CDATA[Reply to tinyxml - triviales problem?! on Mon, 25 Oct 2010 20:12:11 GMT]]></title><description><![CDATA[<p>so ich hab mich an das Vorprojekt gehalten, jetzt fehlt noch der Iterator °°</p>
<pre><code class="language-cpp">bool chopper::chopsui(QByteArray name_file,QByteArray name_data)
{
//------------------------------------------------------------------------------
    int i = 1;
    TiXmlDocument doku = this-&gt;load_file(name_file);
    TiXmlElement* rootElement = doku.RootElement()-&gt;FirstChildElement();
    TiXmlHandle docHandle(&amp;doku);
    TiXmlElement * projectElement = docHandle.FirstChildElement().Element();
    TiXmlHandle projectHandle(projectElement);
// HIER SOLLTE DER ITERATOR KOMMEN     

//-----------------------------------------------------------------------------
    TiXmlDocument newDocument;
    TiXmlDeclaration * decl = new TiXmlDeclaration(&quot;1.0&quot;, &quot;&quot;, &quot;&quot;);
    TiXmlElement * element = new TiXmlElement(&quot;project&quot;);
    newDocument.LinkEndChild(decl);
    newDocument.LinkEndChild(element);
    element-&gt;LinkEndChild(rootElement-&gt;Clone());
    QString name = this-&gt;create_name(name_data,i);
    i++;
    qDebug()&lt;&lt;name;
    newDocument.SaveFile(name.toAscii());
// HIER SOLLTE ER AUFHÖREN 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1970623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1970623</guid><dc:creator><![CDATA[mount &#x2F;dev0]]></dc:creator><pubDate>Mon, 25 Oct 2010 20:12:11 GMT</pubDate></item><item><title><![CDATA[Reply to tinyxml - triviales problem?! on Tue, 26 Oct 2010 09:53:12 GMT]]></title><description><![CDATA[<p>final und geht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<pre><code class="language-cpp">bool chopper::chopsui(QByteArray name_file,QByteArray name_data)
{
    int i = 1;
    TiXmlDocument doku = this-&gt;load_file(name_file);
    TiXmlNode * iNode = doku.FirstChild( &quot;project&quot; );
    // =======================================================================================
    if( iNode != NULL )
    {
        for( TiXmlNode * itemNode = iNode-&gt;FirstChild( &quot;operator&quot; ); itemNode != NULL; itemNode = iNode-&gt;IterateChildren( &quot;operator&quot;, itemNode ) )
        {           
           TiXmlDocument newDocument;
           TiXmlDeclaration * decl = new TiXmlDeclaration(&quot;1.0&quot;, &quot;&quot;, &quot;&quot;);
           TiXmlElement * element = new TiXmlElement(&quot;project&quot;);
           newDocument.LinkEndChild(decl);
           newDocument.LinkEndChild(element);
           //element-&gt;LinkEndChild(rootElement-&gt;Clone());
           element-&gt;LinkEndChild(itemNode-&gt;Clone());
           QString name = this-&gt;create_name(name_data,i);
           i++;

           if(newDocument.SaveFile(name.toAscii()))
           {
               return true;
           }
           else
           {
               return false;
           }
        }
    }
    return false;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1970772</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1970772</guid><dc:creator><![CDATA[mount &#x2F;dev0]]></dc:creator><pubDate>Tue, 26 Oct 2010 09:53:12 GMT</pubDate></item></channel></rss>