traversing in parsed xml document
Hi to all,
I parsed following xml document using libxml2 parser
<Currentpowersettings>
<PowerScheme>Working</PowerScheme>
<CPUSpeed>Adaptive</CPUSpeed>
<Screensaver>Yes</Screensaver>
<LockScreentime>3</LockScreentime>
<Wbrightvalue>90</Wbrightvalue>
<Ibrightvalue>0</Ibrightvalue>
<Dimtime>3</Dimtime>
<Monitortime>5</Monitortime>
<Standby>5</Standby>
<Hibernatetime>720</Hibernatetime>
<HardDiskTimeout>3</HardDiskTimeout>
<Logofftime>600</Logofftime>
<Shutdowntime>0</Shutdowntime>
<ShutdownFlag>No</ShutdownFlag>
<OpenOfficeFlag>Yes</OpenOfficeFlag>
<DownloadsFlag>Yes</DownloadsFlag>
<PlayersFlag>No</PlayersFlag>
<OutLookFlag>No</OutLookFlag>
<VMWareFlag>No</VMWareFlag>
<PPasswordprotected>No</PPasswordprotected>
</Currentpowersettings>
i got a structure like this :
(just i fetched text contents)
Working
Adaptive
Yes
3
90
0
3
5
600
0
NO
YES
Yes
No
my parsing program is like this:
static void parse(xmlNode * a_node)
{
xmlChar* textcont;
xmlNode *cur_node = NULL;
for (cur_node = a_node; cur_node; cur_node = cur_node->next)
{
if (cur_node->type == XML_ELEMENT_NODE)
;
if (strcmp(cur_node->name,"text") == 0)
{
textcont = xmlNodeGetContent (cur_node);
printf("%s", textcont);
}
parse(cur_node->children);
}
}
the important thing is i have to compare and validate each field. i can do this using lessthan 21 'if' statements. but i have a xml document more than 500 lines. i cant use 500 'if' statements in my program. can anybody suggest me an efficient logic to avoid 'statements'. even i tried with switch-case method, it didnt work.pls suggest any search algorithm to reduce code memory.
|