schema tree FEATURE lys_atomize_xpath API function

Tests included.
diff --git a/src/tree_schema.c b/src/tree_schema.c
index f5a70b7..f0c386e 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -30,6 +30,7 @@
 #include "dict.h"
 #include "log.h"
 #include "set.h"
+#include "xpath.h"
 #include "tree.h"
 #include "tree_schema.h"
 #include "tree_schema_internal.h"
@@ -284,6 +285,50 @@
     return NULL;
 }
 
+API LY_ERR
+lys_atomize_xpath(const struct lysc_node *ctx_node, const char *xpath, int options, struct ly_set **set)
+{
+    LY_ERR ret = LY_SUCCESS;
+    struct lyxp_set xp_set;
+    struct lyxp_expr *exp;
+    uint32_t i;
+
+    LY_CHECK_ARG_RET(NULL, ctx_node, xpath, set, LY_EINVAL);
+    if (!(options & LYXP_SCNODE_ALL)) {
+        options = LYXP_SCNODE;
+    }
+
+    memset(&xp_set, 0, sizeof xp_set);
+
+    /* compile expression */
+    exp = lyxp_expr_parse(ctx_node->module->ctx, xpath);
+    LY_CHECK_ERR_GOTO(!exp, ret = LY_EINVAL, cleanup);
+
+    /* atomize expression */
+    ret = lyxp_atomize(exp, LYD_JSON, ctx_node->module, ctx_node, LYXP_NODE_ELEM, &xp_set, options);
+    LY_CHECK_GOTO(ret, cleanup);
+
+    /* allocate return set */
+    *set = ly_set_new();
+    LY_CHECK_ERR_GOTO(!*set, LOGMEM(ctx_node->module->ctx); ret = LY_EMEM, cleanup);
+
+    /* transform into ly_set */
+    (*set)->objs = malloc(xp_set.used * sizeof *(*set)->objs);
+    LY_CHECK_ERR_GOTO(!(*set)->objs, LOGMEM(ctx_node->module->ctx); ret = LY_EMEM, cleanup);
+    (*set)->size = xp_set.used;
+
+    for (i = 0; i < xp_set.used; ++i) {
+        if (xp_set.val.nodes[i].type == LYXP_NODE_ELEM) {
+            ly_set_add(*set, xp_set.val.scnodes[i].scnode, LY_SET_OPT_USEASLIST);
+        }
+    }
+
+cleanup:
+    lyxp_set_free_content(&xp_set);
+    lyxp_expr_free(ctx_node->module->ctx, exp);
+    return ret;
+}
+
 char *
 lysc_path_until(const struct lysc_node *node, const struct lysc_node *parent, LYSC_PATH_TYPE pathtype, char *buffer,
                 size_t buflen)