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?!?!?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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");
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2004-08-03
can you be more accurate with code i have to put in instead
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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?!?!?
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;
}
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");
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
can you be more accurate with code i have to put in instead
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");
now i have the value of ref in atribute variable?
how can i use CreateProcess to start playing that file with media player?
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