data BUGFIX check input node when anydata/anyxml expected

Be more careful about the expected input data in API functions to avoid
later segfaults when treating data as anyxml/anydata when they are
something else.
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index 811051b..1edfb0f 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -266,6 +266,7 @@
     LY_ERR ret = LY_SUCCESS;
 
     LY_CHECK_ARG_RET(NULL, any, value_str, LY_EINVAL);
+    LY_CHECK_ARG_RET(NULL, any->schema, any->schema->nodetype & LYS_ANYDATA, LY_EINVAL);
 
     a = (struct lyd_node_any *)any;
     *value_str = NULL;
@@ -318,6 +319,7 @@
     struct lyd_node_any *t;
 
     LY_CHECK_ARG_RET(NULL, trg, LY_EINVAL);
+    LY_CHECK_ARG_RET(NULL, trg->schema, trg->schema->nodetype & LYS_ANYDATA, LY_EINVAL);
 
     t = (struct lyd_node_any *)trg;