Robert K. wrote in post #990336:
> On Fri, Apr 1, 2011 at 2:53 AM, Kyle X. <haebooty / yahoo.com> wrote:
>
> It is not entirely clear what you want.  Do you want to look for all
> "ref" instances and find elements they are referring to?  Or do you
> want to do some kind of graph traversal where you start with a
> particular element and follow every ref attribute?

Hi and thank you for your help.  I am sorry if what I wrote was unclear. 
What my goal is is to start at a given location (in this case- 
<IfcWallStandardCase id="i1677">) and eventually grab the three 
IfcLengthMeasure text values, that are associated with this 
<IfcWallStandardCase id="i1677">, and put them into an array.

> If the latter you can for example do a BFS.
>
> 10:11:30 Temp$ ./rx.rb
> --- VISIT:
> <IfcAxis2Placement3D id='i1671'>
>  <Location>
>    <IfcCartesianPoint xsi:nil='true' ref='i1667'/>
>  </Location>
> </IfcAxis2Placement3D>
> --- VISIT:
> <IfcCartesianPoint id='i1667'>
>  <Coordinates exp:cType='list' id='i1670'>
>    <IfcLengthMeasure exp:pos='0'>117.4</IfcLengthMeasure>
>    <IfcLengthMeasure exp:pos='1'>119.7</IfcLengthMeasure>
>    <IfcLengthMeasure exp:pos='2'>0.</IfcLengthMeasure>
>  </Coordinates>
> </IfcCartesianPoint>
> 10:11:43 Temp$ cat -n rx.rb
>      1  #!/bin/env ruby19
>      2
>      3  require 'rexml/document'
>      4
>      5  doc = REXML::Document.new(DATA.read)
>      6
>      7  # BFS
>      8  queue = %w{i1671}
>      9
>     10  until queue.empty?
>     11    id = queue.shift
>     12
>     13    REXML::XPath.each(doc, "//*[@id='#{id}']") do |e|
>     14      puts "--- VISIT:", e
>     15
>     16      REXML::XPath.each(e, './/*[@ref]') do |child|
>     17        next_id = child.attribute('ref') and queue.push(next_id)
>     18      end
>     19    end
>     20  end
>     21
>     22  __END__
>     23  <root xmlns:exp="http://foo" xmlns:xsi="http://bar">
>     24  <IfcWallStandardCase id="i1677">
>     25   <ObjectPlacement>
>     26     <IfcLocalPlacement xsi:nil="true" ref="i1671"/>
>     27   </ObjectPlacement>
>     28  </IfcWallStandardCase>
>     29
>     30  <IfcAxis2Placement3D id="i1671">
>     31   <Location>
>     32     <IfcCartesianPoint xsi:nil="true" ref="i1667"/>
>     33   </Location>
>     34  </IfcAxis2Placement3D>
>     35
>     36  <IfcCartesianPoint id="i1667">
>     37   <Coordinates id="i1670" exp:cType="list">
>     38     <IfcLengthMeasure exp:pos="0">117.4</IfcLengthMeasure>
>     39     <IfcLengthMeasure exp:pos="1">119.7</IfcLengthMeasure>
>     40     <IfcLengthMeasure exp:pos="2">0.</IfcLengthMeasure>
>     41   </Coordinates>
>     42  </IfcCartesianPoint>
>     43  </root>
> 10:11:47 Temp$

I will give this a try.

>
> Kind regards
>
> robert

Dear 7stud.  Using the XPath command:

doc = Document.new xml
target = XPath.match(doc, "//*[@id = 'i1671']")
p target

It produces the following output as you said it would.
--output:--
[<IfcAxis2Placement3D id='i1671'> ... </>]

But I cannot figure out how to do anything with this from here to get to 
the next point, and eventually be able to grab the three values.

-- 
Posted via http://www.ruby-forum.com/.