-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functionality to specify a default namespace. #110
Comments
Maybe.... how do you read section 2.3, emphasis mine:
That being said, the feature seems like a reasonable case. I think that an implementation can go beyond the spec so long as the doing so is opt-in and the behavior of the spec can still be followed. That being said, this post seems to indicate that the maintainer of libxml2 thought doing so would be a bad idea. Hard to tell at this point the full background on that. One avenue of research would be to look at some other XPath libraries (Java has a few, IIRC) and see if any of those offer an equivalent feature. |
Ok I see, thanks for your reply. As far as I understand the main issue would be that according to the XPath spec element names without a prefix are by default interpreted as not being in any namespace at all, i.e. the I tried looking around for how other libraries do it and I didn't really find any example where it was possible but I didn't spend a huge amount of time looking for one either. I guess it might be better to stick to the standard in this case. I've actually seen that in XPath 2.0 there is the possibility to use a wildcard prefix |
I believe that to be the case, yes.
That would be my personal opinion, yes 😄 That being said, there might be nicer paths to defining the namespace. I'm always interested in hearing feedback about the API of the library works for people. |
I guess I might have asked for such functionality because it took me a bit to figure out how to set up my parser. It might be a (potentially bad) thing learned from OOP languages but I would have preferred if there was a struct which would contain everything ( Something like: XpathReader<'d> {
fn new(xml: &str) -> Result<Self, _>;
fn evaluate(&self, node: N, xpath_query: &str) -> Result<sxd_xpath::Value<'d>, _>
where N: Into<sxd_xpath::nodeset::Node<'d>>;
} But I'm not sure if that would work like that with the node argument if the struct owns the Document. (An alternative would be to just query against the root element, even if that is a bit limited.) And I'm not sure where I would put the XpathReader<'d> {
fn new_with_context(xml: &str, context: &'d Context) -> Result<Self, _>;
// or
fn set_context(&mut self, context: &'d Context);
} What I have done so far is this, which is inspired by Maybe I'm also just having some Rust beginner issues. :') |
Ok I figured out where the problem was (I had to add the lifetime to |
Actually I've implemented some of the ideas I mentioned in this issue in my crate xpath_reader. #110 and #111 are no longer of concern to me personally and you can close them if you want. (Or keep them if you think the concern might persist for other people.) |
@leoschwarz IIRC, this issue morphed from default namespaces (which we decided was a bad idea) to something about nicer ways to construct the objects. Which aspect(s) of that did you implement? |
The later one, I basically ended up taking out the code I've written for musicbrainz_rust and cleaned it up a bit for the crate. It's a bit more than I initially proposed here, but also more useful. The main interface is the trait XpathReader which provides Namespace configuration still takes place using the |
@shepmaster I'm closing this issue since I am not really in support of it anymore, but if you would like to keep it open please feel free to reopen it. As discussed it would probably be counter-intuitive to diverge from the XPath spec and might cause other issues along the way. This Stack Overflow answer explains why this design decision was deliberately made in the first place. If anything this is a documentation issue and should be covered in a prominent place. Also the other thing I ended up discussing here and sort of shifting the issue is providing a serde-inspired reader API, which I'm still working on and which I plan to get in a nice shape in the next few days. (I'm thinking about an actual serde deserializer in the future but I'm not yet sure how to go about that.) If at some point you think this would be nice functionality to also have in this crate I'd be happy to help upstreaming it or some parts thereof. I made a lot of refactorings (and breaking changes) for the upcoming 0.5 release, so the current docs at docs.rs are currently very outdated. |
Hi. Maybe the functionality is already there and I'm missing something, but essentially I was parsing this XML:
and I had some issues selecting elements due to the namespace. After I saw the test and #108 I've figured out I can use a
Context
withand then use
mb:
for all elements in my XPath queries. e.g.//mb:area/mb:name/text()
. However this is a bit cumbersome, so I wanted to ask if functionality to specify a default namespace which would be used for unqualified selectors in XPath queries is desirable? Or would this break the XPath spec somehow?(I might implement this functionality, I just wanted to ask in advance for some thoughts so I don't end up coding for nothing. ^^)
The text was updated successfully, but these errors were encountered: