Hi
Please help me i want to replace the tag
to at timecan anybody in world give me an solution
Regards
Prashant
Hi
Please help me i want to replace the tag
to at timecan anybody in world give me an solution
Regards
Prashant
On Sep 9, 12:50 pm, prashanth hiremath [email protected]
wrote:
Hi
Please help me i want to replace the tag
to at timecan anybody in world give me an solution
A little more context would be helpful.
Fred
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>/,’’)
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 C.
<[email protected]
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.
अà¤à¤¿à¤¨à¤µ
http://twitter.com/abhinav
On Thu, Sep 10, 2009 at 10:25 AM, prashanth hiremath
Thax for reply i did using hpricot
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
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
Last prob i facing is incrementing of inner_text between span tags
i will explain the code
I have delhi.txt
Central Kolkata
Like this i want this form of xml
so that if Central Kolkata 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>/,’’)
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 Central Kolkata for all spans
as
landmarktypes
Regards
Prashanth Hiremath
On Thu, Sep 10, 2009 at 1:06 PM, prashanth hiremath <
doc1=x.gsub(/<(/?)li>/,’’)
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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs