Menu

simple way get value between tags?

feraradam
2005-10-10
2013-05-20
  • feraradam

    feraradam - 2005-10-10

    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

     
    • DavidA

      DavidA - 2005-10-10

      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

       
    • feraradam

      feraradam - 2005-10-10

      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

       
    • Lee Thomason

      Lee Thomason - 2005-10-10

      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

       
    • feraradam

      feraradam - 2005-10-10

      thanks both, and happy thansgivin...

       

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.