3

I would like to convert yang to xml format. Please let me know if any tools are available already.

I tried with pyang yin format, which provides xml format but not in desired format.

Generated xml: Ex:

<container name="password">
      <leaf name="enc-type">
        <type name="enumeration">
          <enum name="clear">

Requied format:

<container>
   <enc-type>
    </en-type>
  </container>

4 Answers4

2

pyang you can use, I also have this requirement, and I use the pyang is enough.

pyang -f sample-xml-skeleton --sample-xml-skeleton-defaults -o output.xml input.yang

and the pyang format help:

$ pyang -h
Usage: pyang [options] [<filename>...]
 
  -f FORMAT, --format=FORMAT
                        Convert to FORMAT.  Supported formats are: yang, yin,
                        dsdl, capability, depend, jsonxsl, jstree, jtox, name,
                        omni, sample-xml-skeleton, tree, uml
 
  Sample-xml-skeleton output specific options:
    --sample-xml-skeleton-doctype=DOCTYPE
                        Type of sample XML document (data or config).
    --sample-xml-skeleton-defaults
                        Insert leafs with defaults values.
    --sample-xml-skeleton-annotations
                        Add annotations as XML comments.
    --sample-xml-skeleton-path=SAMPLE_PATH
                        Subtree to print
1

here you have a project on github to convert yang model to xml https://github.com/vhosakot/yang_to_xml you can also convert xml to yang model.

user1990
  • 536
  • 3
  • 13
0

YIN format is the standard XML representation of YANG models defined in the same RFC as the YANG itself. You should probably use it instead of any in-house XML format.

What you want to achieve is a strange mixture of YIN (with the container element) and instance document (enc-type element which corresponds to the leaf name). I doubt that your definition is complete enough to be sure what you really mean and I also doubt that there are any existing tools that you can use out of the box.

I'd recommend to stick to YIN or, if absolutely necessary, create own tool for this.

Community
  • 1
  • 1
Piotr Babij
  • 837
  • 5
  • 12
0

you can use pyang for the same. [https://github.com/mbj4668/pyang][1]

Sachin
  • 1,460
  • 17
  • 24