views:

180

answers:

1

Hello there!

I'm currently working on a C++ MFC project on visual studio 2003. The aim of this project is to be able to take an XML file containing language data, convert it to a simple CSV file and back to XML. To do this, I'm using the TinyXML library, which is simple and good enough for my needs.

The problem is that, once I try to convert my .CSV file to an XML, the created XML cannot be opened again with TinyXML. From what I see now, it seems it cannot open the file it just created.

After some testing, I've been able to make TinyXML tell me its error: "Error #9: Unable to read end tag". If I bypass the error, the file is readable up to a point where the DOM tree indents to the right for no reason and then, a bit later,the file seems to be empty of any element.

This is an erroneous file as read by TinyXML, after having been created by it.

<app>
−
<global>
    <langidglobal1 lang="fr">GLOBAL1</langidglobal1>
    <langidglobal1 lang="en">GLOBAL1</langidglobal1>
    <langidglobal1 lang="ru"/>
    <langidglobal1 lang="de"/>
</global>
−
<mainmenu>
    <system lang="fr">Syst�me</system>
    <system lang="en">System</system>
    <system lang="ru"/>
    <system lang="de"/>
    <motor lang="fr">Moteurs</motor>
    <motor lang="en">Motors</motor>
    <motor lang="ru"/>
    <motor lang="de"/>
    <param lang="fr">Param�tres</param>
    <param lang="en">Parameters</param>
    <param lang="ru"/>
    <param lang="de"/>
    <diag lang="fr">Diagnostique</diag>
    <diag lang="en">Diagnostic</diag>
    <diag lang="ru"/>
    <diag lang="de"/>
    <rod lang="fr">Tiges</rod>
    <rod lang="en">Rods</rod>
    <rod lang="ru"/>
    <rod lang="de"/>
    <aide lang="fr">Aide</aide>
    <aide lang="en">Help</aide>
    <aide lang="ru"/>
    <aide lang="de"/>
    <exit lang="fr">Quitter</exit>
    <exit lang="en">Exit</exit>
    <exit lang="ru"/>
    <exit lang="de"/>
    <runningtools lang="fr">Outils</runningtools>
    <runningtools lang="en">Running Tools</runningtools>
    <runningtools lang="ru"/>
    <runningtools lang="de"/>
    <manualpatterns lang="fr">Patron Manuel</manualpatterns>
    <manualpatterns lang="en">Manual Patterns</manualpatterns>
    <manualpatterns lang="ru"/>
    <manualpatterns lang="de"/>
    <alarm lang="fr">Alarmes Actives</alarm>
    <alarm lang="en">Active Alarms</alarm>
    <alarm lang="ru"/>
    <alarm lang="de"/>
    <patternno lang="fr"># Patron</patternno>
    <patternno lang="en">Pattern #</patternno>
    <patternno lang="ru"/>
    <patternno lang="de"/>
    <lastlogs lang="fr">Derni�res Billes</lastlogs>
    <lastlogs lang="en">Last Logs</lastlogs>
    <lastlogs lang="ru"/>
    <lastlogs lang="de"/>
    <maintenancemode lang="fr">Entretien</maintenancemode>
    <maintenancemode lang="en">Maintenance</maintenancemode>
    <maintenancemode lang="ru"/>
    <maintenancemode lang="de"/>
−
    <toolcustom1 lang="fr"> <!-- Random indentation starts here -->
    Force Entr�e

        <toolcustom1 lang="en">Force Input</toolcustom1>
        <toolcustom1 lang="ru"/>
        <toolcustom1 lang="de"/>
        <toolcustom2 lang="fr">Force Sortie</toolcustom2>
        <toolcustom2 lang="en">Force Output</toolcustom2>
        <toolcustom2 lang="ru"/>
        <toolcustom2 lang="de"/>
        <jogaxis lang="fr">Jog Axes</jogaxis>
        <jogaxis lang="en">Jog Axis</jogaxis>
        <jogaxis lang="ru"/>
        <jogaxis lang="de"/>   <!-- And finishes here -->
    </toolcustom1>
    <toolcustom1 lang="en">Force Input</toolcustom1>
    <toolcustom1 lang="ru"/>
    <toolcustom1 lang="de"/>
</mainmenu>
<menuparam/> <!-- File is empty from here. There should be elements like above. -->
<menudiag/>
<menurod/>
<menuaide/>
<button/>
<progrid/>
<aboutbox/>
<dlgexit/>
<doc/>
<!-- ...like this until... -->
</app>

If I get a pointer on the first element and browse while debugging, this is exactly what TinyXML read with the "LoadFile()" command.

Also note that if I do open the file (the source for the erroneous one above) with Firefox, or wordpad, or anything else, the syntax is correct, and there is no error at all. Everything is here, nothing missing.

I don't suspect my read/write code to be wrong, as when I open/read/write an untouched XML file, everything seems to work as planned.

Now if anyone would have any idea as for why do I get this error, I would be very grateful. The TinyXML support and documentation is somewhat limited and doesn't answer to my problem. I'm staying tuned for answers.

A: 

Well, I've got no replies, but I solved this bug by solving another one. The data I was writing into my XML used encoding tables I was using for whatever reason. By letting TinyXML manage its own encodings, this problem dissapeared on its own.

It's a good thing, there were no apparent cause (even by hex comparing, two ascii characters are exactly the same between two encoding table, so I couldn't realise what caused the problem).

SeargX