问题
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.
回答1:
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.
回答2:
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();
来源:https://stackoverflow.com/questions/24950398/parsing-yang-model-in-java