libyang  2.1.148
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Parsing Data

Data parser allows to read instances from a specific format. libyang supports the following data formats:

  • XML

    Original data format used in NETCONF protocol. XML mapping is part of the YANG specification (RFC 6020).

  • JSON

    The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG can be found in RFC 7951. The specification does not cover RPCs, actions and Notifications, so the representation of these data trees is proprietary and corresponds to the representation of these trees in XML.

While the parsers themselves process the input data only syntactically, all the parser functions actually incorporate the common validator checking the input data semantically. Therefore, the parser functions accepts two groups of options - Data parser options and Data validation options.

In contrast to the schema parser, data parser also accepts empty input data if such an empty data tree is valid according to the schemas in the libyang context (i.e. there are no top level mandatory nodes).

There are individual functions to process different types of the data instances trees:

  • lyd_parse_data() is intended for standard configuration data trees. According to the given parser options, the caller can further specify which kind of data tree is expected:
    • complete :running datastore: this is the default case, possibly with the use of (some of) the LYD_PARSE_STRICT, LYD_PARSE_OPAQ or LYD_VALIDATE_PRESENT options.
    • complete configuration-only datastore (such as :startup): in this case it is necessary to except all state data using LYD_PARSE_NO_STATE option.
    • incomplete datastore: there are situation when the data tree is incomplete or invalid by specification. For example the *:operational* datastore is not necessarily valid and results of the NETCONF's <get> or <get-config> oprations used with filters will be incomplete (and thus invalid). This can be allowed using LYD_PARSE_ONLY, the LYD_PARSE_NO_STATE should be used for the data returned by <get-config> operation.
  • lyd_parse_ext_data() is used for parsing configuration data trees defined inside extension instances, such as instances of yang-data extension specified in RFC 8040.
  • lyd_parse_op() is used for parsing RPCs/actions, replies, and notifications. Even NETCONF rpc, rpc-reply, and notification messages are supported.
  • lyd_parse_ext_op() is used for parsing RPCs/actions, replies, and notifications defined inside extension instances.

Further information regarding the processing input instance data can be found on the following pages.

Functions List