Brian Cowdery wrote:
> Recently at work we've decided to attempt to build a basic XML driven 
> automation framework to work with Watir (a web development testing 
> library for ruby).
>
> I cant figure out how to loop through each level of the REXML document 
> to extract the data needed to build the complete object.
>
> It seems that if i try to use any iterators on a root.elements[] object 
> it converts it to text so i can't nest another iterator or loop to 
> access the innards.
>
> my only recourse has been to resort to a ton of nested while loops which 
> is ugly when compared to most other ruby loops.
>
> eg.
> i = 1
> while root.elements['cases'].elements[i] != nil
>
>  n = 1
>  while root.elements['cases'].elements['test-case'] != nil
>
>    #more loops here. continue down the chain until i can build the
>    #object from the inside out.
>
>  i = i+i
>  end
>
> i = i+i
> end
>
>
>
> my xml looks like this
> <script>
> <project-name></project-name>
> <start-url></start-url>
>
>  <test-case id="1">
>   <test-step id="1">
>    <test>
>     <interaction>double click</interaction>
>     <element>
>      <name>button 1</type>
>      <type>button</type>
>     <element>
>    </test>
>    <check>
>     <element>
>      <name>Page title</type>
>      <type>text</type>
>     <element>
>    </check>
>   </test-step>
>
>   <test-step id="2">
>     ...
>   </test-step>
>  </test-case>
>
>  <test-case id="2">
>   ...
>  </test-case>
> </script>
>
> somehow i have to get THAT modeled into an object
> script object contains test-cases, test-cases contain test-steps etc....
>
> Any thoughts? (sorry for the long post... its kinda hard to explain 
> without showing EVERYTHING.
>   
Hi Brian,

Have you given any thought to using YAML instead of  XML?

If you're comfortable with a data format that's a little less 
self-descriptive than XML, you may find that YAML's ease of use could 
work for you.  It's pretty nice to load up your YAML and have all of 
your Ruby objects pieced together for you.  I can send you a small 
example if you'd like.

Regards,
Matthew