Can you search in REXML by attributes?

K

Kyle X.

Hello and thank you to all the wonderful and helpful people at this
forum. I am trying to figure out how to search through an XML file and
grab information. I have been reading the REXML tutorials but could not
see an answer to my problem in them
(http://www.germane-software.com/software/rexml/docs/tutorial.html).
The problem is I need to search by an attribute (in this case the ref)
and cannot figure out how. Here is a snippet of the XML I am trying to
extract information from:

<IfcWallStandardCase id="i1677">
<ObjectPlacement>
<IfcLocalPlacement xsi:nil="true" ref="i1671"/>
</ObjectPlacement>
</IfcWallStandardCase>

<IfcAxis2Placement3D id="i1671">
<Location>
<IfcCartesianPoint xsi:nil="true" ref="i1667"/>
</Location>
</IfcAxis2Placement3D>

<IfcCartesianPoint id="i1667">
<Coordinates id="i1670" exp:cType="list">
<IfcLengthMeasure exp:pos="0">117.4</IfcLengthMeasure>
<IfcLengthMeasure exp:pos="1">119.7</IfcLengthMeasure>
<IfcLengthMeasure exp:pos="2">0.</IfcLengthMeasure>
</Coordinates>
</IfcCartesianPoint>

So basically I have to start with IfcWallStandardCase and from there
work my way through the "ref"'s until I get to the 3 IfcLengthMeasures.
I know how to grab the first ref "i1671" using:
XPath.match(doc,"/IfcWallStandardCase/ObjectPlacement/IfcLocalPlacement")
and some additional code.

My problem is I cannot figure out how to use this "i1671" to search the
xml and grab the next ref. This ref is the only thing linking the items
together, so it is the only thing that I can use.

Is it possible to search a document by using an attribute, and if so
how? In this case to use the ref, "i1671" to search the document for
where it is used as id="i1671" so I can grab the next ref from there and
so on. Any help would be greatly appreciated.

Thank you all.

Sincerely,
Kyle
 
7

7stud --

I think this is the XPath for the elements you want:

//IfcLengthMeasure[@id = 'i1671']

...whether REXML fully supports XPath is another question. Try it and
see if it works.
 
7

7stud --

...the xpath:

//*[@id = 'i1671']

finds all tags with an id attribute whose value is 'i1671'. You might
want to check out an XPath tutorial to get specifics on XPath, e.g.:

http://www.w3schools.com/xpath/xpath_syntax.asp

However, it doesn't necessarily mean that REXML will support the
particular xpath feature you try.
 
K

Kyle X.

Robert K. wrote in post #990336:
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
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.
 
K

Kyle X.

t
#990433:
I usually use Nokogiri to handle XML documents, and find css selectors
easier than XPath. I'd do it like this:

doc =3D Nokogiri::XML(<<END
<root xmlns:exp=3D"http://foo" xmlns:xsi=3D"http://bar">
<IfcWallStandardCase id=3D"i1677">
<ObjectPlacement>
<IfcLocalPlacement xsi:nil=3D"true" ref=3D"i1671"/>
</ObjectPlacement>
</IfcWallStandardCase>

<IfcAxis2Placement3D id=3D"i1671">
<Location>
<IfcCartesianPoint xsi:nil=3D"true" ref=3D"i1667"/>
</Location>
</IfcAxis2Placement3D>

<IfcCartesianPoint id=3D"i1667">
<Coordinates id=3D"i1670" exp:cType=3D"list">
<IfcLengthMeasure exp:pos=3D"0">117.4</IfcLengthMeasure>
<IfcLengthMeasure exp:pos=3D"1">119.7</IfcLengthMeasure>
<IfcLengthMeasure exp:pos=3D"2">0.</IfcLengthMeasure>
</Coordinates>
</IfcCartesianPoint>
</root>
END
)

reference =3D doc.css("#i1671 Location
IfcCartesianPoint").attribute("ref").value
doc.css("##{reference} Coordinates IfcLengthMeasure").map {|element|
element.text}

This returns: =3D> ["117.4", "119.7", "0."]

Thank you for the help. I had been using REXML and it was working find
with one exception, it can be very slow. So now I am trying to use
Nokogiri, and am running into a very simple error, I cannot load xml
files. From the Nokogiri website I have been trying what is in their
tutorial:
f =3D File.open("blossom.xml")
doc =3D Nokogiri::XML(f)
f.close

But regardles of what I put in the ("...") it returns -
Error: #<Errno::EINVAL: C:/Program Files (x86)/Google/Google SketchUp
8/Plugins/examples/auto.rb:11:in `read': Invalid argument -
c:eek:urwalls.xml>
or
Error: #<Errno::ENOENT: C:/Program Files (x86)/Google/Google SketchUp
8/Plugins/examples/auto.rb:11:in `read': No such file or directory -
fourwalls.xml>

If I am simply trying to open an XML file named file.xml located at C:\,
what would I put to open it? I have tried many things such as f
=3DFile.open("C:\file.xml") and what not with no luck. What do I need to=

do to open this?

-- =

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

Kyle X.

Kyle X. wrote in post #992033:
#990433:

I usually use Nokogiri to handle XML documents, and find css selectors=
easier than XPath. I'd do it like this:

doc =3D Nokogiri::XML(<<END
<root xmlns:exp=3D"http://foo" xmlns:xsi=3D"http://bar">
<IfcWallStandardCase id=3D"i1677">
<ObjectPlacement>
<IfcLocalPlacement xsi:nil=3D"true" ref=3D"i1671"/>
</ObjectPlacement>
</IfcWallStandardCase>

<IfcAxis2Placement3D id=3D"i1671">
<Location>
<IfcCartesianPoint xsi:nil=3D"true" ref=3D"i1667"/>
</Location>
</IfcAxis2Placement3D>

<IfcCartesianPoint id=3D"i1667">
<Coordinates id=3D"i1670" exp:cType=3D"list">
<IfcLengthMeasure exp:pos=3D"0">117.4</IfcLengthMeasure>
<IfcLengthMeasure exp:pos=3D"1">119.7</IfcLengthMeasure>
<IfcLengthMeasure exp:pos=3D"2">0.</IfcLengthMeasure>
</Coordinates>
</IfcCartesianPoint>
</root>
END
)

reference =3D doc.css("#i1671 Location
IfcCartesianPoint").attribute("ref").value
doc.css("##{reference} Coordinates IfcLengthMeasure").map {|element|
element.text}

This returns: =3D> ["117.4", "119.7", "0."]

Please disregard the previous post. I figured out how to load the
files, but it does not appear to be reading correctly.

Using-
fname =3D File.open("C:/Users/Kyle/Desktop/CSUF/Research Winter
11/IFXCML/automation trials/one.xml")
$doc =3D Nokogiri::XML(fname)
reference =3D $doc.css(" IfcCartesianPoint Coordinates
IfcLengthMeasure").first

This produce and output of nil when it should be "117.4" correct? What
is going wrong here?

-- =

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

Jesús Gabriel y Galán

Kyle X. wrote in post #992033:
Jes=FAs Gabriel y Gal=E1n said:
I usually use Nokogiri to handle XML documents, and find css selectors
easier than XPath. I'd do it like this:

doc =3D Nokogiri::XML(<<END
<root xmlns:exp=3D"http://foo" xmlns:xsi=3D"http://bar">
<IfcWallStandardCase id=3D"i1677">
=A0<ObjectPlacement>
=A0 =A0<IfcLocalPlacement xsi:nil=3D"true" ref=3D"i1671"/>
=A0</ObjectPlacement>
</IfcWallStandardCase>

<IfcAxis2Placement3D id=3D"i1671">
=A0<Location>
=A0 =A0<IfcCartesianPoint xsi:nil=3D"true" ref=3D"i1667"/>
=A0</Location>
</IfcAxis2Placement3D>

<IfcCartesianPoint id=3D"i1667">
=A0<Coordinates id=3D"i1670" exp:cType=3D"list">
=A0 =A0<IfcLengthMeasure exp:pos=3D"0">117.4</IfcLengthMeasure>
=A0 =A0<IfcLengthMeasure exp:pos=3D"1">119.7</IfcLengthMeasure>
=A0 =A0<IfcLengthMeasure exp:pos=3D"2">0.</IfcLengthMeasure>
=A0</Coordinates>
</IfcCartesianPoint>
</root>
END
)

reference =3D doc.css("#i1671 Location
IfcCartesianPoint").attribute("ref").value
doc.css("##{reference} Coordinates IfcLengthMeasure").map {|element|
element.text}

This returns: =3D> ["117.4", "119.7", "0."]

Please disregard the previous post. =A0I figured out how to load the
files, but it does not appear to be reading correctly.

Using-
fname =3D File.open("C:/Users/Kyle/Desktop/CSUF/Research Winter
11/IFXCML/automation trials/one.xml")
$doc =3D Nokogiri::XML(fname)
reference =3D $doc.css(" IfcCartesianPoint Coordinates
IfcLengthMeasure").first

This produce and output of nil when it should be "117.4" correct? =A0What
is going wrong here?

This works for me:

$ cat noko.rb && ruby -rubygems noko.rb
require 'nokogiri'

doc =3D Nokogiri::XML(File.read("one.xml"))
reference =3D doc.css("IfcCartesianPoint Coordinates IfcLengthMeasure").fir=
st
puts reference.text

117.4

But if I leave a space before IfcCartesianPoint in the call to the css
method I get a parser error (`on_error': unexpected ' ' after ''
(Nokogiri::CSS::SyntaxError)). This is my file one.xml:

<root xmlns:exp=3D"http://foo" xmlns:xsi=3D"http://bar">
<IfcWallStandardCase id=3D"i1677">
<ObjectPlacement>
<IfcLocalPlacement xsi:nil=3D"true" ref=3D"i1671"/>
</ObjectPlacement>
</IfcWallStandardCase>

<IfcAxis2Placement3D id=3D"i1671">
<Location>
<IfcCartesianPoint xsi:nil=3D"true" ref=3D"i1667"/>
</Location>
</IfcAxis2Placement3D>

<IfcCartesianPoint id=3D"i1667">
<Coordinates id=3D"i1670" exp:cType=3D"list">
<IfcLengthMeasure exp:pos=3D"0">117.4</IfcLengthMeasure>
<IfcLengthMeasure exp:pos=3D"1">119.7</IfcLengthMeasure>
<IfcLengthMeasure exp:pos=3D"2">0.</IfcLengthMeasure>
</Coordinates>
</IfcCartesianPoint>
</root>

This works too:

doc.css("IfcCartesianPoint Coordinates IfcLengthMeasure").each {|el|
puts el.text}

Produces:

117.4
119.7
0.

Maybe it's the way you are passing the file to Nokogiri::XML? By the
way, in your way you are not closing the file handler. If you want to
pass Nokogiri the file instead of reading it yourself you can do:

doc =3D nil
File.open("one.xml") {|f| doc =3D Nokogiri::XML(f)}

or

doc =3D File.open("one.xml") {|f| Nokogiri::XML(f)}

This way, the file is properly closed.

Jesus.
 
K

Kyle X.

This works for me:
$ cat noko.rb && ruby -rubygems noko.rb
require 'nokogiri'

doc = Nokogiri::XML(File.read("one.xml"))
reference = doc.css("IfcCartesianPoint Coordinates
IfcLengthMeasure").first
puts reference.text

117.4

But if I leave a space before IfcCartesianPoint in the call to the css
method I get a parser error (`on_error': unexpected ' ' after ''
(Nokogiri::CSS::SyntaxError)). This is my file one.xml:

<root xmlns:exp="http://foo" xmlns:xsi="http://bar">
<IfcWallStandardCase id="i1677">
<ObjectPlacement>
<IfcLocalPlacement xsi:nil="true" ref="i1671"/>
</ObjectPlacement>
</IfcWallStandardCase>

<IfcAxis2Placement3D id="i1671">
<Location>
<IfcCartesianPoint xsi:nil="true" ref="i1667"/>
</Location>
</IfcAxis2Placement3D>

<IfcCartesianPoint id="i1667">
<Coordinates id="i1670" exp:cType="list">
<IfcLengthMeasure exp:pos="0">117.4</IfcLengthMeasure>
<IfcLengthMeasure exp:pos="1">119.7</IfcLengthMeasure>
<IfcLengthMeasure exp:pos="2">0.</IfcLengthMeasure>
</Coordinates>
</IfcCartesianPoint>
</root>

This works too:

doc.css("IfcCartesianPoint Coordinates IfcLengthMeasure").each {|el|
puts el.text}

Produces:

117.4
119.7
0.

Thank you for your reply. When I continue to try and read the file I
have it keeps returning nil values and thus doesn't work. But when I
copy and paste the xml you have written over the file I am trying to
read then it does work. I understand that the path is slightly
different but using the xpath command-

doc.xpath("//IfcCartesianPoint/Coordinates/IfcLengthMeasure").each {|el|
puts el.text}

It should skip ahead to the first appearance of IfcCartesianPoint, much
the same as it works for using REXML xpath, no? As this same sting of
IfcCartesianPoint/Coordinates/IfcLengthMeasure appears in this file.
Based on the documentation here -

(http://nokogiri.org/tutorials/searching_a_xml_html_document.html)

I think it should be working but it always returns nil.

I have attached the xml file I am trying to read and was wondering if
you could see where my error is occurring. The first instance of
IfcCartesianPoint/Coordinates/IfcLengthMeasure appears on line 225.
Maybe it's the way you are passing the file to Nokogiri::XML? By the
way, in your way you are not closing the file handler. If you want to
pass Nokogiri the file instead of reading it yourself you can do:

doc = nil
File.open("one.xml") {|f| doc = Nokogiri::XML(f)}

or

doc = File.open("one.xml") {|f| Nokogiri::XML(f)}

This way, the file is properly closed.

Jesus.

Is there an advantage to using .open vs .read? The program I am writing
has to grab lots of information from the xml, maybe 300 items, would it
make a difference in speed to use one vs the other? Also for me to read
a file at say c:\one.xml for it to read I have to write -
doc = File.open("/one.xml") {|f| Nokogiri::XML(f)}
Another form will not read including "\one.xml"

Thank you again for your time, you have been most helpful and it is
greatly appreciated.

Attachments:
http://www.ruby-forum.com/attachment/6114/one.xml
 
J

Jesús Gabriel y Galán

Thank you for your reply. =A0When I continue to try and read the file I
have it keeps returning nil values and thus doesn't work. =A0But when I
copy and paste the xml you have written over the file I am trying to
read then it does work.

The difference is that you have namespaces in your file. Check this URL:

http://tenderlovemaking.com/2009/04/23/namespaces-in-xml/

In order to make this work, you can do something like this:

require 'nokogiri'

doc =3D Nokogiri::XML(File.read("one.xml"))
doc.collect_namespaces.each {|key,value| puts "#{key} =3D> #{value}"}
doc.css("uosNS|IfcCartesianPoint uosNS|Coordinates
uosNS|IfcLengthMeasure", {"uosNS" =3D>
"http://www.iai-tech.org/ifcXML/IFC2x3/FINAL"}).each {|el| puts
el.text}

(I added a line that shows all namespaces in the document). All nodes
under the uos node inherit the namespace referenced by the url you see
in the code, so in order to search for nodes within the uos node, you
need to specify the namespace.
Is there an advantage to using .open vs .read?

read reads the whole file in memory. Passing a file handler to
nokogiri will probably make no difference, because most likely it's
reading the full file to memory too.
The program I am writing
has to grab lots of information from the xml, maybe 300 items, would it
make a difference in speed to use one vs the other?

The only answer to this question is to benchmark.
Also for me to read
a file at say c:\one.xml for it to read I have to write -
doc =3D File.open("/one.xml") {|f| Nokogiri::XML(f)}
Another form will not read including "\one.xml"

I have no experience in Windows, but I think forward slashes should
always work (no idea about the drive letter, though).

Jesus.
 
R

Robert Klemme

2011/4/12 Jes=FAs Gabriel y Gal=E1n said:
The difference is that you have namespaces in your file. Check this URL:

http://tenderlovemaking.com/2009/04/23/namespaces-in-xml/

In order to make this work, you can do something like this:

require 'nokogiri'

doc =3D Nokogiri::XML(File.read("one.xml"))

The alternative is

doc =3D File.open("one.xml") {|io| Nokogiri::XML(io)}
doc.collect_namespaces.each {|key,value| puts "#{key} =3D> #{value}"}
doc.css("uosNS|IfcCartesianPoint uosNS|Coordinates
uosNS|IfcLengthMeasure", {"uosNS" =3D>
"http://www.iai-tech.org/ifcXML/IFC2x3/FINAL"}).each {|el| puts
el.text}

(I added a line that shows all namespaces in the document). All nodes
under the uos node inherit the namespace referenced by the url you see
in the code, so in order to search for nodes within the uos node, you
need to specify the namespace.


read reads the whole file in memory. Passing a file handler to
nokogiri will probably make no difference, because most likely it's
reading the full file to memory too.

I will have to read the whole file but it may make a crucial
difference whether it does so in one go or in chunks. Large files
might not even be readable with the File.read approach. If you pass
the file as a single string there is no choice but if you pass the
File instance nokogiri can decide what to do. This is more efficient.
Note also that because of buffering small files will have just one
(or a few) IO operations anyway.
The only answer to this question is to benchmark.

I don't think the file loading influences access speed. Once the file
is loaded into a object structure IO is over and all operations are in
memory plus the model of the file will be the same regardless whether
you read in one big chunk or in smaller ones.

The two approaches to loading the file do most likely have different
performance characteristics though.

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
K

Kyle X.

The difference is that you have namespaces in your file. Check this URL:
http://tenderlovemaking.com/2009/04/23/namespaces-in-xml/

In order to make this work, you can do something like this:

require 'nokogiri'

doc = Nokogiri::XML(File.read("one.xml"))
doc.collect_namespaces.each {|key,value| puts "#{key} => #{value}"}
doc.css("uosNS|IfcCartesianPoint uosNS|Coordinates
uosNS|IfcLengthMeasure", {"uosNS" =>
"http://www.iai-tech.org/ifcXML/IFC2x3/FINAL"}).each {|el| puts
el.text}

(I added a line that shows all namespaces in the document). All nodes
under the uos node inherit the namespace referenced by the url you see
in the code, so in order to search for nodes within the uos node, you
need to specify the namespace.

Thank you for the response. After reading the link you provided to make
any xml file read using Nokogiri if it has a namespace you must include
that with each time you are trying to grab information from it correct
(the name space is the url in xmlns="..." correct?)? Like you did here:
doc.css("uosNS|IfcCartesianPoint uosNS|Coordinates
uosNS|IfcLengthMeasure", {"uosNS" =>
"http://www.iai-tech.org/ifcXML/IFC2x3/FINAL"}).each {|el| puts
el.text}

In the link it says that, "Even though using namespaces is essential
when searching an XML document, Nokogiri tries to help out. If there are
namespaces declared on the root node of a document, Nokogiri will
automatically register those for you. You will still have to use the
prefix when searching the document, but the URL registration is done for
you."

Making both -
1 doc.xpath('//xmlns:tire',
2 'xmlns' => 'http://alicesautosupply.example.com/'
3 )
4 doc.xpath('//xmlns:tire')
Equal.

I tried this using the .xml I posted and it does not work. Is this
because the xmlns is not in the first line immediately following <?xml
version="1.0"?>? In turn making it necessary for every inquirary to
include {"uosNS" => "http://www.iai-tech.org/ifcXML/IFC2x3/FINAL"}?
I will have to read the whole file but it may make a crucial
difference whether it does so in one go or in chunks. Large files
might not even be readable with the File.read approach. If you pass
the file as a single string there is no choice but if you pass the
File instance nokogiri can decide what to do. This is more efficient.
Note also that because of buffering small files will have just one
(or a few) IO operations anyway.

I will try both and see how each performs against each other and if both
work properly.

Thank you both for your replies. Your help with this has been
invaluable.

Sincerely,
Kyle
 
J

Jesús Gabriel y Galán

Thank you for the response. =A0After reading the link you provided to mak= e
any xml file read using Nokogiri if it has a namespace you must include
that with each time you are trying to grab information from it correct
(the name space is the url in xmlns=3D"..." correct?)?
Yes.

Like you did here:


In the link it says that, "Even though using namespaces is essential
when searching an XML document, Nokogiri tries to help out. If there are
namespaces declared on the root node of a document, Nokogiri will
automatically register those for you. You will still have to use the
prefix when searching the document, but the URL registration is done for
you."

Making both -
1 =A0doc.xpath('//xmlns:tire',
2 =A0 =A0'xmlns' =3D> 'http://alicesautosupply.example.com/'
3 =A0)
4 =A0doc.xpath('//xmlns:tire')
Equal.

I tried this using the .xml I posted and it does not work. =A0Is this
because the xmlns is not in the first line immediately following <?xml
version=3D"1.0"?>? =A0In turn making it necessary for every inquirary to
include {"uosNS" =3D> "http://www.iai-tech.org/ifcXML/IFC2x3/FINAL"}?

Correct. The root node of your XML is the doc tag, which declares
namespaces, but the uos tag has its own namespace too. nokogiri will
register the ones present in the root node, as the article says. The
children nodes of uos inherit the namespace declared in the uos tag,
so this is what you have to use to search. I have not checked the
behaviour about the automatic registering of namespaces, but reading
the article this is how I understand it.

Jesus.
 
K

Kyle X.

Hello, Nokogiri has been going well for me but recently I have been
having trouble trying to read some xml, and from my reading online I
cannot find the proper way to write it using Nokogiri. Here are the two
lines I am having trouble with:

1)
<IfcWallStandardCase id="i17855">
<Representation>
<IfcProductDefinitionShape id="i17925">
<Representations id="i17928" exp:cType="list">
<IfcShapeRepresentation exp:pos="0" xsi:nil="true"
ref="i17886"/>
<IfcShapeRepresentation exp:pos="1" xsi:nil="true"
ref="i17919"/>
</Representations>
</IfcProductDefinitionShape>
</Representation>
</IfcWallStandardCase>

I am trying to get the reference for exp:pos="1", and I had this working
with using REXML with the following -

XPath.match( $doc, "//IfcWallStandardCase//*[@pos='1']" )

With nokogiri I can get it to read both pos 0 and 1, using .css and
xpath-

$doc_noko.css("uosNS|IfcWallStandardCase uosNS|IfcShapeRepresentation",
{"uosNS" => $http})
and
$doc_noko.xpath("//uosNS:IfcWallStandardCase//uosNS:IfcShapeRepresentation",
{"uosNS" => $http})

But cannot figure out how to get it to read only pos=1 using either
method and continuously get error or nil.


2)
<IfcDirection id="i1574">
<DirectionRatios id="i1577" exp:cType="list">
<exp:double-wrapper pos="0">1.</exp:double-wrapper>
<exp:double-wrapper pos="1">0.</exp:double-wrapper>
<exp:double-wrapper pos="2">0.</exp:double-wrapper>
</DirectionRatios>
</IfcDirection>

The issue I am having here is that I am reading this with Nokogiri using
xpath and the colon in exp:double is giving me trouble since the xpath
is written -

ref = "i1574"
$doc_noko.xpath("//uosNS:*[@id='#{ref}']//uosNS:exp:double-wrapper",
{"uosNS" => $http}).map {|element| element.text}

I am guessing that it would be easier to use .css here rather than
xpath. So I have tried using it but cannot seem to get it correct.
Trying -

ref = "i1574"
$doc_noko.css("uosNS|#{ref} uosNS|exp:double-wrapper", {"uosNS" =>
$http}).map {|element| element.text}

As I read in a previous post that you call the ref using #{} for css,
but this returns nil for me.

Any ideas?
 
K

Kyle X.

This has sufficiently deviated from the title of the thread, so to make
the information more relevant for future searchers I am going to make a
new post. I hope this is acceptable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top