<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic YDK Python decode/encode and XML attributes in Tools</title>
    <link>https://community.cisco.com/t5/tools/ydk-python-decode-encode-and-xml-attributes/m-p/4667725#M1012</link>
    <description>&lt;P&gt;Hello community,&lt;/P&gt;&lt;P&gt;When using YDK python decode and encode modules to convert XML Junos configurations into JSON, XML attributes do not get reflected in the JSON configuration. Whilst I understand this could be a limitation JSON not supporting extensive semantics I would like to understand if this is supported in YDK and or if there may be a way to not lose XML attributes.&lt;/P&gt;&lt;P&gt;Example of XML snipped where the XML attribute is inactive="inactive". This is used in Junos to declare a stanza present in the configuration as deactivated or not active.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;bgp&amp;gt;
&amp;lt;group inactive="inactive"&amp;gt;
  &amp;lt;name&amp;gt;EBGP-TEST&amp;lt;/name&amp;gt;
  &amp;lt;type&amp;gt;external&amp;lt;/type&amp;gt;
  &amp;lt;import&amp;gt;IMPORT-IPV4&amp;lt;/import&amp;gt;
  &amp;lt;export&amp;gt;EXPORT-IPV4&amp;lt;/export&amp;gt;
  &amp;lt;peer-as&amp;gt;1111&amp;lt;/peer-as&amp;gt;
  &amp;lt;neighbor&amp;gt;
    &amp;lt;name&amp;gt;192.168.1.1&amp;lt;/name&amp;gt;
  &amp;lt;/neighbor&amp;gt;
&amp;lt;/group&amp;gt;
&amp;lt;/bgp&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;JSON translated code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;      "bgp": {
        "group": [
          {
            "name": "EBGP-TEST",
            "type": "external",
            "import": [
              "IMPORT-IPV4"
            ],
            "export": [
              "EXPORT-IPV4"
            ],
            "peer-as": "1111",
            "neighbor": [
              {
                "name": "192.168.1.1"
              }
            ]
          }
        ]
      },&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Python code used to decode/encode is the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from ydk.providers import CodecServiceProvider
from ydk.services import CodecService

CODEC = CodecService()

JSON_PROVIDER = CodecServiceProvider(type='json')
XML_PROVIDER = CodecServiceProvider(type='xml')

def test_yang_xml_to_yml (xml_file):

    mode = 'rb'

    with open(xml_file, mode) as xml_in:
        config_xml = xml_in.read()


    decoded_xml = CODEC.decode(XML_PROVIDER, config_xml)
    yang_json = CODEC.encode(JSON_PROVIDER, decoded_xml)

    return yang_json&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
    <pubDate>Thu, 11 Aug 2022 10:29:30 GMT</pubDate>
    <dc:creator>ldacol</dc:creator>
    <dc:date>2022-08-11T10:29:30Z</dc:date>
    <item>
      <title>YDK Python decode/encode and XML attributes</title>
      <link>https://community.cisco.com/t5/tools/ydk-python-decode-encode-and-xml-attributes/m-p/4667725#M1012</link>
      <description>&lt;P&gt;Hello community,&lt;/P&gt;&lt;P&gt;When using YDK python decode and encode modules to convert XML Junos configurations into JSON, XML attributes do not get reflected in the JSON configuration. Whilst I understand this could be a limitation JSON not supporting extensive semantics I would like to understand if this is supported in YDK and or if there may be a way to not lose XML attributes.&lt;/P&gt;&lt;P&gt;Example of XML snipped where the XML attribute is inactive="inactive". This is used in Junos to declare a stanza present in the configuration as deactivated or not active.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;bgp&amp;gt;
