Menu

Please help

2005-08-08
2013-05-20
  • Vincent Richomme

    Hi,

    I am trying to parse the following :
    <?xml version="1.0" ?>
    <resource version="0.1">
        <object class="CView" name="Default">
            <background fillmode="normal" LowColor="0x000000" HiColor="0x000000" />
           
            <object class="Static" name="ID_STATIC_1000">
                <id>1000</id>
                <pos>1,361</pos>
                <size>100,40</size>
                <bg fillmode="0" LowColor="0xc8d0d4" HiColor="0xc8d0d4" />
            </object>
            <object class="Static" name="ID_STATIC_1001">
                <id>1001</id>
                <pos>245,519</pos>
                <size>100,40</size>
                <bg fillmode="0" LowColor="0xcdcdcdcd" HiColor="0xcdcdcdcd" />
            </object>
        </object>
    </resource>

    So I am trying this :
    // Load Xml
        bool bRet = doc.LoadFile( CMisc::GetAppPath() + _T("Borne.xui") );
        if (!bRet)
            return;

        // Go directly to  <object> section
        TiXmlHandle docHandle( &doc );
        TiXmlHandle resHandle = docHandle.
            FirstChild( _T("resource") ).
            FirstChild( _T("object") ).
            FirstChild( _T("object") );

        pXMLElement = resHandle.Element();
        while( pXMLElement ){
            CGUIElement* NewWidget = NULL;
           
            if( _tcsicmp(pXMLElement->Attribute( _T("class") ), "Static") == 0)
                NewWidget = new CGUIStatic( );
            //else if( _tcsicmp(pXMLElement->Attribute( _T("class") ), "Picture") == 0)
            //    NewWidget = new CGUIPicture( );

            // Go deeper
            pXMLElement = pXMLElement->FirstChild()->ToElement();
           
            while( pXMLElement ){

            strTmp = pXMLElement->Value();
            if( _tcsicmp(pXMLElement->Value(), _T("id"))  == 0){

                strTmp = pXMLElement->ToText()->Value(); // EXCEPTION ???

            }
           
            pXMLElement = pXMLElement->NextSiblingElement();
        }
            // move to the next control
            pXMLElement = pXMLElement->NextSiblingElement("object");
        }

    The problem is to get text from <id>, <pos>, ...

    I always have a NULL pointer everytime i call ToText() to get the id text for instance while I am sure there is some text.

    What am I doing wrong ?

     
    • Vincent Richomme

      even when I try this simple thing it fais :

      // Load Xml
          bool bRet = doc.LoadFile( CMisc::GetAppPath() + _T("Borne.xui") );
          if (!bRet)
              return;

          // Go directly to  <object> section
          TiXmlHandle docHandle( &doc );
          TiXmlHandle resHandle = docHandle.
              FirstChild( _T("resource") ).
              FirstChild( _T("object") ).
              FirstChild( _T("object") ).
              FirstChild( _T("id") );

          pXMLElement = resHandle.Element();
          TRACE( _T("<%s>\n"), pXMLElement->Value() );
          strTmp = pXMLElement->ToText()->Value();

       
      • Yves Berquin

        Yves Berquin - 2005-08-08

        Vincent,
        You are missing one point at the end.
        A text node is a child of an element.
        So you need to write
        strTmp=pXMLElement->FirstChild()->ToText()->Value()

        But you'd better put some code to ensure there's a text child.

        Yves

         

Log in to post a comment.