Hi

I am currently loading xml from files and all is working fine. The code is as follows (only the logic part. there is error handling as well):

bool Utils::GetRootElement( const char* xmlFileName, TiXmlElement** element )
{
    TiXmlDocument xmlDoc( xmlFileName );
    bool res = xmlDoc.LoadFile();

    if( res )
    {
        *element = (TiXmlElement*)xmlDoc.RootElement()->Clone();
        return true;
    }
}

Now I need to read the xml from a string. I do the following:

bool Utils::GetRootElementFromString( const char* sXmlString, TiXmlElement** element )
{
    TiXmlDocument xmlDoc;
    const char* res = xmlDoc.Parse(sXmlString, 0, TIXML_ENCODING_UTF8);

    if( res == NULL )
    {
    *element = (TiXmlElement*)xmlDoc.RootElement()->Clone();
    return true;
    }
}

RootElement is created badly

What am I doing wrong?

 
Last edit: haber5 2013-05-23