Menu

newbie question

Anonymous
2004-08-03
2004-08-04
  • Anonymous

    Anonymous - 2004-08-03

    i have XML file like this
    <?xml version="1.0" encoding="UTF-8">
    <declarations>
        <item id="track04">
            <component>
                <resource ref="track04.mp3">
            </component>
        </item>
    </declaration>

    and i want to put in variable value of resource element of ref atribute.
    can someone help me?!?!?

     
    • Yves Berquin

      Yves Berquin - 2004-08-03

      First of all, you have 3 syntax errors in your XML file !

      Here is a corrected version :

      <?xml version="1.0" encoding="UTF-8"?>
      <declarations>
         <item id="track04">
            <component>
               <resource ref="track04.mp3" />
            </component>
         </item>
      </declarations>

      You need to close all items carefully :
      - <?xml ... need to be closed by ?>
      - <declarations> need to be closed by </declarations> with a 's'
      - <resource> need to be closed by a '/' as there is no child

      When you solve all this, you can use the following  (assuming your project defines TIXML_USE_STL

      #include "tinyxml.h"

      int main ()
      {
         TiXmlDocument doc;
         doc . LoadFile ("sample.xml");

         TiXmlHandle docHandle (&doc);
         TiXmlElement * child;

         child = docHandle . FirstChild ("declarations")
                      . FirstChild ("item")
                      . FirstChild ("component")
                      . FirstChild ("resource")
                      . Element();
         if ( child )
         {
            std::string attribute = child -> Attribute ("ref");
            // .. do something with attribute
         }
         return 0;
      }

       
    • Anonymous

      Anonymous - 2004-08-03

      OKEY i fixed my XML code.
      but i'm doing this on PocketPC, and i'm getting error on:
      std::string attribute = child -> Attribute ("ref");

       
      • Yves Berquin

        Yves Berquin - 2004-08-03

        I guess you don't have proper STL support.
        In this case, you can get rid of that line and process
        child -> Attribute ("ref") as a const char *
        You must also undefine the TIXML_USE_STL in your project

         
    • Anonymous

      Anonymous - 2004-08-03

      can you be more accurate with code i have to put in instead

       
      • Yves Berquin

        Yves Berquin - 2004-08-03

        1. You do not define TIXML_USE_STL for your project anymore.
        2. You change the line

        std::string attribute = child -> Attribute ("ref");

        by

        const char * attribute = child -> Attribute ("ref");

         
    • Anonymous

      Anonymous - 2004-08-04

      now i have the value of ref in atribute variable?

      how can i use CreateProcess to start playing that file with media player?

       
    • Ellers

      Ellers - 2004-08-04

      windows ... you may be able to avoid calling CreateProcess() by instead using ShellExecute()/ShellExecuteEx(). This will do the same thing as if the user double clicked on the file.

      eg from MSDN:

      ShellExecute(handle, NULL, "music.mp3", NULL, NULL, SW_SHOWNORMAL);

      HTH

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.