Go based xml manipulation library

163 views
Skip to first unread message

Tong Sun

unread,
Feb 11, 2021, 4:10:51 PM2/11/21
to golang-nuts

Is there any Go library that allow certain following-sibling manipulation?

Specifically, I want to,

  • locate an xml node via XPath
  • delete its following-sibling

More or less like this, http://zvon.org/comp/r/tut-XPath_1.html#Pages~Following-sibling_axis, but to delete the node, instead of just locating it.

thx



Steve Roth

unread,
Feb 11, 2021, 7:17:40 PM2/11/21
to golang-nuts
github.com/beevik/etree does much of what you're looking for.
Steve

Tong Sun

unread,
Feb 12, 2021, 12:00:57 PM2/12/21
to golang-nuts
Thanks Steve, 

That's what I thought, but on taking a closer look, especially the getting to the `following-sibling` part, I didn't find any API that I can make use of out of the box. Hence --


Could you elaborate on how to get to the `following-sibling` part of a given element for etree please? Using http://zvon.org/comp/r/tut-XPath_1.html#Pages~Following-sibling_axis as the example, in either place will do. thx

Santhosh Kumar T

unread,
Feb 14, 2021, 4:28:07 PM2/14/21
to golang-nuts
You can try https://github.com/santhosh-tekuri/xpath. it uses https://github.com/santhosh-tekuri/xpath as model.

BTW, I am author of the above projects

- santhosh

Tong Sun

unread,
Feb 14, 2021, 6:31:11 PM2/14/21
to Santhosh Kumar T, golang-nuts
Thank you Santhosh!

Can the https://github.com/santhosh-tekuri/xpath model edit or delete
elements, apart from locating them?
If so, are there any ready-made examples/blogs etc that I can refer to?

Thx!
> --
> You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/X_Di8cLEncU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e3ad6d21-07aa-41c7-93d1-f68d50018645n%40googlegroups.com.

Santhosh T

unread,
Feb 15, 2021, 2:42:38 AM2/15/21
to Tong Sun, golang-nuts
the dom model, currently only provides Append method.
but the all members of model are exported. so it should
be possible to write delete by removing node from slice and
setting its parent to null.

- santhosh
Reply all
Reply to author
Forward
0 new messages