README example on using the SAX parser.

This commit is contained in:
Yorick Peterse 2014-09-16 14:36:02 +02:00
parent 317b49bcf6
commit 1c7d1e30b1
1 changed files with 20 additions and 0 deletions

View File

@ -44,6 +44,26 @@ Parsing an IO handle using the pull parser:
end end
end end
Parse a string of XML using the SAX parser:
class ElementNames
attr_reader :names
def initialize
@names = []
end
def on_element(namespace, name, attrs = {})
@names << name
end
end
handler = ElementNames.new
Oga.sax_parse_xml(handler, '<foo><bar></bar></foo>')
handler.names # => ["foo", "bar"]
Querying a document using XPath: Querying a document using XPath:
document = Oga.parse_xml('<people><person>Alice</person></people>') document = Oga.parse_xml('<people><person>Alice</person></people>')