struct ShelfInfo
{
int port;
int addslot[5];
};
ShelfInfo g_shelfinfo[5] = {0};
int example_3()
{
static const char* xml =
"<?xml version=\"1.0\"?>"
"<!DOCTYPE PLAY SYSTEM \"play.dtd\">"
"<PLAY>2"
"<PORT>1"
"<SLOT>3</SLOT>"
"<SLOT>4</SLOT>"
"<SLOT>5</SLOT>"
"</PORT>"
"<PORT>4"
"<SLOT>6</SLOT>"
"<SLOT>7</SLOT>"
"<SLOT>8</SLOT>"
"</PORT>"
"</PLAY>";
XMLDocument doc;
doc.Parse( xml );
XMLElement* playElement = doc.FirstChildElement( "PLAY" );
const char* play = playElement->GetText();
printf( "Value of play (1): %s\n", play );
XMLText* textNode = playElement->FirstChild()->ToText();
const char* portNode = textNode->Value();
printf( "Value of play (2): %s\n", portNode );
XMLElement* tempElement = doc.FirstChildElement( "PLAY")->FirstChildElement( "PORT" );
XMLElement* tempiElement = doc.FirstChildElement( "PLAY")->FirstChildElement( "PORT" )->FirstChildElement( "SLOT" );
for (int i = 0; i< atoi(play); i++)
{
if(tempElement != NULL)
{
const char* temp = tempElement->GetText();
g_shelfinfo[i].port = atoi(temp);
printf( "tempnode : %s\n", temp );
tempiElement = tempElement->FirstChildElement( "SLOT" );
for(int j = 0; j < 3; j++)
{
if(tempiElement != NULL)
{
const char* tempi = tempiElement->GetText();
printf(" %s ", tempi);
g_shelfinfo[i].addslot[j] = atoi(tempi);
tempiElement = tempiElement->NextSiblingElement();
}
}
printf( "=======\n");
tempElement = tempElement->NextSiblingElement();
//printf("tempElement->getText = %s\n",tempiElement->GetText());
}
}
return doc.ErrorID();
}
struct ShelfInfo g_C2[]=
{
{1,{3,4,5}},
{2,{7,8,9}},
};
int main()
{
example_3();
printf("mytest g_shelfinfo = %d\n",g_shelfinfo[1].addslot[1]);
system("pause");
return 0;
}