Reputation: 802
How do I parse YANG models in java ? I need to convert the yang model into a xml format.
I have already tried pyang. But since it is in python, it does not suite my requirement.
Upvotes: 10
Views: 7343
Reputation: 1
you can use Yangkit parser.
maven dependency
<dependency>
<groupId>io.github.yang-central.yangkit</groupId>
<artifactId>yangkit-parser</artifactId>
<version>1.1.2</version>
</dependency>
YangSchemaContext schemaContext = YangYinParser.parse("yangdir");
schemaContext.validate();
Upvotes: 0
Reputation: 11
The above API is valid for previous versions. Use the following API for the current version
YangTextSchemaContextResolver yangContextResolver = YangTextSchemaContextResolver.create("yang-context-resolver");
yangContextResolver.registerSource(new URL("file:///home/ABA/XXX/Workspaces/ABC/X/config.yang"));
yangContextResolver.registerSource(new URL("file:///home/ABC/XXX/Workspaces/ABC/X/XXX-YY.yang"));
Optional<SchemaContext> sc = yangContextResolver.getSchemaContext();
Upvotes: 1
Reputation: 82
Yes, that's true.
Use yang-parser-impl from Open daylight. It provides a yang parser and returns a set of parsed modules. Which you can further query to get more node objects.
Upvotes: 5