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 Macneall
2009-Jun-08 13:32 UTC
Re: how can i get attribute values from xml using libxml
try doc.find(''//Root/Stk[@Category="601"]'')
On Mon, 08 Jun 2009 21:09:06 +0800, lecielbleu
<canali83-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> 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
>
Thanks a lot Simon , it worked , can we double this filter method like category="601" and brand="15" at the same time On Jun 8, 4:32 pm, "Simon Macneall" <macne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> try doc.find(''//Root/Stk[@Category="601"]'') > > On Mon, 08 Jun 2009 21:09:06 +0800, lecielbleu <canal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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
Jeffrey L. Taylor
2009-Jun-08 16:34 UTC
Re: how can i get attribute values from xml using libxml
See in-line code additions Quoting lecielbleu <canali83-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > 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.readcase reader.node_type when XML_READER_TYPE_ELEMENT case reader.name when ''Stk'' puts reader[''Category''] puts reader[''Group''] end end> > 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?
Simon Macneall
2009-Jun-08 22:22 UTC
Re: how can i get attribute values from xml using libxml
try researching xpaths, particularly how to or 2 xpaths together. On Mon, 08 Jun 2009 22:03:14 +0800, lecielbleu <canali83-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks a lot Simon , it worked , > can we double this filter method like category="601" and brand="15" at > the same time >