Menu

#92 Different behavior when selecting or editing

all
closed-fixed
nobody
main code (54)
5
2012-09-04
2012-05-18
Anonymous
No

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

Discussion

  • Noam Postavsky

    Noam Postavsky - 2012-05-23

    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

     
  • Anonymous

    Anonymous - 2012-05-23

    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.

     
  • Noam Postavsky

    Noam Postavsky - 2012-05-25
    • status: open --> open-fixed
     
  • Noam Postavsky

    Noam Postavsky - 2012-05-25

    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

     
  • Noam Postavsky

    Noam Postavsky - 2012-09-04

    Find in version 1.4.0

     
  • Noam Postavsky

    Noam Postavsky - 2012-09-04
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.

Auth0 Logo