How to search for elements matching xpath expression in emacs nxml-mode?

Is there a way to interactively search for nodes that match a given xpath expression in emacs?

I would like something similar to re-forward-search , but instead of using a regular expression, I would type xpath.

+6
source share
2 answers

I do not have an answer to XPath requests; Sorry. But you can try Icicles to search for the search keys Ms Ms x and Ms Ms x ( icicle-search-xml-element and icicle-search-xml-element-text-node ).

This allows you to search for content and text() nodes, respectively, of top-level XML elements whose names match the regular expression that you provide.

For icicle-search-xml-element can be any of these forms:

  • <ELEMENTNAME>...</ELEMENTNAME>
  • <ELEMENTNAME ATTRIBUTE1="..."...>...</ELEMENTNAME>
  • <ELEMENTNAME/>
  • <ELEMENTNAME ATTRIBUTE1="...".../>

You can also select a search rather than search contexts. defined by the regular expression-name-name of the element, but non-contexts, that is, buffer text that is outside such elements. To do this, use `CM- ~ 'at the time of completion. (This is a switch, and this only affects the future of the search command, not the current one.)

For icicle-search-xml-element-text-node top-level matching elements must not have attributes. Only the top-level elements of the form <ELEMENTNAME>...</ELEMENTNAME> are matched.

NTN.

0
source

I did something similar a long time ago. Now I can not give you any details, but I will provide an overview of the approach that I have taken.

I created some Emacs functions to interact with (query) my own XML database. I did this with the Mark Logic server one time and with the Berkley DB XML database another time. One of these functions was simply querying the database. Another feature will send an XQuery query that includes an Emacs buffer or a buffer selection.

The native XML database server processed the query, returned the results, and my Emacs functions displayed the result in the result buffer.

This approach allowed me to query XML using XPath and XQuery, which is a much more powerful query language that includes XPath. (I wrote about XQuery a long time ago, here: https://www.ibm.com/developerworks/library/x-xqueryxpath/ )

It was difficult how it might sound, it turned out that it was surprisingly easy.

0
source

Source: https://habr.com/ru/post/979744/


All Articles