hello,
I have the following simple xml file:
<?xml version="1.0" encoding="utf-8" ?>
document -->
<thresholds>
<Thresholder>
<tmin>55.236</tmin>
<tmid>60.254</tmid>
<tmax>130.65</tmax>
</Thresholder>
<ContourSizes>
<tmin>80</tmin>
<tmid>100</tmid>
<tmax>120</tmax>
</ContourSizes>
</thresholds>
All I want is a safe way to retreive the value between tags, for example, if I have the following variable (double dbl=0;) how can in a simple yet safe way assign the value between the tags <tmin> of <Thresholder> to variable dlb.
thanx
ferar
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dave,
yes I read the tutorial if you can name it like that. I really couldn't figure out where this very basic thing (getting values back from the file) is illustruated clearly.The doxygen documentation, is bad no examples or detailed information about the functions are given, seems the Attribute class might do what I seek, yet getting errors casting the nodes to an instance of it. anyways thanx for your kind help.
ferar
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dave's suggestion was sound and the tutorial does cover the information you wanted, I think. Assuming you want to get to the number "55.236", it is a text value of the <tmin> element.
"55.236" is a TiXmlText node, and it's value is a string. There is no way (of course) in TinyXML to convert the value of text to anything. However, your c (and C++) libraries give you serveral functions.
I'm coding without a compiler - dangerous - but I think you want this:
if ( text )
{
float dbl = atoi( text->Value() );
}
Note the final "FirstChild" gets the TiXmlText that is a child of the TiXmlElement. The "Text" is a conversion function that safely converts it to a TiXmlText element.
hope that helps,
lee
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hello,
I have the following simple xml file:
<?xml version="1.0" encoding="utf-8" ?>
document -->
<thresholds>
<Thresholder>
<tmin>55.236</tmin>
<tmid>60.254</tmid>
<tmax>130.65</tmax>
</Thresholder>
<ContourSizes>
<tmin>80</tmin>
<tmid>100</tmid>
<tmax>120</tmax>
</ContourSizes>
</thresholds>
All I want is a safe way to retreive the value between tags, for example, if I have the following variable (double dbl=0;) how can in a simple yet safe way assign the value between the tags <tmin> of <Thresholder> to variable dlb.
thanx
ferar
Hi Ferar
Have you read this tutorial?
http://software.ellerton.net/tinyxml.html
I suggest you follow the examples there and also use the TinyXml documentation.
Also, use a good debugger and inspect the objects as you parse the XML, to find where you are.
David
Dave,
yes I read the tutorial if you can name it like that. I really couldn't figure out where this very basic thing (getting values back from the file) is illustruated clearly.The doxygen documentation, is bad no examples or detailed information about the functions are given, seems the Attribute class might do what I seek, yet getting errors casting the nodes to an instance of it. anyways thanx for your kind help.
ferar
ferar --
Dave's suggestion was sound and the tutorial does cover the information you wanted, I think. Assuming you want to get to the number "55.236", it is a text value of the <tmin> element.
"55.236" is a TiXmlText node, and it's value is a string. There is no way (of course) in TinyXML to convert the value of text to anything. However, your c (and C++) libraries give you serveral functions.
I'm coding without a compiler - dangerous - but I think you want this:
TiXmlHandle docHandle( &document );
TiXmlText* textNode = docHandle.FirstChildElement( "thresholds" ).FirstChildElement( "Thresholder" ).FirstChildElement( "tmin", 1 ).FirstChild().Text();
if ( text )
{
float dbl = atoi( text->Value() );
}
Note the final "FirstChild" gets the TiXmlText that is a child of the TiXmlElement. The "Text" is a conversion function that safely converts it to a TiXmlText element.
hope that helps,
lee
thanks both, and happy thansgivin...