LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Closed Thread
  Search this Thread
Old 07-16-2009, 02:31 AM   #1
naveenisback
Member
 
Registered: Jun 2009
Posts: 80
Blog Entries: 1

Rep: Reputation: 16
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.
 
Old 07-16-2009, 02:36 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
traversing in parsed xml document naveenisback Programming 1 07-16-2009 08:59 AM
how to create an html object from an XML document mohtasham1983 Programming 2 12-20-2007 02:58 AM
Including document in XML-file that uses CSS ronald-be Linux - Desktop 1 01-13-2007 06:48 PM
Help!Write xml document with shell scripts wmh830621 Programming 4 08-11-2006 04:55 AM
Reading a xml document: amirspl Programming 3 09-10-2003 07:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration