xsd 验证失败 [英] xsd validation is failing

查看:34
本文介绍了xsd 验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 xml 验证失败,原因如下:

My xml validation is failing with the following reason:

无法执行目标 se.ericsson.jcat.ebs:xml-validation-plugin:1.0.2:validate (default) on project ebs-extensions: Unable to execute mojo: While parsing/home/xchoshu/latestWorkspace/ebs-extensions/src/main/resources/log4j2.xml,在文件:/home/xchoshu/latestWorkspace/ebs-extensions/src/main/resources/log4j.xsd,第 18 行,第 64 列:src-resolve.4.1:错误解析组件ConfigurationType".检测到ConfigurationType"没有命名空间,但无法从架构文档file:/home/xchoshu/latestWorkspace/ebs-extensions/src/main/resources/log4j.xsd"中引用没有目标命名空间的组件.如果ConfigurationType"打算具有命名空间,则可能需要提供前缀.如果打算ConfigurationType"没有命名空间,则应将没有命名空间"属性的导入"添加到file:/home/xchoshu/latestWorkspace/ebs-extensions/src/main/resources/log4j.xsd"'.-> [帮助 1]

Failed to execute goal se.ericsson.jcat.ebs:xml-validation-plugin:1.0.2:validate (default) on project ebs-extensions: Unable to execute mojo: While parsing /home/xchoshu/latestWorkspace/ebs-extensions/src/main/resources/log4j2.xml, at file:/home/xchoshu/latestWorkspace/ebs-extensions/src/main/resources/log4j.xsd, line 18, column 64: src-resolve.4.1: Error resolving component 'ConfigurationType'. It was detected that 'ConfigurationType' has no namespace, but components with no target namespace are not referenceable from schema document 'file:/home/xchoshu/latestWorkspace/ebs-extensions/src/main/resources/log4j.xsd'. If 'ConfigurationType' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'ConfigurationType' has no namespace, then an 'import' without a "namespace" attribute should be added to 'file:/home/xchoshu/latestWorkspace/ebs-extensions/src/main/resources/log4j.xsd'. -> [Help 1]

我的 xds 看起来像:

my xds looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://logging.apache.org/log4j/2.0/config" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="Configuration" type="ConfigurationType"/>
    <xs:complexType name="ConfigurationType">
        <xs:sequence>
            <xs:choice minOccurs="0" maxOccurs="1">
                <xs:element name="CustomLevels" type="CustomLevelsType"/>
                <xs:element name="CustomLevel" type="CustomLevelType"/>
            </xs:choice>
            <xs:element name="Properties" type="PropertiesType"/>
            <xs:choice minOccurs="0" maxOccurs="1">
                <xs:element name="Filters" type="FiltersType"/>
                <xs:element name="Filter" type="FilterType"/>
            </xs:choice>
            <xs:element name="ThresholdFilter" type="ThresholdFilterType"/>
            <xs:element name="Appenders" type="AppendersType"/>
            <xs:element name="Loggers" type="LoggersType"/>
        </xs:sequence>
        <xs:attribute name="packages" type="xs:string"/>
        <xs:attribute name="status" type="xs:string"/>
        <xs:attribute name="strict" type="xs:string"/>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="advertiser" type="xs:string"/>
        <xs:attribute name="schema" type="xs:string"/>
    </xs:complexType>
    <xs:complexType name="PropertiesType">
        <xs:sequence>
            <xs:element name="Property" type="PropertyType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="AppenderType">
        <xs:sequence>
            <xs:element name="Layout" type="LayoutType" minOccurs="0"/>
            <xs:choice minOccurs="0" maxOccurs="1">
                <xs:element name="Filters" type="FiltersType"/>
                <xs:element name="Filter" type="FilterType"/>
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="type" type="xs:string" use="required"/>
        <xs:attribute name="name" type="xs:string" use="required"/>
        <xs:attribute name="fileName" type="xs:string" use="optional"/>
    </xs:complexType>
    <xs:complexType name="RootType">
        <xs:sequence>
            <xs:element name="AppenderRef" type="AppenderRefType" minOccurs="1" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="level" type="xs:string"/>
    </xs:complexType>
    <xs:complexType name="PropertyType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="name" type="xs:string"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="KeyValuePairType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="key" type="xs:string"/>
                <xs:attribute name="value" type="xs:string"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="AppendersType">
        <xs:sequence>
            <xs:element name="Appender" type="AppenderType" minOccurs="1" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="AppenderRefType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="ref" type="xs:string" use="required"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="LoggerType">
        <xs:sequence>
            <xs:choice minOccurs="0" maxOccurs="1">
                <xs:element name="Filters" type="FiltersType"/>
                <xs:element name="Filter" type="FilterType"/>
            </xs:choice>
            <xs:element name="AppenderRef" type="AppenderRefType"/>
        </xs:sequence>
        <xs:attribute name="name" type="xs:string" use="required"/>
        <xs:attribute name="level" type="xs:string" use="optional"/>
        <xs:attribute name="additivity" type="xs:string" use="optional"/>
    </xs:complexType>
    <xs:complexType name="FilterType" mixed="true">
        <xs:sequence>
            <xs:element name="KeyValuePair" type="KeyValuePairType" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="type" type="xs:string" use="required"/>
        <xs:attribute name="level" type="xs:string" use="optional"/>
        <xs:attribute name="marker" type="xs:string" use="optional"/>
        <xs:attribute name="onMatch" type="xs:string" use="optional"/>
        <xs:attribute name="onMismatch" type="xs:string" use="optional"/>
    </xs:complexType>
    <xs:complexType name="FiltersType">
        <xs:sequence>
            <xs:element name="Filter" type="FilterType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="CustomLevelType">
        <xs:attribute name="name" type="xs:string" use="required"/>
        <xs:attribute name="intLevel" type="xs:string" use="required"/>
    </xs:complexType>
    <xs:complexType name="CustomLevelsType">
        <xs:sequence>
            <xs:element name="CustomLevel" type="CustomLevelType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="LoggersType" mixed="true">
        <xs:sequence>
            <xs:element name="Logger" type="LoggerType" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="Root" type="RootType" minOccurs="1" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="LayoutType" mixed="true">
        <xs:sequence>
            <xs:element name="Pattern" type="xs:string" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="type" type="xs:string" use="required"/>
        <xs:attribute name="pattern" type="xs:string" use="optional"/>
    </xs:complexType>
    <xs:complexType name="ThresholdFilterType">
        <xs:attribute name="level" type="xs:string" use="optional"/>
        <xs:attribute name="onMatch" type="xs:string" use="optional"/>
        <xs:attribute name="onMismatch" type="xs:string" use="optional"/>
    </xs:complexType>
