Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert yang to xml

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>
like image 771
Sujani Chalagalla Avatar asked Oct 20 '25 14:10

Sujani Chalagalla


2 Answers

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
like image 162
Pengwei Chen Avatar answered Oct 23 '25 18:10

Pengwei Chen


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.

like image 28
Piotr Babij Avatar answered Oct 23 '25 18:10

Piotr Babij



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!