私はノコギリとルビーに全く慣れておらず、少し助けを求めています。
を使用して非常に大きなXMLファイルを解析していますclass MyDoc < Nokogiri::XML::SAX::Document
。次に、ブロックの内側をトラバースします。
これが私のXMLファイルのフォーマットです:
<Content id="83087">
<Title></Title>
<PublisherEntity id="1067">eBooksLib</PublisherEntity>
<Publisher>eBooksLib</Publisher>
......
</Content>
「Content」タグが見つかったかどうかはすでにわかりますが、その中をトラバースする方法を知りたいと思います。これが私の短縮コードです:
class MyDoc < Nokogiri::XML::SAX::Document
#check the start element. set flag for each element
def start_element name, attrs = []
if(name == 'Content')
#get the <Title>
#get the <PublisherEntity>
#get the Publisher
end
end
def cdata_block(string)
characters(string)
end
def characters(str)
puts str
end
end