Hi Please help me i want to replace the tag </li><span> to </li></see><see><span> at time can anybody in world give me an solution Regards Prashant
On Sep 9, 12:50 pm, prashanth hiremath <prashanthhirema...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi > > Please help me i want to replace the tag > > </li><span> to </li></see><see><span> at time > > can anybody in world give me an solution >A little more context would be helpful. Fred> Regards > > Prashant
Thank u i have done different method m using gsub operator i replaces the
tags to the form ,but problem is that
if
doc = Hpricot(open(''Delhi.txt''))
x=doc.to_s
doc1=x.gsub(/<(\/?)li><span>/,''</li></see><see><span>'')
puts doc1
doc1.search(''span'').each do |y|
puts y.inner_text
end
its giving error
undefined method `search'' for #<String:0xb7d0bc74>
(NoMethodError)
because doc1 is string how can i conevrt so that i can read the file again
by hpricot
On Wed, Sep 9, 2009 at 6:42 PM, Frederick Cheung
<frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
> On Sep 9, 12:50 pm, prashanth hiremath
<prashanthhirema...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
> > Hi
> >
> > Please help me i want to replace the tag
> >
> > </li><span> to
</li></see><see><span> at time
> >
> > can anybody in world give me an solution
> >
>
> A little more context would be helpful.
>
> Fred
> > Regards
> >
> > Prashant
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I don''t know Hpricot, but what you can do is: first open the file and do a gsub on the content, save it in a different/same file, and then open it using Hpricot. Just to warn you, won''t be very efficient if files are huge or there are lot many files you want to process. I think, there must be some more simpler way of doing it as well. Thanks, Abhinav -- अभिनव http://twitter.com/abhinav On Thu, Sep 10, 2009 at 10:25 AM, prashanth hiremath <prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thank u i have done different method m using gsub operator i replaces the > tags to the form ,but problem is that > > if > doc = Hpricot(open(''Delhi.txt'')) > x=doc.to_s > doc1=x.gsub(/<(\/?)li><span>/, > ''</li></see><see><span>'') > > puts doc1 > doc1.search(''span'').each do |y| > puts y.inner_text > end > > > its giving error > > undefined method `search'' for #<String:0xb7d0bc74> (NoMethodError) > because doc1 is string how can i conevrt so that i can read the file again > by hpricot > > On Wed, Sep 9, 2009 at 6:42 PM, Frederick Cheung > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> On Sep 9, 12:50 pm, prashanth hiremath <prashanthhirema...-Re5JQEeQqe8@public.gmane.orgm> >> wrote: >> > Hi >> > >> > Please help me i want to replace the tag >> > >> > </li><span> to </li></see><see><span> at time >> > >> > can anybody in world give me an solution >> > >> >> A little more context would be helpful. >> >> Fred >> > Regards >> > >> > Prashant >> > > > > >
Thax for reply i did using hpricot On Thu, Sep 10, 2009 at 12:33 PM, Abhinav Saxena <abhinav061-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> > I don''t know Hpricot, but what you can do is: first open the file and > do a gsub on the content, save it in a different/same file, and then > open it using Hpricot. Just to warn you, won''t be very efficient if > files are huge or there are lot many files you want to process. > > I think, there must be some more simpler way of doing it as well. > > Thanks, > Abhinav > -- > अभिनव > http://twitter.com/abhinav > > > > > On Thu, Sep 10, 2009 at 10:25 AM, prashanth hiremath > <prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Thank u i have done different method m using gsub operator i replaces the > > tags to the form ,but problem is that > > > > if > > doc = Hpricot(open(''Delhi.txt'')) > > x=doc.to_s > > doc1=x.gsub(/<(\/?)li><span>/, > > ''</li></see><see><span>'') > > > > puts doc1 > > doc1.search(''span'').each do |y| > > puts y.inner_text > > end > > > > > > its giving error > > > > undefined method `search'' for #<String:0xb7d0bc74> (NoMethodError) > > because doc1 is string how can i conevrt so that i can read the file > again > > by hpricot > > > > On Wed, Sep 9, 2009 at 6:42 PM, Frederick Cheung > > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > >> > >> > >> On Sep 9, 12:50 pm, prashanth hiremath <prashanthhirema...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> wrote: > >> > Hi > >> > > >> > Please help me i want to replace the tag > >> > > >> > </li><span> to </li></see><see><span> at time > >> > > >> > can anybody in world give me an solution > >> > > >> > >> A little more context would be helpful. > >> > >> Fred > >> > Regards > >> > > >> > Prashant > >> > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Can you let us know how you did it using Hpricot? -- अभिनव http://twitter.com/abhinav On Thu, Sep 10, 2009 at 12:41 PM, prashanth hiremath <prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thax for reply i did using hpricot > > > On Thu, Sep 10, 2009 at 12:33 PM, Abhinav Saxena <abhinav061-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> >> I don''t know Hpricot, but what you can do is: first open the file and >> do a gsub on the content, save it in a different/same file, and then >> open it using Hpricot. Just to warn you, won''t be very efficient if >> files are huge or there are lot many files you want to process. >> >> I think, there must be some more simpler way of doing it as well. >> >> Thanks, >> Abhinav >> -- >> अभिनव >> http://twitter.com/abhinav >> >> >> >> >> On Thu, Sep 10, 2009 at 10:25 AM, prashanth hiremath >> <prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Thank u i have done different method m using gsub operator i replaces >> > the >> > tags to the form ,but problem is that >> > >> > if >> > doc = Hpricot(open(''Delhi.txt'')) >> > x=doc.to_s >> > doc1=x.gsub(/<(\/?)li><span>/, >> > ''</li></see><see><span>'') >> > >> > puts doc1 >> > doc1.search(''span'').each do |y| >> > puts y.inner_text >> > end >> > >> > >> > its giving error >> > >> > undefined method `search'' for #<String:0xb7d0bc74> (NoMethodError) >> > because doc1 is string how can i conevrt so that i can read the file >> > again >> > by hpricot >> > >> > On Wed, Sep 9, 2009 at 6:42 PM, Frederick Cheung >> > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> >> >> >> >> On Sep 9, 12:50 pm, prashanth hiremath <prashanthhirema...@gmail.com> >> >> wrote: >> >> > Hi >> >> > >> >> > Please help me i want to replace the tag >> >> > >> >> > </li><span> to </li></see><see><span> at time >> >> > >> >> > can anybody in world give me an solution >> >> > >> >> >> >> A little more context would be helpful. >> >> >> >> Fred >> >> > Regards >> >> > >> >> > Prashant >> >> >> > >> > >> > > >> > >> >> > > > > >
Sure i did using gsub operator and then i again opened using hpricot like
this
doc = Hpricot(open(''Delhi.txt''))
x=doc.to_s
doc1=x.gsub(/<(\/?)li><span>/,''</li></see><see><span>'')
doc2=Hpricot(doc1.to_s)
doc2.search(''li'').each do |z|
puts z.inner_text
end
On Thu, Sep 10, 2009 at 12:48 PM, Abhinav Saxena
<abhinav061-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:
>
> Can you let us know how you did it using Hpricot?
>
> --
> अभिनव
> http://twitter.com/abhinav
>
>
>
>
> On Thu, Sep 10, 2009 at 12:41 PM, prashanth hiremath
> <prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Thax for reply i did using hpricot
> >
> >
> > On Thu, Sep 10, 2009 at 12:33 PM, Abhinav Saxena
<abhinav061-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > wrote:
> >>
> >> I don''t know Hpricot, but what you can do is: first open
the file and
> >> do a gsub on the content, save it in a different/same file, and
then
> >> open it using Hpricot. Just to warn you, won''t be very
efficient if
> >> files are huge or there are lot many files you want to process.
> >>
> >> I think, there must be some more simpler way of doing it as well.
> >>
> >> Thanks,
> >> Abhinav
> >> --
> >> अभिनव
> >> http://twitter.com/abhinav
> >>
> >>
> >>
> >>
> >> On Thu, Sep 10, 2009 at 10:25 AM, prashanth hiremath
> >> <prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> >> > Thank u i have done different method m using gsub operator i
replaces
> >> > the
> >> > tags to the form ,but problem is that
> >> >
> >> > if
> >> > doc = Hpricot(open(''Delhi.txt''))
> >> > x=doc.to_s
> >> > doc1=x.gsub(/<(\/?)li><span>/,
> >> >
''</li></see><see><span>'')
> >> >
> >> > puts doc1
> >> > doc1.search(''span'').each do |y|
> >> > puts y.inner_text
> >> > end
> >> >
> >> >
> >> > its giving error
> >> >
> >> > undefined method `search'' for
#<String:0xb7d0bc74> (NoMethodError)
> >> > because doc1 is string how can i conevrt so that i can read
the file
> >> > again
> >> > by hpricot
> >> >
> >> > On Wed, Sep 9, 2009 at 6:42 PM, Frederick Cheung
> >> >
<frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >> >>
> >> >>
> >> >>
> >> >> On Sep 9, 12:50 pm, prashanth hiremath
<prashanthhirema...-Re5JQEeQqe8@public.gmane.orgm
> >
> >> >> wrote:
> >> >> > Hi
> >> >> >
> >> >> > Please help me i want to replace the tag
> >> >> >
> >> >> > </li><span> to
</li></see><see><span> at time
> >> >> >
> >> >> > can anybody in world give me an solution
> >> >> >
> >> >>
> >> >> A little more context would be helpful.
> >> >>
> >> >> Fred
> >> >> > Regards
> >> >> >
> >> >> > Prashant
> >> >>
> >> >
> >> >
> >> > >
> >> >
> >>
> >>
> >
> >
> > >
> >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Last prob i facing is incrementing of inner_text between span tags
i will explain the code
I have delhi.txt
<see><span>Central Kolkata</span><li> <b>Eden
Gardens</b> (one of the most
famous cricket stadiums in the world),
</li><li> <b>Akashwani Bhavan</b>, All India Radio
building
</li><li> <b>Indoor Stadium</b>
</li><li> <b>Fort William</b>, the massive and
impregnable British Citadel
built in 1773. The fort is still in use and retains its well-guarded
grandeur. Visitors are allowed in with special permission only.
</li><li> <b>Victoria Memorial</b>
</li><li> <b>Calcutta Racecourse</b>
</li><li> <b>Chowringee</b>, is the Market place of
Kolkata. You will find
shops ranging from Computer Periferals to cloth merchants. Even tailors and
a few famous Movie theaters too. This place is a favourite pass time for
local people.
</li><span>Northern Kolkata</span><li> <b>Nakhoda
Mosque</b> (the largest
mosque in Kolkata) and the </li></see>
Like this i want this form of xml
<See>
<Sights>
<LandMarkType>Redfort
<Location>
<Landmarkname> Chatta chowk </Landmarkname>
<desc> ---- </desc>
</Location>
<Location>
<Landmarkname>---- </Landmarkname>
<desc> a </desc>
</Location>
</LandMarkType>
</Sights>
<Sights>
<LandMarkType>---- </LandMarkType>
<Location>
<Landmarkname> --- </Landmarkname>
<desc> -- </desc>
</Location>
<Location>
<Landmarkname>-- </Landmarkname>
<desc> --- </desc>
</Location>
</Sights>
</See>
so that if <span>Central Kolkata</span> is this then have to execute
upto
another span
i have code for that
doc = Hpricot(open(''Delhi.txt''))
x=doc.to_s
doc1=x.gsub(/<(\/?)li><span>/,''</li></see><see><span>'')
doc2=Hpricot(doc1.to_s)
doc3=Document.new
doc3.add_element("See")
doc3.root.add_element("Sights")
c= doc3.root.elements[1]
c.add_element("LandMarkType")
(doc2/"see").each do |dv|
(dv/"span").each do |h|
# dv/"span").each do |h|
puts h
if h.inner_html == "Central Kolkata"
c.elements["LandMarkType"].text= h.inner_html
(dv/"li").each do |y|
d=y.search(''b'').inner_text
z=c.add_element("Location")
z.elements <<
Element.new("LandMarkname")
z.elements["LandMarkname"].text=d
z.add_element("desc")
z.elements["desc"].text=y.inner_text
end
end
end
end
please help me to increment <span>Central Kolkata</span> for all
spans as
landmarktypes
Regards
Prashanth Hiremath
On Thu, Sep 10, 2009 at 1:06 PM, prashanth hiremath <
prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Sure i did using gsub operator and then i again opened using hpricot like
> this
>
> doc = Hpricot(open(''Delhi.txt''))
>
> x=doc.to_s
>
doc1=x.gsub(/<(\/?)li><span>/,''</li></see><see><span>'')
>
> doc2=Hpricot(doc1.to_s)
> doc2.search(''li'').each do |z|
> puts z.inner_text
> end
>
>
>
> On Thu, Sep 10, 2009 at 12:48 PM, Abhinav Saxena
<abhinav061-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:
>
>>
>> Can you let us know how you did it using Hpricot?
>>
>> --
>> अभिनव
>> http://twitter.com/abhinav
>>
>>
>>
>>
>> On Thu, Sep 10, 2009 at 12:41 PM, prashanth hiremath
>> <prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
>> > Thax for reply i did using hpricot
>> >
>> >
>> > On Thu, Sep 10, 2009 at 12:33 PM, Abhinav Saxena
<abhinav061-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> > wrote:
>> >>
>> >> I don''t know Hpricot, but what you can do is: first
open the file and
>> >> do a gsub on the content, save it in a different/same file,
and then
>> >> open it using Hpricot. Just to warn you, won''t be
very efficient if
>> >> files are huge or there are lot many files you want to
process.
>> >>
>> >> I think, there must be some more simpler way of doing it as
well.
>> >>
>> >> Thanks,
>> >> Abhinav
>> >> --
>> >> अभिनव
>> >> http://twitter.com/abhinav
>> >>
>> >>
>> >>
>> >>
>> >> On Thu, Sep 10, 2009 at 10:25 AM, prashanth hiremath
>> >>
<prashanthhiremath2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> >> > Thank u i have done different method m using gsub
operator i replaces
>> >> > the
>> >> > tags to the form ,but problem is that
>> >> >
>> >> > if
>> >> > doc =
Hpricot(open(''Delhi.txt''))
>> >> > x=doc.to_s
>> >> > doc1=x.gsub(/<(\/?)li><span>/,
>> >> >
''</li></see><see><span>'')
>> >> >
>> >> > puts doc1
>> >> > doc1.search(''span'').each do
|y|
>> >> > puts y.inner_text
>> >> > end
>> >> >
>> >> >
>> >> > its giving error
>> >> >
>> >> > undefined method `search'' for
#<String:0xb7d0bc74> (NoMethodError)
>> >> > because doc1 is string how can i conevrt so that i can
read the file
>> >> > again
>> >> > by hpricot
>> >> >
>> >> > On Wed, Sep 9, 2009 at 6:42 PM, Frederick Cheung
>> >> >
<frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> >> >>
>> >> >>
>> >> >>
>> >> >> On Sep 9, 12:50 pm, prashanth hiremath <
>> prashanthhirema...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> >> >> wrote:
>> >> >> > Hi
>> >> >> >
>> >> >> > Please help me i want to replace the tag
>> >> >> >
>> >> >> > </li><span> to
</li></see><see><span> at time
>> >> >> >
>> >> >> > can anybody in world give me an solution
>> >> >> >
>> >> >>
>> >> >> A little more context would be helpful.
>> >> >>
>> >> >> Fred
>> >> >> > Regards
>> >> >> >
>> >> >> > Prashant
>> >> >>
>> >> >
>> >> >
>> >> > >
>> >> >
>> >>
>> >>
>> >
>> >
>> > >
>> >
>>
>> >>
>>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> > doc1=x.gsub(/<(\/?)li><span>/,''</li></see><see><span>'') > doc2=Hpricot(doc1.to_s)doc1 is only a string, so: A) doc1 is misleading in this context and I''d use a different variable name, and B) doc1.to_s is superfluous processing in the Hpricot call If you want to process all the ''Kolkata''s, then don''t do the if/end. Encountering a div in ''(doc2/"see").each do |dv|'' should force the creation of a new LandMarkType element since you have only one span per div. This creates the container to nest all your other data (from the li items) for that landmark type. My earlier example picking out only 1 span to work on was to show that once the span/li sets were properly wrapped with divs, you could process a specific one if you wanted to. If you want them all, just iterate without the selection. Slow down and ponder the code you write, understanding the ''why'' of what you do. Don''t just type in other stuff blindly, because at the end of the day, what have you learned? Real knowledge isn''t solving just this problem, it''s learning a new tool that you can apply to a different situation, which requires understanding why something worked. -- Posted via http://www.ruby-forum.com/.
Thank u da I solved ya m just beginner in ruby on rails.I will work hard to learn Regards prashanth On Thu, Sep 10, 2009 at 7:37 PM, Ar Chron <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > > > > doc1=x.gsub(/<(\/?)li><span>/,''</li></see><see><span>'') > > doc2=Hpricot(doc1.to_s) > > doc1 is only a string, so: > A) doc1 is misleading in this context and I''d use a different variable > name, and > B) doc1.to_s is superfluous processing in the Hpricot call > > If you want to process all the ''Kolkata''s, then don''t do the if/end. > > Encountering a div in ''(doc2/"see").each do |dv|'' should force the > creation of a new LandMarkType element since you have only one span per > div. This creates the container to nest all your other data (from the li > items) for that landmark type. > > My earlier example picking out only 1 span to work on was to show that > once the span/li sets were properly wrapped with divs, you could process > a specific one if you wanted to. If you want them all, just iterate > without the selection. > > Slow down and ponder the code you write, understanding the ''why'' of what > you do. Don''t just type in other stuff blindly, because at the end of > the day, what have you learned? Real knowledge isn''t solving just this > problem, it''s learning a new tool that you can apply to a different > situation, which requires understanding why something worked. > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---