XML 验证没有匹配的全局声明可用于验证根
XML validation No matching global declaration available for the validation root
我有 Cisco 为 IOS XE 路由器提供的 XML 架构。当在路由器的 cli 中 运行 命令 'show ip access-list test | format' 时,它吐出一个 XML 片段, 应该 验证此模式。然而事实并非如此。相反,我收到错误“:没有匹配的全局声明可用于验证根”
Cisco 提供的架构由 运行 'show xsd-format cli show ip access-lists' 提取,这里 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 推荐如下所示:
<?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>
路由器输出的XML片段是:
<?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>
模式是否损坏?我如何让它验证?
答案取决于您是想更改 XML 还是 XSD...
改变XML
根据您的 XSD,您的 XML 不应该在命名空间中,也不应该有多个 PermitFilter
元素。
因此,如果您希望保持 XSD 不变,以下更新的 XML 将针对您的 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>
改变XSD
您的 XML 在命名空间中并且有多个 PermitFilter
元素。
如果您希望保持 XML 不变,请将 targetNamespace
添加到您的 XSD,为该命名空间定义一个命名空间前缀,并在引用组件时使用该前缀命名空间。以下更新的 XSD 准确地显示了如何执行此操作并将成功验证您的 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>
我有 Cisco 为 IOS XE 路由器提供的 XML 架构。当在路由器的 cli 中 运行 命令 'show ip access-list test | format' 时,它吐出一个 XML 片段, 应该 验证此模式。然而事实并非如此。相反,我收到错误“:没有匹配的全局声明可用于验证根”
Cisco 提供的架构由 运行 'show xsd-format cli show ip access-lists' 提取,这里 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 推荐如下所示:
<?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>
路由器输出的XML片段是:
<?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>
模式是否损坏?我如何让它验证?
答案取决于您是想更改 XML 还是 XSD...
改变XML
根据您的 XSD,您的 XML 不应该在命名空间中,也不应该有多个 PermitFilter
元素。
因此,如果您希望保持 XSD 不变,以下更新的 XML 将针对您的 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>
改变XSD
您的 XML 在命名空间中并且有多个 PermitFilter
元素。
如果您希望保持 XML 不变,请将 targetNamespace
添加到您的 XSD,为该命名空间定义一个命名空间前缀,并在引用组件时使用该前缀命名空间。以下更新的 XSD 准确地显示了如何执行此操作并将成功验证您的 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>