# Excel to xml

**URL:** <https://www.ruby-forum.com/t/excel-to-xml/134491>\
**Category:** Rails\
**Created:** [April 11, 2008, 11:53am UTC](https://www.ruby-forum.com/t/excel-to-xml/134491 "2008-04-11T11:53:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumantacaptain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@sumantacaptain](https://www.ruby-forum.com/u/sumantacaptain)\
**Post date:** [April 11, 2008, 11:53am UTC](https://www.ruby-forum.com/t/excel-to-xml/134491/1 "2008-04-11T11:53:28Z")

</div>

i have done excel to xml conversion like this but the problem is…if i  
rename the “d:\database\terget.txt” to “d:\database\terget.xml” then the  
file is not opening as a xml file & " The XML page cannot be displayed  
Cannot view XML input using style sheet. Please correct the error and  
then click the Refresh button, or try again later.

* * *

Invalid at the top level of the document. Error processing resource  
‘file:///D:/database/terget.xml’. Line 1, Position 1

- 10043-35-3 "  
^  
this error messege is generated

but if i use this as text file it is opening in internet explorer.

& another thing is that if i want to use  
1)dynamic path to select the source excel file… what should i do?

2)& the features of xml in this file that is the expanding & Collapseing  
features by ‘-’ & ‘+’ sign i want to add, but how?  
its very urgent realy  
thanx

---

<div class="post-metadata">

