Madam has asked for the wisdom of the Perl Monks concerning the following question:
This is the xml which i have taken and it is just an example and it is simliar to the one which i am using.i have an executable by name 'recipe'. so if i run 'recipe -name Chocolate Chip Bars" it will select the recipe name "Chocolate Chip Bars" and its contents. or if i specify 'recipe -name chocolate cake' it will select the recipe name "chocolate cake " and its contents. To select the proper contents, In the command line, i will specify 'recipe -name Chocolate Chip Bars -use "vanilla"',then it should select 'step name=combine with brown sugar and vanilla in large mixing bowl' and if i specify 'recipe -name Chocolate Chip Bars -use "vanilla,nuts",then it should select 'step name=combine with brown sugar and vanilla,nuts in large mixing bowl '.this is where i am facing the problem.what is the best way to select the "dependency" depending on the specification from the command line. my code:<?xml version="1.0" encoding="ISO-8859-1" ?> - <recipe name= "Chocolate Chip Bars"> <optional>vanilla,mango,nuts</optional> <step name="Preheat oven to 350 degrees"/> <step name="Melt butter" /> <step name="combine with brown sugar and vanilla in large mixing bow +l"> <dependency use="vanilla"/> </step> <step name="combine with brown sugar and vanilla,nuts in large mixi +ng bowl"> <dependency use="vanilla,nuts,!mango"/> </step> <step name="combine with brown sugar and mango in large mixing bowl +"> <dependency use="mango,!vanilla,!nuts"/> </step> ... </recipe> <recipe name="chocolate cake"> ....
my $parser = XML::LibXML->new(); my $recipeDoc = $parser->parse_file("recipe.xml"); foreach my $recipe ($recipeDoc->getElementsByTagName("recipe")) { $recipeName = $recipe->getAttribute("name"); foreach my $step ($recipe->getElementsByTagName("step")) { foreach my $dep ($step->getElementsByTagName("dependency")) { if($dep->hasAttribute("use") { # this is where i am struck. # here i have to get value from the command line ( and i know ho +w to get the information from command line) and match it with the dep +endency value. (the issue is with matching it with the dependency val +ue after getting the values from command line) } $stepName = $step->getAttribute("name"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parsing xml file using LIBXML
by mirod (Canon) on May 12, 2005 at 08:18 UTC | |
by Tanktalus (Canon) on May 12, 2005 at 21:12 UTC | |
by mirod (Canon) on May 13, 2005 at 04:08 UTC | |
|
Re: parsing xml file using LIBXML
by dakkar (Hermit) on May 12, 2005 at 12:57 UTC |