On Mon, Apr 11, 2011 at 8:57 PM, Kyle X. <haebooty / yahoo.com> wrote:
> 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.