LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-16-2009, 02:26 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





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. any search algorithm to reduce code memory.
 
Old 07-16-2009, 08:59 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
I would create something like a template (either in code or read from a file) and compare the content of the template with the xml file that you have parsed.

I'm not familiar with libxml, if your result is in an hashed array and your template as well you can do something like in below (some kind of just invented pseudo code)
Code:
set fail false
foreach element in template
{
    if {data[element]!=template[element]} {
        set fail true
    }
}
return fail

Last edited by Wim Sturkenboom; 07-16-2009 at 09:01 AM.
 
  


Reply



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
Including document in XML-file that uses CSS ronald-be Linux - Desktop 1 01-13-2007 06:48 PM
Including document in XML-file that uses CSS ronald-be Linux - Desktop 0 01-13-2007 11:46 AM
XSLT transformation of XML document using XMLNS Foomajick Programming 7 10-25-2006 05:27 AM
how to use shell scripts process xml document? wmh830621 Programming 4 08-03-2006 11:13 PM
Reading a xml document: amirspl Programming 3 09-10-2003 07:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:08 PM.

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