我正在研究开源项目SAML1.1,从sourceid官网下载的代码,用的是xmlbeans1.0.jar,没有任何问题。
但是如果我升级成xmlbeans2.3.0.jar,就会出现下面这个错误,
error: cvc-elt.1: Invalid type
at org.sourceid.config.ConfigUtil.getXml(ConfigUtil.java:136)
at org.sourceid.config.ConfigUtil.getXmlFromResource(ConfigUtil.java:97)
求高人指点啊!!!
下面是出错的xml文件及其schema文件:
<Participants xmlns="http://www.sourceid.org/2004/03/participants">
<!-- AP participants -->
<Participant name="authenticator">
<Activity instance="getStatements"
classname="org.sourceid.saml11.participant.ap.AuthenticatorPWorker"
methodname="getStatements"/>
<Activity instance="processQuery"
classname="org.sourceid.saml11.participant.ap.AuthenticatorPWorker"
methodname="processQuery"/>
<Activity instance="updateAssertions"
classname="org.sourceid.saml11.participant.ap.AuthenticatorPWorker"
methodname="updateAssertions"/>
</Participant>
<!-- AP finalizers -->
<Participant name="apProtocol">
<Activity instance="finalizer"
classname="org.sourceid.saml11.participant.ap.Finalizer"
methodname="finalizeApProtocol"/>
</Participant>
<Participant name="apSso">
<Activity instance="finalizer"
classname="org.sourceid.saml11.participant.ap.Finalizer"
methodname="finalizeApSso"/>
</Participant>
<!-- RP participants -->
<Participant name="ap">
<Activity instance="processRequest"
classname="org.sourceid.saml11.participant.rp.ApPWorker"
methodname="processRequest"/>
</Participant>
<!-- RP finalizers -->
<Participant name="rpProtocol">
<Activity instance="finalizer"
classname="org.sourceid.saml11.participant.rp.Finalizer"
methodname="finalizeRpProtocol"/>
</Participant>
<Participant name="rpSso">
<Activity instance="finalizer"
classname="org.sourceid.saml11.participant.rp.Finalizer"
methodname="finalizeRpSso"/>
</Participant>
</Participants>
<schema xmlns='http://www.w3.org/2001/XMLSchema' version='1.0'
xmlns:part='http://www.sourceid.org/2004/03/participants'
targetNamespace="http://www.sourceid.org/2004/03/participants"
elementFormDefault='qualified'>
<element name='Participants' type='part:ParticipantsType'/>
<element name='Participant' type='part:ParticipantType'/>
<element name='Activity' type='part:ActivityType'/>
<complexType name='ParticipantsType'>
<sequence>
<element ref='part:Participant' maxOccurs='unbounded'/>
</sequence>
</complexType>
<complexType name='ParticipantType'>
<sequence>
<element ref='part:Activity' maxOccurs='unbounded'/>
</sequence>
<attribute name='name' type='string'/>
</complexType>
<complexType name='ActivityType'>
<attribute name='instance' type='NMTOKEN'/>
<attribute name='classname' type='string'/>
<attribute name='methodname' type='string'/>
</complexType>
</schema>
但是如果我升级成xmlbeans2.3.0.jar,就会出现下面这个错误,
error: cvc-elt.1: Invalid type
at org.sourceid.config.ConfigUtil.getXml(ConfigUtil.java:136)
at org.sourceid.config.ConfigUtil.getXmlFromResource(ConfigUtil.java:97)
求高人指点啊!!!
下面是出错的xml文件及其schema文件:
<Participants xmlns="http://www.sourceid.org/2004/03/participants">
<!-- AP participants -->
<Participant name="authenticator">
<Activity instance="getStatements"
classname="org.sourceid.saml11.participant.ap.AuthenticatorPWorker"
methodname="getStatements"/>
<Activity instance="processQuery"
classname="org.sourceid.saml11.participant.ap.AuthenticatorPWorker"
methodname="processQuery"/>
<Activity instance="updateAssertions"
classname="org.sourceid.saml11.participant.ap.AuthenticatorPWorker"
methodname="updateAssertions"/>
</Participant>
<!-- AP finalizers -->
<Participant name="apProtocol">
<Activity instance="finalizer"
classname="org.sourceid.saml11.participant.ap.Finalizer"
methodname="finalizeApProtocol"/>
</Participant>
<Participant name="apSso">
<Activity instance="finalizer"
classname="org.sourceid.saml11.participant.ap.Finalizer"
methodname="finalizeApSso"/>
</Participant>
<!-- RP participants -->
<Participant name="ap">
<Activity instance="processRequest"
classname="org.sourceid.saml11.participant.rp.ApPWorker"
methodname="processRequest"/>
</Participant>
<!-- RP finalizers -->
<Participant name="rpProtocol">
<Activity instance="finalizer"
classname="org.sourceid.saml11.participant.rp.Finalizer"
methodname="finalizeRpProtocol"/>
</Participant>
<Participant name="rpSso">
<Activity instance="finalizer"
classname="org.sourceid.saml11.participant.rp.Finalizer"
methodname="finalizeRpSso"/>
</Participant>
</Participants>
<schema xmlns='http://www.w3.org/2001/XMLSchema' version='1.0'
xmlns:part='http://www.sourceid.org/2004/03/participants'
targetNamespace="http://www.sourceid.org/2004/03/participants"
elementFormDefault='qualified'>
<element name='Participants' type='part:ParticipantsType'/>
<element name='Participant' type='part:ParticipantType'/>
<element name='Activity' type='part:ActivityType'/>
<complexType name='ParticipantsType'>
<sequence>
<element ref='part:Participant' maxOccurs='unbounded'/>
</sequence>
</complexType>
<complexType name='ParticipantType'>
<sequence>
<element ref='part:Activity' maxOccurs='unbounded'/>
</sequence>
<attribute name='name' type='string'/>
</complexType>
<complexType name='ActivityType'>
<attribute name='instance' type='NMTOKEN'/>
<attribute name='classname' type='string'/>
<attribute name='methodname' type='string'/>
</complexType>
</schema>
谢谢你的回答。因为项目中别的功能需要用到新版本的xmlbeans.jar。源码官网上现在用的是xmlbeans1.0.jar
已经debug过了,就是在if的地方,elementType.isNoType()是false,感觉可能是xml和schema的匹配方面有问题吧,或者是xml的type有问题,但是已经好几天了,试过很多方法都没解决 //
// the no-type is always invalid (even if there is an xsi:type)
// if (elementType.isNoType())
{
emitFieldError( event, XmlErrorCodes.ELEM_LOCALLY_VALID$NO_TYPE,
null, event.getName(), null, null,
XmlValidationError.ELEMENT_TYPE_INVALID, null); _eatContent = 1;
}
像上面说的schema,版本不一样都会不一样。。所以可能要改其他的代码中。。一般不用修改。。版本都是向下兼容。。
以前没弄过schema这些,所以不知道你说的schema版本是具体指哪个?xmlns还是targetNamespace,还是别的?
另外,这个是跟什么比较是不是一样的?
谢谢!
你说的是不是<?xml version="1.0" encoding="UTF-8"?>,这个加和不加会报同样的错。
难道这个version要高一些?
上面是说,schema里面使用的dtd 或者 xsd 里面指向的 验证文件有误,高的一般会兼容低。
据我所知,schema就是.xsd文件吧,一楼里最下面贴出了xml对应的.xsd文件,你帮忙看下有什么不对的地方。
谢谢!
2
3 * Improved Saxon support, Saxon 8.8 became the recommended version
4 * Added options to control use of CDATA sections when saving to XML
5 * Added support for QNames in Schema annotations
6 * Added support for new encodings: UTF-16LE, UTF-16BE, CP936/GBK.
7 * Fix: overzealous whitespace cropping after parsing entities like & (XMLBEANS-274)
8 * Fix: selectPath() with setXqueryCurrentNodeVar() option does not work for Saxon (XMLBEANS-276)
9 * Fix: synchronization problem with array setters
10 * Fix: Saver$TextSaver.replace method throws java.lang.ArrayIndexOutOfBoundsException (XMLBEANS-209)
11 * Fix: QNameSet generated by QNameSet.forArray(QName[]) can't be unioned with other QNameSets (XMLBEANS-290)
12 * Fix: java.lang.ArrayIndexOutOfBoundsException when saving XML (XMLBEANS-291)
13 * Fix: XQuery gives wrong result with Saxon 8.6.1 (XMLBEANS-275)
14 * Fix: bug during generation of complex types with simple content
15 * Fix: improved error handling during loading of Schema type system
16 * Fix: bugs in Duration serialization
17 * Fix: XMLCursor.getTextValue()
18 * Fix: Remove year zero from GDate, GDateBuilder and XmlCalendar per
19 XMLSchema spec D.3.2
20
21 Changes in v2.2.0 since v2.1.0:
22
23 * Allow polymorphism in Extension Interfaces Feature
24 * Fix for circular buffer in TextSaver
25 * Tuned synchronization for multithreaded validation
26 * Updated to the latest XMLSchema.xsd - January 25, 2006
27 * Better QName validation
28 * Fix insertion positions when using substitution groups with arrays
29 * Updated XmlBeans to work with SaxonB-8.6.1 in place of SaxonB8.1
30 * Fix for regex validation in multi-threaded, multi-processor environment
31 * Fix for schema compilation error when restricting complex type with simple content
32 * Implemented XMLInputStream interface for saving a store
33 * XQuery external variable binding support
34 * Various other bug fixes
35
36
37 Changes in v2.1.0 since v2.0.0:
38
39 * Fixed the issue whereby some IDEs would have problems with the TypeSystemHolder class being generated in the classes directory
40 * Better integration with Maven
41 * Implemented support for ID/IDREF in DTDs via DOM's .getElementByID()
42 * Integrated a patch that makes XmlBeans work in a sandboxed environment
43 * Added the ability to control entitization of characters when saving documents
44 * Fixed issue with memory reclamation in multi-threaded environments, which was delayed too much so it could be mistaken for a memory leak
45 * Added numerous new test cases and performance tests
46 * Continued improving performance, especially in the DOM support and XmlCursor areas
47 * Added column numbers support in our snapshot of Piccolo; validation and XMLSchema error reporting benefit from this and is of course usable from user code
48 * Line/column number is now also available for end-tags
49 * Solved a legal inconsistency surrounding our use of JSR173 APIs
50 * Fixed a lot of reported issues in various areas of the product
51
52
53 Changes in v2.0.0 since v2.0.0-beta1:
54
55 * many performance related changes, especialy in the DOM and Cursor areas
56 * rewrite of the <xs:redefine> support
57 * Completed the implementation of Filer
58 * new documentation on xs:any, validation plus updates of the old docs
59 * many bug fixes, including perm gen memory bug
60
61
62 Changes in v2.0.0-beta1:
63
64 * new store implementation, including native DOM implementation
65 * Piccolo is now the default parser.XmlOptions.setLoadUseXMLReader (XMLReader xmlReader) can be used when a diffrent parser is required.
66 * Sample xml generation from an schema file
67 * New failfast behavior for simple types, more consistent
68 * EntityResolver is setable in SchemaCompiler
69 * XPath 2.0 and Xquery support through Saxon
70 * java 1.5 generics for array properties added to generated source
71 * Simplified working with substitution groups by adding XmlObject.substitute() method
72 * "-noVDoc" command-line option for scomp to skip validation of <xs:documentation> contents
73 * uniform access to the getSourceName() method in Schema Object Model
74 * Cleaned up schema compilation APIs with a XmlBeans.compileXmlBeans()
75 * Added error codes and improved validation error messages
76 * Changed .xsb format and loading strategy to improve performance
77 * Ability to pass URLs instead of Files for Wsdl/Schemas
78 * Added option to pass in "##local" to -allowmdef
79 * Inst2xsd: support for xsi:nil and qname fix.
80 * adding getCurrentElementSchemaType in Validator for finding schema types of elements with xsi:type attribute
81 * adding ValidatingInfoXMLStreamReader for PSVI access on XMLStreamReaders
82 * added Location to streaming validation errors
83 * Instance 2 schema tool
84 * Support for arbitrarily nesting <xsd:redefine>s
85 * New "schema book" mechanism allowing one to tag user data on Schema Object Model entities
86 * Add ability for XmlSaxHandler to insert books while loading
87 * Added a diff utility that compares two jars (or directories) containing compiled Schema types
88 * Interface and pre-post extensions
89 * Enabled ValidatingXMLStreamReader to start validating from both current and next event in the XMLStreamReader
90 * Functionality to retrieve xml validation errors programatically
91 * Added saver options to not save xml decl
92 * Added ability to compile Schemas containing references to SOAP11 encoded arrays
93 * selectChildren and selectAttributes for dynamic getters and some wildcard scenarios
94 * Location in ValidatingXmlStreamReader
95 * Added a wrapper over jsr173's XMLStreamReader
96 * Added support for default value in XMLStreamReaderExt interface and implementation
97 * Adding typed value for QName case in the Validator
98 * Adding an utility for validation of simple schema types
99 * Improved the Validator to ofer PSVI info
100 * Exposed some of the XMLSchema validator functionality in the public interfaces
101 * Added support for XML Catalog, based on Apache Commons CatalogResolver
102 * Added XMLStreamReaderExt an extention of XMLStreamReader which alowes getting strongly typed java values from a stream
103 * Adds support for annotations in XMLSchema
104 * Added JSR 173 support
105
106 * performance tests
107 * various feature tests
108 * samples and documentation
109 * packaging, licencing changeshttp://svn.apache.org/viewvc/xmlbeans/trunk/CHANGES.txt?view=up&pathrev=540734
刚刚改成2006试了一下,没有效果,仍旧有那个error
这里有源码,可以对号版本调试看看但这句话可能有用:
XMLBeans 2.x.x is source compatible with version 1. When upgrading, you should recompile XML schemas used in your application.
问题下午已经解决了,参照这个链接
http://mail-archives.apache.org/mod_mbox/xmlbeans-user/200501.mbox/%[email protected]%3E
把schema重新生成一遍就可以了。非常感谢你的回答。你的思路是对的