When I select only the y element from the attached file, I get nothing:
xmlstarlet sel -t -c y test.xml
I need to include the root element (x):
xmlstarlet sel -t -c x/y test.xml
But when I want to update the element, it works without root element:
xmlstarlet ed -u y -v New test.xml
I find this behavior inconsistent. Is it intended? If not, what would be the correct one?
Thanks,
Simon
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
Test file
I agree that it's surprising, but xmlstarlet is somewhat
underdocumented so it's hard to say what's correct/indended.
Currently, ed applies to whatever xmlXPathEvalExpression() returns,
and sel just passes a stylesheet to xsltApplyStylesheetUser().
A sensible idea might be to rewrite ed to use xslt as well, which
would make things consistent as well as add power and flexibility. On
the other hand, it would probably break backwards compatibility and
require a significant amount of work. So don't expect that to happen
unless someone volunteers...
http://xmlsoft.org/html/libxml-xpath.html#xmlXPathEvalExpression
http://xmlsoft.org/XSLT/html/libxslt-transform.html#xsltApplyStylesheetUser
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
Ok, I understand. If it bugs me again, I'll send a patch :)
Maybe a small note in the Documentation for ed would suffice for now? This way others won't be stumped like me.
So I dug into this a bit more and it turns out it's actually a pretty simple bug. Initially I thought ed was doing the equivalent of //y when given y, but actually it was doing /node()/y, ie: starting 1 node too far down. And it turns out xmllint had the same problem.
Fixed in a7ba9a6405905a80ceb71ecbee10b21e21a73778
libxml2 mailing list thread: https://mail.gnome.org/archives/xml/2012-May/msg00078.html
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
Great, thanks for the effort!
Find in version 1.4.0