</xs:schema>

我的 xml 看起来像:

my xml looks like:

 <Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://logging.apache.org/log4j/2.0/config"
    xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config https://ei-switching.rnd.ki.sw.ericsson.se/browser/jcat-bsp/log4j.xsd">

    <Appenders>
        <Console name="JCATDefaultConsoleAppender" target="SYSTEM_OUT"
            follow="true">
            <PatternLayout pattern="%d{default} %m [%t] %l%n%ex{full}" />
        </Console>
    </Appenders>

    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="JCATDefaultConsoleAppender" />
        </Root>
    </Loggers>

谁能帮我更正xsd.TIA

can anyone help me in correcting the xsd. TIA

问候,舒班卡

推荐答案

XSD 缺少命名空间声明 xmlns="http://logging.apache.org/log4j/2.0/config".这使得 XSD 有效.

The XSD is missing the namespace declaration xmlns="http://logging.apache.org/log4j/2.0/config". That makes the XSD valid.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns="http://logging.apache.org/log4j/2.0/config" 
           targetNamespace="http://logging.apache.org/log4j/2.0/config" 
           elementFormDefault="qualified" 
           attributeFormDefault="unqualified">
    <xs:element name="Configuration" type="ConfigurationType"/>

但是你的 XML 文件有很多问题

But then your XML files has lots of issues

您缺少必需元素 PropertiesThresholdFiltersAppenders 应至少包含 1 个 Appender(不是控制台)

You are missing the mandatory elements Properties and ThresholdFilters and Appenders should contain at least 1 Appender (not a Console)

示例文档看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML 2017 Liquid Studio - Data Designer Edition 15.0.0.6978 (https://www.liquid-technologies.com) -->
<ns:Configuration xmlns:ns="http://logging.apache.org/log4j/2.0/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config C:\Temp\StackOverflow\41177776\Schema.xsd" packages="string" status="string" strict="string" name="string" advertiser="string" schema="string">
    <ns:CustomLevels><!--optional-->
        <ns:CustomLevel name="string" intLevel="string" />
        <ns:CustomLevel name="string" intLevel="string" />
        <ns:CustomLevel name="string" intLevel="string" />
    </ns:CustomLevels>
    <ns:Properties>
        <ns:Property>string</ns:Property>
        <ns:Property>string</ns:Property>
    </ns:Properties>
    <ns:Filters><!--optional-->
        <ns:Filter type="string" level="string" marker="string" onMatch="string" onMismatch="string">
            <ns:KeyValuePair key="string" value="string">string</ns:KeyValuePair>
        </ns:Filter>
    </ns:Filters>
    <ns:ThresholdFilter level="string" onMatch="string" onMismatch="string" />
    <ns:Appenders>
        <ns:Appender type="string" name="string" fileName="string" />
        <ns:Appender type="string" name="string" />
    </ns:Appenders>
    <ns:Loggers>
        <ns:Logger name="string" level="string" additivity="string">
            <ns:AppenderRef ref="string">string</ns:AppenderRef>
        </ns:Logger>
        <ns:Root>
            <ns:AppenderRef ref="string">string</ns:AppenderRef>
        </ns:Root>
    </ns:Loggers>
</ns:Configuration>

这篇关于xsd 验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