Nokogiri のソース コードを調べていますが、Nokogiri が文字列を要素に解析する方法がわかりません。ソースコードは次の場所にあります。
https://github.com/sparklemotion/nokogiri/tree/master/lib/nokogiri
例:私は文字列を持っています:
raw = "<html> <body> body <div>this is div </div> </body> <html>"
Nokogiri::HTML(raw)
=>
#(Document:0x4d0c786 {
name = "document",
children = [
#(DTD:0x4d0bc6e { name = "html" }),
#(Element:0x4cfa46e {
name = "html",
children = [
#(Element:0x4cf9bfe {
name = "body",
children = [
#(Text "body"),
#(Element:0x4cf9348 {
name = "div",
children = [ #(Text "this is div")]
})]
})]
})]
})
を調べましたがnokogiri / lib / nokogiri / xml / sax
、html文字列をどのように解釈するかはどこにもわかりません。ソースコードを読んでみると、上記の出力で data typeElement
があることに気付きましたが、ソースコードのどこにも を宣言していませんclass Element
。
一般に、ノコギリが文字列を上記のデータ構造に解析する方法を説明してくれる人はいますか?