Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LibXML-Ruby find with namespace 1

Status
Not open for further replies.

lazylester

Programmer
Dec 21, 2009
1
US
I would greatly appreciate any help with this noob question...

I'm using LibXML-Ruby to make a very small xml doc and then search for a node. The document is correctly generated, but I'm evidently missing something very basic because the search is not yielding any result. I have:

require 'rubygems'
require 'xml'
tmp_doc = XML::Document.new()
tmp_doc.root = XML::Node.new('a:frame')
tmp_doc.root["xmlns:a"]='tmp_doc.root << XML::Node.new('a:table')
puts tmp_doc
puts tmp_doc.find("//a:table","a:
The doc is printed but search result is 0

Can you help with the "find" statement, please? Thanks in advance.
 
This is a rewrite of it.
[tt]
require 'rubygems'
require 'xml'

tmp_doc = XML::Document.new()
tmp_doc.root = XML::Node.new('a:frame')

[red]#[/red]tmp_doc.root["xmlns:a"]='[ignore][/ignore]'
[blue]nsroot=XML::Namespace.new(tmp_doc.root,'a','[ignore][/ignore]')[/blue]

tmp_doc.root << [blue]p=[/blue]XML::Node.new('a:table')
[blue]p.namespaces.namespace=nsroot[/blue]

puts tmp_doc
puts tmp_doc.find("//a:table",[blue]{'a'=>'[ignore][/ignore]'}[/blue]).length
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top