Forum: Ruby on Rails how can i get attribute values from xml using libxml

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
lecielbleu (Guest)
on 2009-06-08 17:09
(Received via mailing list)
Hi ,
i have xml document like this
<?xml version="1.0" encoding="ISO-8859-9"?>
<Root><Stk Category="601" Group="60101"
Brand="001">....................

then i have to use Category attribute but reader class couldnt
recognize attributes

when i use these codes below for testing;

    while reader.read

    puts reader.node_type
    end

it shows only 1 and 15 values which means
XML_READER_TYPE_ELEMENT                 => 1
XML_READER_TYPE_END_ELEMENT             => 15

how can i get attribute values?

 i tried another method
doc = reader.expand
doc.find('//Root/Stk/[Category='601']')
but it also didnt work
Simon M. (Guest)
on 2009-06-08 17:33
(Received via mailing list)
try doc.find('//Root/Stk[@Category="601"]')
lecielbleu (Guest)
on 2009-06-08 18:03
(Received via mailing list)
Thanks a lot Simon , it worked ,
can we double this filter method like category="601" and brand="15" at
the same time
Jeffrey L. Taylor (Guest)
on 2009-06-08 20:35
(Received via mailing list)
See in-line code additions

Quoting lecielbleu <removed_email_address@domain.invalid>:
> when i use these codes below for testing;
>
>     while reader.read
                case reader.node_type
                when XML_READER_TYPE_ELEMENT
                    case reader.name
                    when 'Stk'
          puts reader['Category']
          puts reader['Group']
                    end
                end
Simon M. (Guest)
on 2009-06-09 02:23
(Received via mailing list)
try researching xpaths, particularly how to or 2 xpaths together.
This topic is locked and can not be replied to.