**Author:** ![sumantacaptain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@sumantacaptain](https://www.ruby-forum.com/u/sumantacaptain)\
**Post date:** [April 11, 2008, 11:55am UTC](https://www.ruby-forum.com/t/excel-to-xml/134491/2 "2008-04-11T11:55:35Z")

</div>

require ‘parseexcel’  
require ‘win32ole’  
require ‘roo’  
workbook = Spreadsheet::ParseExcel.parse(‘d:\source.xls’)  
worksheet = workbook.worksheet(0)  
puts  
@C = 0  
@r = 0  
@header = []  
@fn=[]  
skip = 0  
worksheet.each(skip){|row|  
first\_cell = row  
File.open(‘d:\test.txt’,‘a’) do |f|  
if @r \< 1  
@C = first\_cell.length  
for l in 0…@C  
@header[l] = first\_cell[l].to\_s(‘latin1’)  
end  
end  
@r = @r +1

end  
}

skip =1  
@cnt=0  
worksheet.each(skip) { |row|  
File.open(‘d:\database\terget.xml’,‘a’) do |file|

```
         first_cell=row
       for l in 0...@C
           if first_cell[l] !=nil
              str = first_cell[l].to_s('latin1')
          else
           str = ' '
           end
           file.puts "- <" + @header[l] + ">" + str + "</" + 

```

@header[l]+ “\>”  
file.puts  
end  
end  
@cnt= @cnt+1  
}

---

<div class="post-metadata">

**Author:** ![sumantacaptain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@sumantacaptain](https://www.ruby-forum.com/u/sumantacaptain)\
**Post date:** [April 11, 2008, 12:14pm UTC](https://www.ruby-forum.com/t/excel-to-xml/134491/3 "2008-04-11T12:14:02Z")

</div>

On 11 Apr 2008, at 10:53, Sumanta D. wrote:

> 2)& the features of xml in this file that is the expanding &  
> Collapseing  
> features by ‘-’ & ‘+’ sign i want to add, but how?  
> its very urgent realy  
> thanx

Umm that’s not an xml thing. The program displaying the xml may choose  
to do that, but that’s absolutely not somthing that should be in the  
xml itself. (and it looks like that’s what’s causing your parse error)

Fred

---

<div class="post-metadata">

**Author:** ![sumantacaptain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@sumantacaptain](https://www.ruby-forum.com/u/sumantacaptain)\
**Post date:** [April 11, 2008, 12:37pm UTC](https://www.ruby-forum.com/t/excel-to-xml/134491/4 "2008-04-11T12:37:16Z")

</div>

but can u help me on that…  
if u can help me by submitting code in reply that will be realy helpfull  
for me  
its urgent please…

---

<div class="post-metadata">

**Author:** ![sumantacaptain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@sumantacaptain](https://www.ruby-forum.com/u/sumantacaptain)\
**Post date:** [April 11, 2008, 12:54pm UTC](https://www.ruby-forum.com/t/excel-to-xml/134491/5 "2008-04-11T12:54:02Z")

</div>

On 11 Apr 2008, at 11:37, Sumanta D. wrote:

> but can u help me on that…  
> if u can help me by submitting code in reply that will be realy  
> helpfull  
> for me  
> its urgent please…

There is absolutely nothing that you can put in an xml file that will  
make the elements be collapsable. xml just describes some data, it  
doesn’t care about how it’s displayed. The program displaying the data  
may choose to do nice things such as some form of syntax highlighting.  
If you stick a bare xml document into firefox for example, you’ll get  
your collapsable nodes, because that’s just how firefox likes to  
display xml. If you need more then you could always right an xsl  
stylesheet that transforms the xml into an html document with all the  
GUI niceties that you want.

Fred

---

<div class="post-metadata">

**Author:** ![sumantacaptain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@sumantacaptain](https://www.ruby-forum.com/u/sumantacaptain)\
**Post date:** [April 11, 2008, 1:24pm UTC](https://www.ruby-forum.com/t/excel-to-xml/134491/6 "2008-04-11T13:24:45Z")

</div>

On 11 Apr 2008, at 12:04, Sumanta D. wrote:

> > stylesheet that transforms the xml into an html document with all the  
> > that will be really helpfuul to me  
> > Which u want to say above i know that…but i can’t reach the goal  
> > thats  
> > why i am submitting the code,asked for solution…  
> > can u help me(coding+advice) to solve it???

As far as the xml generation goes, you should probably look a  
something like builder (as it is you could very easily be generating  
invalid xml if the cells contain any of the forbidden characters.

Fred

---

<div class="post-metadata">

**Author:** ![sumantacaptain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@sumantacaptain](https://www.ruby-forum.com/u/sumantacaptain)\
**Post date:** [April 11, 2008, 1:04pm UTC](https://www.ruby-forum.com/t/excel-to-xml/134491/7 "2008-04-11T13:04:17Z")

</div>

> There is absolutely nothing that you can put in an xml file that will  
> make the elements be collapsable. xml just describes some data, it  
> doesn’t care about how it’s displayed. The program displaying the data  
> may choose to do nice things such as some form of syntax highlighting.  
> If you stick a bare xml document into firefox for example, you’ll get  
> your collapsable nodes, because that’s just how firefox likes to  
> display xml. If you need more then you could always right an xsl  
> stylesheet that transforms the xml into an html document with all the  
> GUI niceties that you want.

but in my project have to read excel file& i have to generate xml for  
each row individualy…& all the xml should in a common file as i want  
to do there…  
now can u help me by submitting some code to me??  
that will be really helpfuul to me  
Which u want to say above i know that…but i can’t reach the goal thats  
why i am submitting the code,asked for solution…  
can u help me(coding+advice) to solve it???

---

<div class="post-metadata">

**Author:** ![sumantacaptain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@sumantacaptain](https://www.ruby-forum.com/u/sumantacaptain)\
**Post date:** [April 11, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/excel-to-xml/134491/8 "2008-04-11T13:28:25Z")

</div>

plz provide some code/example

---

<div class="post-metadata">

**Author:** ![sumantacaptain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@sumantacaptain](https://www.ruby-forum.com/u/sumantacaptain)\
**Post date:** [April 11, 2008, 2:25pm UTC](https://www.ruby-forum.com/t/excel-to-xml/134491/9 "2008-04-11T14:25:25Z")

</div>

On 11 Apr 2008, at 12:28, Sumanta D. wrote:

> plz provide some code/example

[http://builder.rubyforge.org/](http://builder.rubyforge.org/)
