Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2706

Re: Can you search in REXML by attributes?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail
From "Kyle X." <haebooty@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: Can you search in REXML by attributes?
Date Tue, 12 Apr 2011 14:39:21 -0500
Organization Service de news de lacave.net
Lines 69
Message-ID <432aa169fd6ad8a814926c8ea0c7e61b@ruby-forum.com> (permalink)
References <6680e1dd986ba2ce87d806950a81ee57@ruby-forum.com> <BANLkTim=ZwXUL-1hoLvfDzN8EUCUQDk1Vw@mail.gmail.com> <07d88b73a8b6b59812b5fed98c782aca@ruby-forum.com> <AANLkTikDnWpKcMM70U1VjsE5QJv8kpAbkFsKLKnyijtG@mail.gmail.com> <cce24af37a85d53425022f133364bb62@ruby-forum.com> <560f26c9f7549339ef393be5559307fd@ruby-forum.com> <BANLkTikxs8g3Gq6OGNhT7p6oGMUA4RUVNw@mail.gmail.com> <3eb231103a780e91a17cc5b95fd82ddf@ruby-forum.com> <BANLkTim9mUWkWgJDH4Obkx6gHjnUtdHLSQ@mail.gmail.com>
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1302637184 61330 65.111.164.187 (12 Apr 2011 19:39:44 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Tue, 12 Apr 2011 19:39:44 +0000 (UTC)
In-Reply-To <BANLkTim9mUWkWgJDH4Obkx6gHjnUtdHLSQ@mail.gmail.com>
X-Received-From This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway
X-Mail-Count 381375
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <432aa169fd6ad8a814926c8ea0c7e61b@ruby-forum.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:2706

Show key headers only | View raw


> 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

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

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Can you search in REXML by attributes? "Kyle X." <haebooty@yahoo.com> - 2011-03-31 19:53 -0500
  Re: Can you search in REXML by attributes? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-03-31 20:27 -0500
  Re: Can you search in REXML by attributes? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-03-31 20:45 -0500
  Re: Can you search in REXML by attributes? "Kyle X." <haebooty@yahoo.com> - 2011-04-01 11:27 -0500
    Re: Can you search in REXML by attributes? Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-01 12:19 -0500
      Re: Can you search in REXML by attributes? "Kyle X." <haebooty@yahoo.com> - 2011-04-10 18:01 -0500
        Re: Can you search in REXML by attributes? "Kyle X." <haebooty@yahoo.com> - 2011-04-10 18:27 -0500
          Re: Can you search in REXML by attributes? Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-11 02:37 -0500
            Re: Can you search in REXML by attributes? "Kyle X." <haebooty@yahoo.com> - 2011-04-11 13:57 -0500
              Re: Can you search in REXML by attributes? Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-12 03:17 -0500
                Re: Can you search in REXML by attributes? Robert Klemme <shortcutter@googlemail.com> - 2011-04-12 04:46 -0500
                Re: Can you search in REXML by attributes? "Kyle X." <haebooty@yahoo.com> - 2011-04-12 14:39 -0500
                Re: Can you search in REXML by attributes? Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-12 15:37 -0500
  Re: Can you search in REXML by attributes? "Kyle X." <haebooty@yahoo.com> - 2011-04-01 14:22 -0500
    Re: Can you search in REXML by attributes? "Kyle X." <haebooty@yahoo.com> - 2011-04-04 13:44 -0500
  Re: Can you search in REXML by attributes? "Kyle X." <haebooty@yahoo.com> - 2011-04-19 15:42 -0500
  Re: Can you search in REXML by attributes? "Kyle X." <haebooty@yahoo.com> - 2011-04-20 02:22 -0500

csiph-web