From 10e9101c423cc8ab26d407644f525df9bdd67989 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Tue, 3 Dec 2019 20:13:32 +0900 Subject: [PATCH] Write document about XML::Queryng#xpath's namespace argument --- README.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 002e044..1313f2a 100644 --- a/README.md +++ b/README.md @@ -227,15 +227,14 @@ And if you want to specify an explicit namespace URI, you can use this: descendant::*[local-name() = "bar" and namespace-uri() = "http://example.com"] -Unlike Nokogiri, Oga does _not_ provide a way to create "dynamic" namespaces. -That is, Nokogiri allows one to query the above document as following: +Like Nokogiri, Oga provides a way to create "dynamic" namespaces. +That is, Oga allows one to query the above document as following: - document = Nokogiri::XML('bar') + document = Oga.parse_xml('bar') - document.xpath('x:root/x:bar', :x => 'http://example.com') + document.xpath('x:root/x:bar', namespaces: {'x' => 'http://example.com'}) -Oga does have a small trick you can use to cut down the size of your XPath -queries. Because Oga assigns the name "xmlns" to default namespaces you can use +Moreover, because Oga assigns the name "xmlns" to default namespaces you can use this in your XPath queries: document = Oga.parse_xml('bar') @@ -246,9 +245,6 @@ When using this you can still restrict the query to the correct namespace URI: document.xpath('xmlns:root[namespace-uri() = "http://example.com"]/xmlns:bar') -In the future I might add an API to ease this process, although at this time I -have little interest in providing an API similar to Nokogiri. - ## HTML5 Support Oga fully supports HTML5 including the omission of certain tags. For example,