私のコードがあります:
require 'builder'
def initXML(builder)
builder.instruct!
builder.results(:result => 'result'){}
end
def writeXML(builder,name,hello)
builder.test(:name => name){
builder.hello hello
}
end
builder = Builder::XmlMarkup.new(:target=> STDOUT, :indent=>4)
initXML(builder)
writeXML(builder,'name1','hello1')
writeXML(builder,'name2','hello2')
私はこのXMLを取得することを実行します:
<?xml version="1.0" encoding="UTF-8"?>
<results result="result">
</results>
<test name="name1">
<hello>hello1</hello>
</test>
<test name="name2">
<hello>hello2</hello>
</test>
しかし</results>
、ファイルの最後に終了タグが必要です。<results>
ノード内に書き込む方法はありますか? または</results>
、ファイルの最後に移動しますか? のこぎりを使ったほうがいいですか?または、XML を手動で生成した方がよいでしょうか? 私はWatir単体テストでそれを使用しようとしています.XMLファイルに結果を書き込むために使用できるものはありますか?
(更新)それが私が欲しいXMLです:
<?xml version="1.0" encoding="UTF-8"?>
<results result="result">
<test name="name1">
<hello>hello1</hello>
</test>
<test name="name2">
<hello>hello2</hello>
</test>
</results>
ありがとう。