&amp;lt;group inactive="inactive"&amp;gt;
  &amp;lt;name&amp;gt;EBGP-TEST&amp;lt;/name&amp;gt;
  &amp;lt;type&amp;gt;external&amp;lt;/type&amp;gt;
  &amp;lt;import&amp;gt;IMPORT-IPV4&amp;lt;/import&amp;gt;
  &amp;lt;export&amp;gt;EXPORT-IPV4&amp;lt;/export&amp;gt;
  &amp;lt;peer-as&amp;gt;1111&amp;lt;/peer-as&amp;gt;
  &amp;lt;neighbor&amp;gt;
    &amp;lt;name&amp;gt;192.168.1.1&amp;lt;/name&amp;gt;
  &amp;lt;/neighbor&amp;gt;
&amp;lt;/group&amp;gt;
&amp;lt;/bgp&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;JSON translated code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;      "bgp": {
        "group": [
          {
            "name": "EBGP-TEST",
            "type": "external",
            "import": [
              "IMPORT-IPV4"
            ],
            "export": [
              "EXPORT-IPV4"
            ],
            "peer-as": "1111",
            "neighbor": [
              {
                "name": "192.168.1.1"
              }
            ]
          }
        ]
      },&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Python code used to decode/encode is the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from ydk.providers import CodecServiceProvider
from ydk.services import CodecService

CODEC = CodecService()

JSON_PROVIDER = CodecServiceProvider(type='json')
XML_PROVIDER = CodecServiceProvider(type='xml')

def test_yang_xml_to_yml (xml_file):

    mode = 'rb'

    with open(xml_file, mode) as xml_in:
        config_xml = xml_in.read()


    decoded_xml = CODEC.decode(XML_PROVIDER, config_xml)
    yang_json = CODEC.encode(JSON_PROVIDER, decoded_xml)

    return yang_json&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 10:29:30 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-python-decode-encode-and-xml-attributes/m-p/4667725#M1012</guid>
      <dc:creator>ldacol</dc:creator>
      <dc:date>2022-08-11T10:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: YDK Python decode/encode and XML attributes</title>
      <link>https://community.cisco.com/t5/tools/ydk-python-decode-encode-and-xml-attributes/m-p/4667887#M1013</link>
      <description>&lt;P&gt;Could you please attach YANG models that are used to encode the payload.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 15:04:27 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-python-decode-encode-and-xml-attributes/m-p/4667887#M1013</guid>
      <dc:creator>ygorelik</dc:creator>
      <dc:date>2022-08-11T15:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: YDK Python decode/encode and XML attributes</title>
      <link>https://community.cisco.com/t5/tools/ydk-python-decode-encode-and-xml-attributes/m-p/4667890#M1014</link>
      <description>&lt;P&gt;YANG models are the Juniper models taken from &lt;A href="https://github.com/Juniper/yang/tree/master/18.4/18.4R3/junos/conf" target="_blank"&gt;https://github.com/Juniper/yang/tree/master/18.4/18.4R3/junos/conf&lt;/A&gt; and bundles generated from the models above. BGP is covered under junos-conf-protocols &lt;A href="https://yangcatalog.org/yang-search/module_details/junos-conf-protocols" target="_blank"&gt;https://yangcatalog.org/yang-search/module_details/junos-conf-protocols&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 15:13:18 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-python-decode-encode-and-xml-attributes/m-p/4667890#M1014</guid>
      <dc:creator>ldacol</dc:creator>
      <dc:date>2022-08-11T15:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: YDK Python decode/encode and XML attributes</title>
      <link>https://community.cisco.com/t5/tools/ydk-python-decode-encode-and-xml-attributes/m-p/4668525#M1015</link>
      <description>&lt;P&gt;The YDK does not process XML attributes other than &lt;EM&gt;xmlns&lt;/EM&gt;, which defines element's namespace. It is not designed to do the translation from XML to JSON and backward. For this you would need to use some other tools, which are available in open source space.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 16:24:31 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-python-decode-encode-and-xml-attributes/m-p/4668525#M1015</guid>
      <dc:creator>ygorelik</dc:creator>
      <dc:date>2022-08-12T16:24:31Z</dc:date>
    </item>
  </channel>
</rss>

