Class: Resedit::FormatXml
- Inherits:
-
TextFormat
- Object
- TextFormat
- Resedit::FormatXml
- Defined in:
- lib/resedit/text/format_xml.rb
Instance Method Summary collapse
-
#initialize(encoding) ⇒ FormatXml
constructor
A new instance of FormatXml.
- #loadLines(fname) ⇒ Object
- #saveLines(fname, lines, meta) ⇒ Object
Constructor Details
#initialize(encoding) ⇒ FormatXml
Returns a new instance of FormatXml.
9 10 11 |
# File 'lib/resedit/text/format_xml.rb', line 9 def initialize(encoding) super('utf-8') end |
Instance Method Details
#loadLines(fname) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/resedit/text/format_xml.rb', line 27 def loadLines(fname) hs={} open(fname+".xml", "r:"+@encoding) {|f| doc=REXML::Document.new(f) doc.elements.each("body/text"){|e| hs[e.attributes['id']] = e.text } } raise "No data in xml" if !hs.length lns=[] for i in 0..hs.length-1 raise "Text not found: "+i if !hs[i] lns+=[ hs[i] ] end return lns end |
#saveLines(fname, lines, meta) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/resedit/text/format_xml.rb', line 13 def saveLines(fname, lines, ) open(fname+".xml", "w:"+@encoding) {|f| xml=Builder::XmlMarkup.new(:indent => 2 , :target=>f) xml.instruct! :xml, :encoding => @encoding xml.body {|b| lines.each.with_index{|l,i| mt = {'id' => i} mt.update([i]) if [i] b.text(l, mt) } } } end |