How can i get attribute values from xml using libxml


#1

Hi ,
i have xml document like this

<?xml version="1.0" encoding="ISO-8859-9"?>

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


#2

try doc.find(’//Root/Stk[@Category=“601”]’)


#3

Thanks a lot Simon , it worked ,
can we double this filter method like category=“601” and brand=“15” at
the same time


#4

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

#5

try researching xpaths, particularly how to or 2 xpaths together.