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" />
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 ?
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();
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