xml的schema的错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml的schema的错误相关的知识,希望对你有一定的参考价值。
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="grade">
<xsd:complexType>
<xsd:attribute name="year" type="xsd:string" />
<xsd:element name="class">
<xsd:complexType>
<xsd:attribute name="number" type="xsd:string" />
<xsd:element name="student">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="number" type="xsd:string" />
<xsd:element name="name" type="xsd:string" />
<xsd:element name="email" type="xsd:string" />
<xsd:element name="qq" type="xsd:string" />
<xsd:element name="address">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="province" type="xsd:string" />
<xsd:element name="city" type="xsd:string" />
<xsd:element name="street" type="xsd:string" />
<xsd:element name="mailcode" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:complexType>
</xsd:element>
</xsd:complexType>
</xsd:element>
</xsd:schema>
提示说<xsd:complexType>下的<xsd:element>无效
为什么啊~~ 应该怎么改啊
啊 太谢谢你帮我看看了 xml就是那样的 不过可能有几个class 每个class里面有几个student 这样可以吧?
需要作为<xsd:sequence>或者<xsd:choice>中的一个子节点出现在复杂类型元素(xsd:complexType)中。
***你的Schema中的错误***:
1. <xsd:element name="class">直接作为<xsd:complexType>的子节点了。
2. <xsd:element name="student">同样也是直接作为<xsd:complexType>的子节点了。
3.你希望class中可以出现多个student的问题,那么你需要将你对应的element节点加入 maxOccurs="unbounded" 的属性及其值。
例如:
<xsd:element name="student">
改为:
<xsd:element name="student" maxOccurs="unbounded">
(按照语境来说,grade下同样可以有多个class)
4.在复杂类型中<xsd:attribute>节点放在最后。
最终的正确Schema(*对你的稍加修改)
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="grade">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="class" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="student" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="number" type="xsd:string"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="email" type="xsd:string"/>
<xsd:element name="qq" type="xsd:string"/>
<xsd:element name="address">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="province" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="mailcode" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="number" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="year" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:schema> 参考技术A 首先你的所有属性添加格式都有问题...其次在属性添加中的属性本身最好是定的,这样可以体现出此元素的属性 <xsd:attribute name="year" type="xsd:string" />当中属性year很郁闷...你下面很多都是这样...
以后试试这样定义你的属性:<xs:attribute name='location' fixed='UK'/>
上面的xml应该是
<grade year=''>
<class number=''>
<student>
<number></number>
<name></name>
<email></email>
<qq></qq>
<address>
<province></province>
<city></city>
<street></street>
<mailcode></mailcode>
</address>
</student>
</class>
</grade>
今天太晚了,错误没细看,给你手写了一份,这个肯定不会报错了,明天有时间我再看看:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="grade">
<xs:complexType>
<xs:sequence>
<xs:element ref="class"/>
</xs:sequence>
<xs:attribute name="year" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="class">
<xs:complexType>
<xs:sequence>
<xs:element ref="student"/>
</xs:sequence>
<xs:attribute name="number" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element ref="number"/>
<xs:element ref="name"/>
<xs:element ref="email"/>
<xs:element ref="qq"/>
<xs:element ref="address"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element ref="province"/>
<xs:element ref="city"/>
<xs:element ref="street"/>
<xs:element ref="mailcode"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="mailcode" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="number" type="xs:string"/>
<xs:element name="province" type="xs:string"/>
<xs:element name="qq" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
</xs:schema>
最近比较忙,上网见少...对不起...刚刚看了下下面的回答,说的好啊...问题说的很对...maxOccurs="unbounded"这个是用于拓展的,如果你的schema编译要添加拓展方面的应用,是要写的。每个class中有多个student的话,只要每个的格式相同就可以编译,不管有几个,你写出一个就可以了。
Apache Camel Spring 配置错误 - 无法找到 XML 模式命名空间的 Spring NamespaceHandler [http://camel.apache.org/schema/
【中文标题】Apache Camel Spring 配置错误 - 无法找到 XML 模式命名空间的 Spring NamespaceHandler [http://camel.apache.org/schema/spring]【英文标题】:Apache Camel Spring configuration error - Unable to locate Spring NamespaceHandler for XML schema namespace [http://camel.apache.org/schema/spring] 【发布时间】:2010-12-03 00:20:39 【问题描述】:我发布了 spring.xml 文件的摘录和我得到的堆栈跟踪。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:util="http://www.springframework.org/schema/util" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring-2.0.0.xsd"
default-init-method="init" default-lazy-init="false">
<!-- import web service configuration -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<package>com.testdomain.testpackage</package>
</camelContext>
...
</beans>
抛出此异常:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://camel.apache.org/schema/spring]
Offending resource: class path resource [spring-config.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:281)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1294)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
at.......
有人可以帮忙解决问题吗?
【问题讨论】:
【参考方案1】:我错过了camel-spring.jar。 我添加了它,一切正常。
【讨论】:
【参考方案2】:如果使用 maven 程序集插件构建 JAR,请尝试使用 shade 插件 :)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.mypackage.mainclass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
【讨论】:
非常感谢!!你为我节省了很多时间!以上是关于xml的schema的错误的主要内容,如果未能解决你的问题,请参考以下文章
XML XSD 错误:org.xml.sax.SAXParseException:s4s-elt-schema-ns:元素“配置”的命名空间必须来自模式命名空间
解决:xml中出现“文档中根元素后面的标记必须格式正确。”的错误
mvn打包spring工程成jar时报Unable to locate Spring NamespaceHandler for XML schema namespace错误解决办法