# Html to xml

**URL:** <https://www.ruby-forum.com/t/html-to-xml/174884>\
**Category:** Rails\
**Created:** [September 3, 2009, 1:57pm UTC](https://www.ruby-forum.com/t/html-to-xml/174884 "2009-09-03T13:57:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![prashanth\_hiremath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prashanth\_hiremath](https://www.ruby-forum.com/u/prashanth_hiremath)\
**Post date:** [September 3, 2009, 1:57pm UTC](https://www.ruby-forum.com/t/html-to-xml/174884/1 "2009-09-03T13:57:17Z")

</div>

Hi ,

This is prashanth

\<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' ' http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' [

]\> Red Fort

- **Chatta  
Chowk**  
(Covered Bazaar) â€“ True to the name, this is a covered bazaar between  
the  
gate and the fort itself, now filled with souvenir hawkers.
- **Diwan-i-Am** (Hall of Public Audience) â€“ This building separates the outer court from the inner court, and has a marble platform for the emperor's throne.
- **Hayat Baksh Bagh** (Life-Bestowing Gardens) â€“ Once a grand garden of full of fountains and streams, now sadly all dry — only dry channels and acres of green grass remain.
- **Diwan-i-Khas** (Hall of Private Audience) â€“ Built completely of marble, this is where the emperor received special visitors.
- **Khas Mahal** (Private Palace) â€“ The Emperor's main residence. The octagonal **Mussaman Burj** tower looks out toward the Yamuna River, and is where the Emperor used to appear before the public for each morning.
- **Rang Mahal** (Colour Palace) â€“ The residence of the Sultan's main wife.
- **Mumtaz Mahal** (Jewel Palace) â€“ Contained six apartments for the Sultan's harem. Now used as a museum of court textiles, carpets, weapons, etc (free).
- **Daawat Khana**. A minor palace at the northmost end of the Fort, this was originally the residence of a prince, but it was converted into a tea house by the British, a function it continues today. Basic meals go for around 60 rupees, drinks 10-20 rupees, and it also has the cleanest toilets around.
- **Swatantra Sangrama Sangrahalaya** (Museum of the Independence Movement) â€“ To the left after the Chatta Chowk, this is a reasonably well-presented museum on the history of independence activism in India, starting from the Mutiny of 1857 all the way to Gandhi.

I got an html format by hpricot and its search method

i wanna covert to xml format i mean i able to got inner\_text between  
span  
that is in case Red Fort

Red Fort got and taken in temp variable as t1 and between **Chatta  
Chowk** taken as t2 and between

- …
 as t3

So i pulling text from html so i wanna convert to xml format

the format is  
  
Red FortChatta Chowk  
 Chatta Chowk (Covered Bazaar) â€“ True to the name, this is  
a  
covered bazaar between the gate and the fort itself, now filled with  
souvenir hawkers.

like i have to do this kind of structure i ,So can you help me to  
convert

Regards

Prashant

---

<div class="post-metadata">

**Author:** ![prashanth\_hiremath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prashanth\_hiremath](https://www.ruby-forum.com/u/prashanth_hiremath)\
**Post date:** [September 3, 2009, 2:07pm UTC](https://www.ruby-forum.com/t/html-to-xml/174884/2 "2009-09-03T14:07:14Z")

</div>

On Thu, Sep 3, 2009 at 4:54 AM, prashanth  
hiremath[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> like i have to do this kind of structure i ,So can you help me to convert

So what have you tried so far, and how isn’t it giving you the result  
you’re looking for?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![prashanth\_hiremath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prashanth\_hiremath](https://www.ruby-forum.com/u/prashanth_hiremath)\
**Post date:** [September 3, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/html-to-xml/174884/3 "2009-09-03T14:28:19Z")

</div>

Thank u for reply

K i will send you the code ,and also the input and output i am getting  
.I  
will send how the output like

INPUT is

Red Fort

- **Chatta Chowk** (Covered Bazaar) â€“ True to the name, this is a covered bazaar between the gate and the fort itself, now filled with souvenir hawkers.
- **Diwan-i-Am** (Hall of Public Audience) â€“ This building separates the outer court from the inner court, and has a marble platform for the emperor's throne.
Agrsa- **very Beautiful** A minor palace at the northmost end of the Fort, this was originally the residence of a prince, but it was converted into a tea house by the British, a function it continues today. Basic meals go for around 60 rupees, drinks 10-20 rupees, and it also has the cleanest toilets around.
- **Diwan-i-Am** (Hall of Public Audience) â€“ This building separates the outer court from the inner court, and has a marble platform for the emperor's throne.

So s I able to pull the text from the html inform of array but i dont  
know  
how to put the text to currespoding elements

Red Fort  
Chatta Chowk  
(Covered Bazaar) â€“ True to the name, this is a covered  
bazaar  
between the gate and the fort itself, now filled with souvenir hawkers.

i have to continue for all i mean for next text also So that I am not  
getting to do through loop

so can u help me

Regards  
Prashant

On Thu, Sep 3, 2009 at 5:35 PM, Hassan S.  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![prashanth\_hiremath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prashanth\_hiremath](https://www.ruby-forum.com/u/prashanth_hiremath)\
**Post date:** [September 3, 2009, 2:45pm UTC](https://www.ruby-forum.com/t/html-to-xml/174884/4 "2009-09-03T14:45:52Z")

</div>

On Thu, Sep 3, 2009 at 5:26 AM, prashanth  
hiremath[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Personally, I’d probably do something like this with XSLT, but…

Aside from that, this example looks very strange – do you really  
intend that LandMarkName be a child of LandMarkType, and so  
on?

> Red Fort  
> Chatta Chowk  
> (Covered Bazaar) – True to the name, this is a covered bazaar  
> between the gate and the fort itself, now filled with souvenir hawkers.

I would think you would want e.g.  
  
Red Fort  
Chatta Chowk  
…

Frankly, your example doesn’t make sense – an xpath query on  
LandMarkName is going to return the Description tags and value  
as well, which seems an odd use case 🙂

## FWIW,

Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![prashanth\_hiremath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/df705f/32.png) [@prashanth\_hiremath](https://www.ruby-forum.com/u/prashanth_hiremath)\
**Post date:** [September 3, 2009, 3:10pm UTC](https://www.ruby-forum.com/t/html-to-xml/174884/5 "2009-09-03T15:10:28Z")

</div>

K i will try and if any problem i will ask u

On Thu, Sep 3, 2009 at 6:14 PM, Hassan S.  
\<removed\_email\_address@domain.invalid
