From: Charles Wel on 1 Aug 2010 10:41 Hello All, I have an XML file containing this <properties> <property key="ABC"> <value xml:lang="de">Description de</value> <value xml:lang="en">Description en</value> </property> <property key="XYZ"> <value xml:lang="de">Description de</value> <value xml:lang="en">Description en</value> </property> </properties> I made a code to add a new <value> tag to each <property>. The part of code is: require "rexml/document" include REXML ... ... pval = Element.new("value") pval.add_attribute("xml:lang","fr") pval.add_text("Description fr") fproperty.elements << pval fproperty is the node object My final XML file looks like this: <properties> <property key="ABC"> <value xml:lang="de">Description de</value> <value xml:lang="en">Description en</value> <value xml:lang="fr">Description fr</value></property> <property key="XYZ"> <value xml:lang="de">Description de</value> <value xml:lang="en">Description en</value> <value xml:lang="fr">Description fr</value></property> </properties> One "TAB" is inserted for each 4 spaces which were in the original file. How to avoid this? And how to add a CR to the new element? Thanks for your help, I'm a very newby -- Posted via http://www.ruby-forum.com/.
From: Robert Klemme on 1 Aug 2010 15:06 2010/8/1 Charles Wel <charlemagne(a)welnowiec.net>: > Hello All, > > I have an XML file containing this > <properties> > <property key="ABC"> > <value xml:lang="de">Description de</value> > <value xml:lang="en">Description en</value> > </property> > <property key="XYZ"> > <value xml:lang="de">Description de</value> > <value xml:lang="en">Description en</value> > </property> > </properties> > > I made a code to add a new <value> tag to each <property>. > The part of code is: > > require "rexml/document" > include REXML > ... > ... > pval = Element.new("value") > pval.add_attribute("xml:lang","fr") > pval.add_text("Description fr") > fproperty.elements << pval > fproperty is the node object > > My final XML file looks like this: > > <properties> > <property key="ABC"> > <value xml:lang="de">Description de</value> > <value xml:lang="en">Description en</value> > <value xml:lang="fr">Description fr</value></property> > <property key="XYZ"> > <value xml:lang="de">Description de</value> > <value xml:lang="en">Description en</value> > <value xml:lang="fr">Description fr</value></property> > </properties> > > One "TAB" is inserted for each 4 spaces which were in the original file. > How to avoid this? > And how to add a CR to the new element? > > Thanks for your help, I'm a very newby I think, you will have to create your own formatter - or use a different one for output. You'll find some explanation in the REXML documentation. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
From: Charles Wel on 1 Aug 2010 15:33 Robert Klemme wrote: > > I think, you will have to create your own formatter - or use a > different one for output. You'll find some explanation in the REXML > documentation. Thank you Robert for your reply. I am willing to write my own formatter but despite I read some REXML docs, I don't know where to begin. :-D This is really my first day with ruby; concerning REXML I'll be happy to be pointed to some samples. In advance Thanks to All, Charles -- Posted via http://www.ruby-forum.com/.
From: Robert Klemme on 12 Aug 2010 13:11 2010/8/1 Charles Wel <charlemagne(a)welnowiec.net>: > Robert Klemme wrote: >> >> I think, you will have to create your own formatter - or use a >> different one for output. You'll find some explanation in the REXML >> documentation. > > Thank you Robert for your reply. > I am willing to write my own formatter but despite I read some REXML > docs, I don't know where to begin. :-D > > This is really my first day with ruby; > concerning REXML I'll be happy to be pointed to some samples. I hope you found it by now. If not, please see http://www.germane-software.com/software/rexml/docs/tutorial.html Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
From: Charles Wel on 12 Aug 2010 15:25 Robert Klemme wrote: > I hope you found it by now. If not, please see > http://www.germane-software.com/software/rexml/docs/tutorial.html > I saw it before but I'll give it a look again. Great thank you. Charles -- Posted via http://www.ruby-forum.com/.
|
Next
|
Last
Pages: 1 2 Prev: Could I build a video chat site with ruby on rails? Next: Standard IO streams in Ruby |