tinyxml2 icon indicating copy to clipboard operation
tinyxml2 copied to clipboard

Porting from tinyxml to tinyxml2

Open renu555 opened this issue 8 years ago • 10 comments

In Tinyxml creating a declaration was like : TiXmlDeclaration xmlDecl = new TiXmlDeclaration("1.0", "UTF-8", ""); But in Tinyxml2 it requires to create a document first tinyxml2::XMLDeclaration decl = doc.NewDeclaration(); decl->SetValue("xml version="1.0" encoding=""");

In tinyxml2, Do I need to do InsertEndChild after creating a new declaration?

renu555 avatar Dec 03 '15 07:12 renu555

Yes, you do. The declaration will not be added to the document structure until you add it explicitly. The test project contains an example (search for NewDeclaration() call).

Dmitry-Me avatar Dec 03 '15 07:12 Dmitry-Me

Thanks. While porting to tinyxml2, apart from changes of namespace and class name, if there is possibility of more changes like these , I think a porting document can be helpful.

renu555 avatar Dec 03 '15 08:12 renu555

Since I am porting my application to tinyxml2, I can work on this ,if you think it can be helpful to others. @Dmitry

renu555 avatar Dec 03 '15 13:12 renu555

Well, I cannot comment on this, I never saw any code for earlier tinyxml. Perhaps @leethomason has some ideas.

Dmitry-Me avatar Dec 03 '15 14:12 Dmitry-Me

It's been so long since I ported over...I've sort of forgotten the stumbling blocks. Should have documented it then.

I would like to address some issues in the Readme: the TinyXML-1 vs. 2 part is pretty outdated (there is no reason to use TinyXML-1 any more.) If you had a brief list of porting notes, it could go in the readme, and replace much of the existing 1 vs. 2 discussion.

leethomason avatar Dec 04 '15 20:12 leethomason

Also a good issue to remember to more aggressively deprecate TinyXML-1. That version should be fully retired.

leethomason avatar Mar 30 '16 23:03 leethomason

I'm doing this now :-(

Most of it seems pretty straightforward - xDoc.NewXYZ instead of new XYZ. ToElement() instead of Element(), create a XMLPrinter to export an object to text, etc.

The stumbling blocks come with the lack of Clone(), and the missing index parameters on Child().

The big warning is that XMLDocument.Parse returns the opposite of what it used to - 0 is now good, 0 in tinyXML1 was bad.

gbjbaanb avatar Jul 20 '16 07:07 gbjbaanb

Clone() is problematic; although writing a DeepClone() is on the list. (But still doesn't work quite the same.)

The Child() index is (of course) fixable - it's just such a performance stumbling block.

And Parse()...yeah. Sorry about that. But didn't want to keep persisting the irregularity.

leethomason avatar Jul 20 '16 18:07 leethomason

It was said earlier: --Since I am porting my application to tinyxml2, I can work on this ,if you think it can be helpful to others. @dmitry --Well, I cannot comment on this, I never saw any code for earlier tinyxml. Perhaps @leethomason has some ideas.

I would very much appreciate a porting guide. I am struggling with the various API changes, such as XMLDeclaration. At the very least I think that there should be a prominent statement that there are significant API differences - it is not a drop-in replacement.

marlowa avatar Apr 01 '22 08:04 marlowa

I came here looking for an answer to the XMLDeclaration question, but since there isn't one:

    XMLDocument doc;
    XMLDeclaration* decl = doc.NewDeclaration();
    doc.LinkEndChild(decl);

parsley72 avatar Oct 19 '22 08:10 parsley72