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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and 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"

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

when i use these codes below for testing;


    puts reader.node_type

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

how can i get attribute values?

 i tried another method
doc = reader.expand
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
                case reader.node_type
                when XML_READER_TYPE_ELEMENT
                    when 'Stk'
          puts reader['Category']
          puts reader['Group']
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.