Skip to content

lyd_parse_data_path parse options #2477

Open

Description

@yoousra

Hi,

Used versions:
libyang-3.13.6
sysrepo-3.7.11

I'm using lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree) to parse an xml file and validate that its content is conformed to the yang data tree.

I have something like this:

sr_connect(0, &sr_conn);
struct ly_ctx* ctx = sr_acquire_context(sr_conn);
lyd_parse_data_path(ctx, my_xml_file, LYD_XML, parse_options=**LYD_PARSE_STRICT**, LYD_VALIDATE_MULTI_ERROR, &output);

But my need is also to return an error when there's a module in the xml that is not installed in sysrepo.
I'm using LYD_PARSE_STRICT but it doesn't work for this type of verification. Is there a way to verify this?

Thank you for your reply!

Activity

  1. michalvasko commented on Jan 23, 2026

    @michalvasko
    Member

    I am not sure I understand, you using LYD_VALIDATE_MULTI_ERROR with LYD_PARSE_STRICT should cause that you get an error on an unknown element but possible get more errors if found in the data.

  2. yoousra commented on Jan 27, 2026

    @yoousra
    Author

    Let me clarify my question with an example.

    Suppose I have 3 modules in the xml I want to validate, for example:

    <hardware xmlns="urn:ietf:params:xml:ns:yang:ietf-hardware">
      <component>
      	<name>random_name</name>
      </component>
    </hardware>
    
    <fan-tray xmlns="urn:o-ran:fan:1.0">
      <fan-state>
      	<wrong-leaf-name>random_value</wrong-leaf-name>
      </fan-state>
    </fan-tray>
    
    <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
     .....
    </interfaces>
    

    And suppose I install o-ran-fan and o-ran-hardware modules but not ietf-interfaces module:

    sysrepoctl --install o-ran-fan.yang
    sysrepoctl --install o-ran-hardware.yang
    

    In this case by executing the function:
    lyd_parse_data_path(ctx, my_xml_file, LYD_XML, parse_options=**LYD_PARSE_STRICT**, LYD_VALIDATE_MULTI_ERROR, &output);

    I expect 2 errors:
    1- On o-ran-fan because it has a wrong leaf (wrong-leaf-name) which doesn't exist in the yang schema.
    2- On ietf-interfaces because it is not installed (=> doesn't exist in the context against which the validation is done).

    But I only get the first error. Is there something I'm missing or is my understanding not correct?

    Thanks a lot for your reply.

  3. michalvasko commented on Jan 29, 2026

    @michalvasko
    Member

    I have tested it with some examples and it worked as expected. Please provide a similar example I can reproduce (with all the required YANG modules).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    is:questionIssue is actually a question.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions