Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help needed with xmljson #555

Closed
mahen-g opened this issue Feb 2, 2020 · 5 comments
Closed

Help needed with xmljson #555

mahen-g opened this issue Feb 2, 2020 · 5 comments

Comments

@mahen-g
Copy link

mahen-g commented Feb 2, 2020

Hi,

I am referring to the below wiki for xmljson conversion.
https://github.com/mbj4668/pyang/wiki/XmlJson

I was able to generate the stylesheet. But having issues with converting xml instance document to json.
I have set the following environment variables.
However, xsltproc seems to looking for the files in the default installed directory. Shouldn't it be looking for the files in the below directory.
Is there any other option I am missing ?

which xsltproc
/usr/bin/xsltproc

env | grep -i pyang
PYANG_RNG_LIBDIR=/home/test/pyang/pyang/schema
PYANG_XSLT_DIR=/home/test/pyang/pyang/xslt

xsltproc -o nw.json nw.xsl a.xml
warning: failed to load external entity "/usr/local/share/yang/xslt/jsonxsl-templates.xsl"
compilation error: file nw.xsl line 2 element include
xsl:include : unable to load /usr/local/share/yang/xslt/jsonxsl-templates.xsl

Thanks,

@mahen-g
Copy link
Author

mahen-g commented Feb 3, 2020

Team,

Any help with this.

Thanks,

@mbj4668
Copy link
Owner

mbj4668 commented Feb 3, 2020

Was PYANG_XSLT_DIR set when you first ran pyang -f jsonxsl? This plugin will look for PYANG_XSLT_DIR and use that value, and that dir will then be found in the generated xslt script.

@mahen-g
Copy link
Author

mahen-g commented Feb 3, 2020

Thank you very much. I re-executed pyang -f jsonxsl and it worked without any errors.

pyang -f jsonxsl -o nw.xsl openconfig-network-instance.yang cisco-nx-openconfig-network-instance-deviations.yang

One follow up question if you can please answer. If I have the below payload (nw.xml) and try to execute the below to convert it to json
xsltproc -o nw.json nw.xsl nw.xml,

should it report an error for the value of the vlan-id below. As per the yang file, this property is supposed to be an uint16, whereas the below data instance has this value as a float.

<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:f050add5-3ccc-4cbc-9c65-b3f57bd42f1e">
    <data>
        <network-instances xmlns="http://openconfig.net/yang/network-instance">
            <network-instance>
                <name>default</name>
                <vlans>
                    <vlan>
                        <vlan-id>2.0</vlan-id>
                        <config>
                            <name>vlan-2</name>
                            <status>ACTIVE</status>
                            <vlan-id>2.0</vlan-id>
                        </config>
                        <state>
                            <name>vlan-2</name>
                            <status>ACTIVE</status>
                            <vlan-id>2</vlan-id>
                        </state>
                    </vlan>
                </vlans>
            </network-instance>
        </network-instances>
    </data>
</rpc-reply>

Thanks,

@llhotka
Copy link
Collaborator

llhotka commented Feb 4, 2020

In nw.xml you have the element <vlan-id>2.0</vlan-id>. If it is a problem, the conversion to JSON won't correct it. You should validate the XML instance data to catch this.

@mahen-g
Copy link
Author

mahen-g commented Feb 4, 2020

Thank you.

@llhotka llhotka closed this as completed Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants