Write document about XML::Queryng#xpath's namespace argument

This commit is contained in:
Kitaiti Makoto 2019-12-03 20:13:32 +09:00
parent f4832339b2
commit 10e9101c42
1 changed files with 5 additions and 9 deletions

View File

@ -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"] descendant::*[local-name() = "bar" and namespace-uri() = "http://example.com"]
Unlike Nokogiri, Oga does _not_ provide a way to create "dynamic" namespaces. Like Nokogiri, Oga provides a way to create "dynamic" namespaces.
That is, Nokogiri allows one to query the above document as following: That is, Oga allows one to query the above document as following:
document = Nokogiri::XML('<root xmlns="http://example.com"><bar>bar</bar></root>') document = Oga.parse_xml('<root xmlns="http://example.com"><bar>bar</bar></root>')
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 Moreover, because Oga assigns the name "xmlns" to default namespaces you can use
queries. Because Oga assigns the name "xmlns" to default namespaces you can use
this in your XPath queries: this in your XPath queries:
document = Oga.parse_xml('<root xmlns="http://example.com"><bar>bar</bar></root>') document = Oga.parse_xml('<root xmlns="http://example.com"><bar>bar</bar></root>')
@ -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') 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 ## HTML5 Support
Oga fully supports HTML5 including the omission of certain tags. For example, Oga fully supports HTML5 including the omission of certain tags. For example,