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 <
[email protected]> 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 <[email protected]>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
>> <[email protected]> wrote:
>> > Thax for reply i did using hpricot
>> >
>> >
>> > On Thu, Sep 10, 2009 at 12:33 PM, Abhinav Saxena <[email protected]>
>> > 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
>> >> <[email protected]> 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
>> >> > <[email protected]> wrote:
>> >> >>
>> >> >>
>> >> >>
>> >> >> On Sep 9, 12:50 pm, prashanth hiremath <
>> [email protected]>
>> >> >> 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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to