XML validation No matching global declaration available for the validation root

Chris picture Chris · Apr 7, 2017 · Viewed 11.7k times · Source

I have an XML schema provided by Cisco for an IOS XE router. When running the command 'show ip access-list test | format' in the router's cli, it spits out an XML fragment that should validate against this schema. However it does not. Instead I get the error ": No matching global declaration available for the validation root"

Schema provided by Cisco extracted by running 'show xsd-format cli show ip access-lists' as recommended here http://www.cisco.com/c/en/us/td/docs/ios-xml/ios/xmlpi/command/xmlpi-cr-book/xmlpi-cr-p1.html#GUID-33CB3BAB-25B4-4FAD-9741-C7AFB483F701 is shown below:

<?xml version="1.0" encoding="UTF-8"?>
  <xsd:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
    <xsd:complexType name="ShowAccesslists_def">
      <xsd:sequence>
        <xsd:element ref="SpecVersion" minOccurs="0" />
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:element ref="Info" />
          <xsd:element name="Access-List" minOccurs="0" maxOccurs="1">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="Type" minOccurs="0" maxOccurs="1" type="xsd:string" />
                <xsd:element name="Name" minOccurs="0" maxOccurs="1" type="xsd:string" />
                <xsd:element name="DenyFilter" minOccurs="0" maxOccurs="1">
                  <xsd:complexType>
                    <xsd:sequence>
                      <xsd:element name="Filter" minOccurs="0" maxOccurs="1" type="xsd:string" />
                    </xsd:sequence>
                  </xsd:complexType>
                </xsd:element>
                <xsd:element name="PermitFilter" minOccurs="0" maxOccurs="1">
                  <xsd:complexType>
                    <xsd:sequence>
                      <xsd:element name="Filter" minOccurs="0" maxOccurs="1" type="xsd:string" />
                    </xsd:sequence>
                  </xsd:complexType>
                </xsd:element>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="SpecVersion" type="xsd:string" />
    <xsd:element name="Info" type="xsd:string" />
    <xsd:element name="ShowAccesslists" type="ShowAccesslists_def" />
  </xsd:schema>

The XML fragment the router spits out is:

<?xml version="1.0" encoding="UTF-8"?>
   <ShowAccesslists xmlns="ODM://built-in//show_access-lists">
    <Access-List>
      <Type>Extended IP</Type>
      <Name>test</Name>
      <PermitFilter>
        <Filter>10 permit ip any any</Filter>
      </PermitFilter>
      <PermitFilter>
        <Filter>20 permit tcp 0.0.0.1 255.255.255.0 any</Filter>
      </PermitFilter>
      <PermitFilter>
        <Filter>40 permit tcp host 10.22.1.128 10.11.79.0 0.0.0.255 eq domain</Filter>
      </PermitFilter>
      <PermitFilter>
        <Filter>50 permit tcp host 10.22.1.128 eq domain 10.11.79.0 0.0.0.255</Filter>
      </PermitFilter>
    </Access-List>
  </ShowAccesslists>

Is the schema broken? How do I get it to validate?

Answer

kjhughes picture kjhughes · Apr 7, 2017

Answer depends on whether you wish to change your XML or your XSD...

Change XML

According to your XSD, your XML should not be in a namespace and should not have multiple PermitFilter elements.

Therefore, if you wish to keep the XSD constant, the following updated XML will validate successfully against your XSD.

<?xml version="1.0" encoding="UTF-8"?>
<ShowAccesslists>
  <Access-List>
    <Type>Extended IP</Type>
    <Name>test</Name>
    <PermitFilter>
      <Filter>10 permit ip any any</Filter>
    </PermitFilter>
  </Access-List>
</ShowAccesslists>

Change XSD

Your XML is in a namespace and has multiple PermitFilter elements.

If you wish to keep the XML constant, add a targetNamespace to your XSD, define a namespace prefix for that namespace, and use the prefix when referencing components in that namespace. The following updated XSD shows exactly how to do this and will successfully validate your XML:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema elementFormDefault="qualified" attributeFormDefault="unqualified" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            xmlns:sal="ODM://built-in//show_access-lists" 
            targetNamespace="ODM://built-in//show_access-lists">
  <xsd:complexType name="ShowAccesslists_def">
    <xsd:sequence>
      <xsd:element ref="sal:SpecVersion" minOccurs="0" />
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:element ref="sal:Info" />
        <xsd:element name="Access-List" minOccurs="0" maxOccurs="1">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="Type" minOccurs="0" maxOccurs="1" type="xsd:string" />
              <xsd:element name="Name" minOccurs="0" maxOccurs="1" type="xsd:string" />
              <xsd:element name="DenyFilter" minOccurs="0" maxOccurs="1">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="Filter" minOccurs="0" maxOccurs="1" type="xsd:string" />
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="PermitFilter" minOccurs="0" maxOccurs="unbounded">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="Filter" minOccurs="0" maxOccurs="1" type="xsd:string" />
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:choice>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:element name="SpecVersion" type="xsd:string" />
  <xsd:element name="Info" type="xsd:string" />
  <xsd:element name="ShowAccesslists" type="sal:ShowAccesslists_def" />
</xsd:schema>