On Tue, Apr 12, 2011 at 9:39 PM, Kyle X. <haebooty / yahoo.com> wrote:
>> 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.
>
> 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:
>
>> doc.css("uosNS|IfcCartesianPoint uosNS|Coordinates
>> uosNS|IfcLengthMeasure", {"uosNS" =3D>
>> "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 =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.