Menu

Single and Double Quotes issue - bug?

Developer
2005-10-19
2013-05-20
  • Mateusz Loskot

    Mateusz Loskot - 2005-10-19

    Hi,

    I'm using TinyXML in my application to save/open project file based on XML format.
    I opened it and then save with new filename without any changes to the XML tree.
    And as you can see below, some element in new file gets different format than in original.

    Here is XML element <COORSYS> from original file:

    <COORDSYS string="GEOGCS[&quot;GCS_WGS_1984&quot;,DATUM[&quot;WGS84&quot;,SPHEROID[&quot;WGS84&quot;,6378137,298.257223563]],PRIMEM[&quot;Greenwich&quot;,0],UNIT[&quot;Degree&quot;,0.0174532925199433]]"/>

    but this is after TinyXML save XML tree (with <COORDSYS> to file:

    <COORDSYS string='GEOGCS[&quot;GCS_WGS_1984&quot;,DATUM[&quot;WGS84&quot;,SPHEROID[&quot;WGS84&quot;,6378137,298.257223563]],PRIMEM[&quot;Greenwich&quot;,0],UNIT[&quot;Degree&quot;,0.0174532925199433]]' />

    Please, note the difference in quotes.
    The new version of <COORDSYS> gets single quotes around the attribute string. That's incorrect.

    So, is this a bug in TinyXML?
    I need it working a bit urgently, so please give me some guidelines how can I fix it.

    Thanks in advance.
    Cheers

     
    • Ellers

      Ellers - 2005-10-19

      No, thats not right, as far as I know and from doing some googling.

      Both attrib="double" and attrib='single' quotes are acceptable.

      If you have some need to have double quotes then the simplest solution is edit the source yourself.

      But there is no XML-specific reason why that would be needed, AFAIK.

      Off topic but I think it would be better to reorganise your XML a bit, e.g.
      <COORDSYS>GEOGCS...</COORDSYS>

      or even
      <COORDSYS><GEOGCS>WGS_1984</GEOGCS>...</COORDSYS>

       
    • Mateusz Loskot

      Mateusz Loskot - 2005-10-19

      1. I agree. XML supports double and single quotes. So I will try to find some solution.

      2. Yes, I'd like to use such prettier structure for the <COORDSYS> but unfortunately I can't. This XML format is  defined by ESRI company as ArcXML specification.
      So, I have to stick to their guidelines.
      The only thing I have to do is to figure out why ESRI's software does not support single quotes for attribute value as XML supports.

      Thanks

       
    • Ellers

      Ellers - 2005-10-19

      Ah, I have vague recollections of ESRI from years ago.

      Its bound to be that they have a limited parser that they wrote themselves, thats all.

      In this case it may warrant just hacking tinyxml a bit to get it to write out with the quote style you want.

       
    • Mateusz Loskot

      Mateusz Loskot - 2005-10-21

      Hi,
      After a short investigation I revealed that &quot; entity in attribute value is found as double-quote (") character only when compiling TinyXML in non-STL mode. But when I turn STL support on, then &quot; entity seems to be preserved as is with no "conversion" to double-quote character. So, in STL mode everything works fine for me.
      Here are my very simple changes I put to TinyXML in order to force TinyXML will act as I wish:

      void TiXmlAttribute::Print( FILE* cfile, int /*depth*/ ) const
      {
         TIXML_STRING n, v;

         PutString( name, &n );
         PutString( value, &v );

         if (value.find ('\&quot;') == TIXML_STRING::npos)
         {
            fprintf (cfile, "%s=\&quot;%s\&quot;", n.c_str(), v.c_str() );
         }
            else
         {
      #ifdef TIXML_USE_STL
            fprintf (cfile, "%s=\&quot;%s\&quot;", n.c_str(), v.c_str());
      #else
            fprintf (cfile, "%s=\'%s\'", n.c_str(), v.c_str() );
      #endif
         }
      }

      Cheers
      Mateusz

       

Log in to post a comment.