You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was porting my Ruby code which uses the Nokogiri library to sxd-xpath and was very confused why none of my xpaths were working anymore, and after some searching around I found #138
So copy-pasting the examples from that issue, this doesn't work:
let package = sxd_document::parser::parse("<root xmlns=\"https://some.place.com/metadata\">hello</root>").expect("failed to parse XML");let document = package.as_document();let value = sxd_xpath::evaluate_xpath(&document,"/root").expect("XPath evaluation failed");assert_eq!("hello", value.string());
but this does:
let package = sxd_document::parser::parse("<root xmlns=\"https://some.place.com/metadata\">hello</root>").expect("failed to parse XML");let document = package.as_document();letmut context = sxd_xpath::Context::new();
context.set_namespace("foobar","https://some.place.com/metadata");let xpath = sxd_xpath::Factory::new().build("/foobar:root").expect("Unable to build xpath").expect("Unable to build xpath");let value = xpath.evaluate(&context, document.root()).expect("XPath evaluation failed");assert_eq!("hello", value.string());
It would be nice to have a way to at least disable this behavior, although in my opinion it shouldn't be the default. It's unergonomic, the vast majority of XML files don't need it, and at least some other XML libraries (e.g. Nokogiri) don't work this way.
let xml = "<root xmlns=\"https://some.place.com/metadata\">hello</root>";let xml = remove_namespaces(xml);let package = sxd_document::parser::parse(&xml).expect("failed to parse XML");let document = package.as_document();let value = sxd_xpath::evaluate_xpath(&document,"/root").expect("XPath evaluation failed");assert_eq!("hello", value.string());
The text was updated successfully, but these errors were encountered:
I was porting my Ruby code which uses the Nokogiri library to
sxd-xpath
and was very confused why none of my xpaths were working anymore, and after some searching around I found #138So copy-pasting the examples from that issue, this doesn't work:
but this does:
It would be nice to have a way to at least disable this behavior, although in my opinion it shouldn't be the default. It's unergonomic, the vast majority of XML files don't need it, and at least some other XML libraries (e.g. Nokogiri) don't work this way.
A quick (and somewhat silly) workaround:
...and with this it works:
The text was updated successfully, but these errors were encountered: