我想使用JABX从XSD文件生成Java对象并执行脚本以使用不同的数据编组一些XML。
实际上,为了获取我的XSD文件,我使用了一个名为AGAPE的程序(法语工具来生成SEDA文件)。该软件生成RNG文件和XSD文件。我以为我可以使用RNG文件将他与Jing Trang翻译成XSD。但它看起来并不好,有一些语法错误(有点奇怪)......
所以我选择使用XML文件(我认为)主要是XSD。我只想使用JABX从这个文件创建Java对象。
但目前我无法做到,因为当我运行此命令时:
xjc.exe -nv -d C:\test3 C:\20150907.xsd
或20150907.xml ...
我收到此消息错误:
[ERROR] Unexpected <xsd:element> appears at line 10 column 57
ligne 10 sur file:/C:/20150907.xml
Echec de lanalyse dun schéma.
或
[ERROR] Unexpected <xsd:element> appears at line 10 column 57
ligne 10 sur file:/C:/20150907.xsd
Echec de lanalyse dun schéma.
所以我真的希望有人可以帮助我。
这是我的XML / XSD文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="fr:gouv:ae:archive:draft:standard_echange_v0.2"
xmlns:qdt="fr:gouv:ae:archive:draft:standard_echange_v0.2:QualifiedDataType:1"
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:6" attributeFormDefault="unqualified"
elementFormDefault="qualified" targetNamespace="fr:gouv:ae:archive:draft:standard_echange_v0.2"
version="1.1">
<xsd:element name="ArchiveTransfer">
<xsd:element fixed="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" minOccurs="0"
name="Comment" type="udt:TextType">
<xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
</xsd:element>
<xsd:element fixed="2015-09-07T00:00:00.0Z" name="Date" type="udt:DateTimeType">
<xsd:annotation>Date du dépôt</xsd:annotation>
</xsd:element>
<xsd:element name="TransferIdentifier" type="qdt:ArchivesIDType">
<xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
<xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
<xsd:annotation>Idfentifiant Unique attribué par Mnesys</xsd:annotation>
</xsd:element>
<xsd:element name="TransferringAgency" type="OrganizationType">
<xsd:element fixed="XXXXXXXXXXXXXXXXXXX" name="Identification" type="qdt:ArchivesIDType">
<xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
<xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
</xsd:element>
<xsd:element fixed="Banctec" minOccurs="1" name="Name" type="udt:TextType">
<xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
</xsd:element>
</xsd:element>
<xsd:element name="ArchivalAgency" type="OrganizationType">
<xsd:element fixed="YYYYYY" name="Identification" type="qdt:ArchivesIDType">
<xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
<xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
</xsd:element>
<xsd:element fixed=" XXXXXXX" minOccurs="0" name="Name"
type="udt:TextType">
<xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
</xsd:element>
</xsd:element>
<xsd:element maxOccurs="1" minOccurs="1" name="Integrity" type="HashCodeType"/>
<xsd:element maxOccurs="unbounded" name="Contains" type="ArchiveType">
<xsd:element fixed="ZZZZZZZZZZZZZZZ" minOccurs="1" name="ArchivalAgreement" type="qdt:ArchivesIDType">
<xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
<xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
</xsd:element>
<xsd:element fixed="AAAAAAA" minOccurs="0" name="ArchivalProfile" type="qdt:ArchivesIDType">
<xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
<xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
</xsd:element>
<xsd:element fixed="fr" maxOccurs="1" name="DescriptionLanguage" type="qdt:CodeLanguageType">
<xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
</xsd:element>
<xsd:element fixed="series" name="DescriptionLevel" type="qdt:CodeDescriptionLevelType">
<xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
</xsd:element>
<xsd:element fixed="AAAAAAAAAAAAAAAAAAAAAAA" name="Name" type="udt:TextType">
<xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
</xsd:element>
<xsd:element name="ContentDescription" type="ContentDescriptionType">
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
<xsd:element fixed="ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ" minOccurs="1"
name="Description" type="udt:TextType">
<xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
</xsd:element>
<xsd:element fixed="AAAAAAAAAAAAAAA" maxOccurs="1" minOccurs="1" name="FilePlanPosition"
type="qdt:ArchivesIDType">
<xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
<xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
</xsd:element>
<xsd:element fixed="EEEEEEEEEEEEE" maxOccurs="1" minOccurs="1" name="FilePlanPosition"
type="qdt:ArchivesIDType">
<xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
<xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
<xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
<xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
</xsd:element>
<xsd:element maxOccurs="1" minOccurs="1" name="Format" type="udt:TextType">
<xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
<xsd:annotation>PDF</xsd:annotation>
</xsd:element>
<xsd:element fixed="fr" maxOccurs="1" name="Language" type="qdt:CodeLanguageType">
<xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
</xsd:element>
<xsd:element fixed="2015-09-07" minOccurs="1" name="OldestDate" type="udt:DateType">
<xsd:annotation>Date de transfert</xsd:annotation>
</xsd:element>
</xsd:element>
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
<xsd:element maxOccurs="1" minOccurs="1" name="Appraisal" type="AppraisalRulesType">
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
<xsd:element fixed="conserver" name="Code" type="qdt:CodeAppraisalType">
<xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
</xsd:element>
<xsd:element fixed="P30Y" name="Duration" type="qdt:ArchivesDurationType"/>
<xsd:element fixed="2015-09-07" name="StartDate" type="udt:DateType">
<xsd:annotation>Date de transfert</xsd:annotation>
</xsd:element>
</xsd:element>
<xsd:element maxOccurs="1" minOccurs="1" name="AccessRestriction" type="AccessRestrictionRulesType">
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
<xsd:element fixed="AR061" name="Code" type="qdt:CodeAccessRestrictionType">
<xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
</xsd:element>
<xsd:element fixed="2015-09-07" name="StartDate" type="udt:DateType">
<xsd:annotation>Date de transfert</xsd:annotation>
</xsd:element>
</xsd:element>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Contains" type="ArchiveObjectType">
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
<xsd:element fixed="series" name="DescriptionLevel" type="qdt:CodeDescriptionLevelType">
<xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
</xsd:element>
<xsd:element fixed="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" name="Name"
type="udt:TextType">
<xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
</xsd:element>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Document" type="DocumentType">
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
<xsd:element name="Attachment" type="qdt:ArchivesBinaryObjectType">
<xsd:attribute name="format" type="clmDAFFileTypeCode:FileTypeCodeType" use="prohibited"/>
<xsd:attribute name="mimeCode" type="clmIANAMIMEMediaType:MIMEMediaTypeContentType"
use="prohibited"/>
<xsd:attribute name="encodingCode" type="clm60133:CharacterSetEncodingCodeContentType"
use="prohibited"/>
<xsd:attribute name="characterSetCode"
type="clmIANACharacterSetCode:CharacterSetCodeContentType" use="prohibited"/>
<xsd:attribute name="uri" type="xsd:anyURI" use="prohibited"/>
<xsd:attribute name="filename" type="xsd:string" use="prohibited"/>
<xsd:annotation>Objet-données (contenu binaire ou fichier joint)</xsd:annotation>
</xsd:element>
<xsd:element fixed="CDO" name="Type" type="qdt:CodeDocumentType">
<xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
</xsd:element>
</xsd:element>
</xsd:element>
</xsd:element>
<xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
</xsd:element>
</xsd:schema>
如果您更喜欢RNG格式,我会链接RNG文件。
<?xml version="1.0" encoding="UTF-8"?>
<rng:grammar xmlns:rng="http://relaxng.org/ns/structure/1.0"
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:6"
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:qdt="fr:gouv:ae:archive:draft:standard_echange_v0.2:QualifiedDataType:1"
xmlns:ccts="urn:un:unece:uncefact:documentation:standard:CoreComponentsTechnicalSpecification:2"
xmlns="fr:gouv:ae:archive:draft:standard_echange_v0.2" ns="fr:gouv:ae:archive:draft:standard_echange_v0.2"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<jaxb:schemaBindings>
<jaxb:package name="com.acme.foo"/>
</jaxb:schemaBindings>
<rng:start combine="choice">
<rng:ref name="ArchiveTransfer"/>
</rng:start>
<rng:define name="ArchiveTransfer">
<rng:element name="ArchiveTransfer">
<rng:ref name="ArchiveTransfer_N65537"/>
</rng:element>
</rng:define>
<rng:define name="ArchiveTransfer_N65537">
<rng:optional>
<rng:element name="Comment">
<rng:ref name="Comment_N65541"/>
</rng:element>
</rng:optional>
<rng:element name="Date">
<rng:value>2015-09-07T00:00:00.0Z</rng:value>
</rng:element>
<rng:element name="TransferIdentifier">
<rng:ref name="TransferIdentifier_N65562"/>
</rng:element>
<rng:element name="TransferringAgency">
<rng:ref name="TransferringAgency_N65594"/>
</rng:element>
<rng:element name="ArchivalAgency">
<rng:ref name="ArchivalAgency_N65640"/>
</rng:element>
<rng:element name="Integrity">
<rng:ref name="anyElement"/>
</rng:element>
<rng:oneOrMore>
<rng:element name="Contains">
<rng:ref name="Contains_N65694"/>
</rng:element>
</rng:oneOrMore>
</rng:define>
<rng:define name="TransferringAgency_N65594">
<rng:element name="Identification">
<rng:ref name="Identification_N65597"/>
</rng:element>
<rng:element name="Name">
<rng:ref name="Name_N65628"/>
</rng:element>
</rng:define>
<rng:define name="ArchivalAgency_N65640">
<rng:element name="Identification">
<rng:ref name="Identification_N65643"/>
</rng:element>
<rng:optional>
<rng:element name="Name">
<rng:ref name="Name_N65674"/>
</rng:element>
</rng:optional>
</rng:define>
<rng:define name="Contains_N65694">
<rng:element name="ArchivalAgreement">
<rng:ref name="ArchivalAgreement_N65698"/>
</rng:element>
<rng:optional>
<rng:element name="ArchivalProfile">
<rng:ref name="ArchivalProfile_N65730"/>
</rng:element>
</rng:optional>
<rng:element name="DescriptionLanguage">
<rng:ref name="DescriptionLanguage_N65762"/>
</rng:element>
<rng:element name="DescriptionLevel">
<rng:ref name="DescriptionLevel_N65775"/>
</rng:element>
<rng:element name="Name">
<rng:ref name="Name_N65787"/>
</rng:element>
<rng:element name="ContentDescription">
<rng:ref name="ContentDescription_N65798"/>
</rng:element>
<rng:element name="Appraisal">
<rng:ref name="Appraisal_N65923"/>
</rng:element>
<rng:element name="AccessRestriction">
<rng:ref name="AccessRestriction_N65963"/>
</rng:element>
<rng:zeroOrMore>
<rng:element name="Contains">
<rng:ref name="Contains_N65996"/>
</rng:element>
</rng:zeroOrMore>
</rng:define>
<rng:define name="ContentDescription_N65798">
<rng:element name="Description">
<rng:ref name="Description_N65801"/>
</rng:element>
<rng:element name="FilePlanPosition">
<rng:ref name="FilePlanPosition_N65813"/>
</rng:element>
<rng:element name="FilePlanPosition">
<rng:ref name="FilePlanPosition_N65846"/>
</rng:element>
<rng:element name="Format">
<rng:ref name="Format_N65879"/>
</rng:element>
<rng:element name="Language">
<rng:ref name="Language_N65893"/>
</rng:element>
<rng:element name="OldestDate">
<rng:value>2015-09-07</rng:value>
</rng:element>
</rng:define>
<rng:define name="Appraisal_N65923">
<rng:element name="Code">
<rng:ref name="Code_N65928"/>
</rng:element>
<rng:element name="Duration">
<rng:value>P30Y</rng:value>
</rng:element>
<rng:element name="StartDate">
<rng:value>2015-09-07</rng:value>
</rng:element>
</rng:define>
<rng:define name="AccessRestriction_N65963">
<rng:element name="Code">
<rng:ref name="Code_N65968"/>
</rng:element>
<rng:element name="StartDate">
<rng:value>2015-09-07</rng:value>
</rng:element>
</rng:define>
<rng:define name="Contains_N65996">
<rng:element name="DescriptionLevel">
<rng:ref name="DescriptionLevel_N66001"/>
</rng:element>
<rng:element name="Name">
<rng:ref name="Name_N66013"/>
</rng:element>
<rng:zeroOrMore>
<rng:element name="Document">
<rng:ref name="Document_N66024"/>
</rng:element>
</rng:zeroOrMore>
</rng:define>
<rng:define name="Document_N66024">
<rng:element name="Attachment">
<rng:ref name="Attachment_N66029"/>
</rng:element>
<rng:element name="Type">
<rng:ref name="Type_N66061"/>
</rng:element>
</rng:define>
<rng:define name="Comment_N65541">
<rng:value>AAAAAAAAAAAAAAAAA</rng:value>
</rng:define>
<rng:define name="TransferIdentifier_N65562">
<rng:data type="string"/>
</rng:define>
<rng:define name="Identification_N65597">
<rng:value>XXXXXXXXXXXXXXXXXXX</rng:value>
</rng:define>
<rng:define name="Name_N65628">
<rng:value>Banctec</rng:value>
</rng:define>
<rng:define name="Identification_N65643">
<rng:value>YYYYYYYYYYYYYYYYYYY</rng:value>
</rng:define>
<rng:define name="Name_N65674">
<rng:value>SAAAAAAAAAAAAAAAAAAAAA</rng:value>
</rng:define>
<rng:define name="ArchivalAgreement_N65698">
<rng:value>NNNNNNNNNNNNNNNNNNNNNNN</rng:value>
</rng:define>
<rng:define name="ArchivalProfile_N65730">
<rng:value>PMMMMMMMMMMMMMMMMMMMMMMMMMMMMM</rng:value>
</rng:define>
<rng:define name="DescriptionLanguage_N65762">
<rng:value>fr</rng:value>
<rng:attribute name="listVersionID">
<rng:value>edition 2009</rng:value>
</rng:attribute>
</rng:define>
<rng:define name="DescriptionLevel_N65775">
<rng:value>series</rng:value>
<rng:attribute name="listVersionID">
<rng:value>edition 2009</rng:value>
</rng:attribute>
</rng:define>
<rng:define name="Name_N65787">
<rng:value>AAAAAAAAAAAAAAAAAAAAAA</rng:value>
</rng:define>
<rng:define name="Description_N65801">
<rng:value>AAAAAAAAAAAAAAAAAAAAAAAAAAAA</rng:value>
</rng:define>
<rng:define name="FilePlanPosition_N65813">
<rng:value>BBBBBBBBBBBBBBBBB</rng:value>
</rng:define>
<rng:define name="FilePlanPosition_N65846">
<rng:value>CCCCCCCCCCCCCCCCCCCCCCC</rng:value>
</rng:define>
<rng:define name="Format_N65879">
<rng:data type="string"/>
</rng:define>
<rng:define name="Language_N65893">
<rng:value>fr</rng:value>
<rng:attribute name="listVersionID">
<rng:value>edition 2009</rng:value>
</rng:attribute>
</rng:define>
<rng:define name="Code_N65928">
<rng:value>conserver</rng:value>
<rng:attribute name="listVersionID">
<rng:value>edition 2009</rng:value>
</rng:attribute>
</rng:define>
<rng:define name="Code_N65968">
<rng:value>AR061</rng:value>
<rng:attribute name="listVersionID">
<rng:value>edition 2009</rng:value>
</rng:attribute>
</rng:define>
<rng:define name="DescriptionLevel_N66001">
<rng:value>series</rng:value>
<rng:attribute name="listVersionID">
<rng:value>edition 2009</rng:value>
</rng:attribute>
</rng:define>
<rng:define name="Name_N66013">
<rng:value>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</rng:value>
</rng:define>
<rng:define name="Attachment_N66029">
<rng:data type="string"/>
</rng:define>
<rng:define name="Type_N66061">
<rng:value>CDO</rng:value>
<rng:attribute name="listVersionID">
<rng:value>edition 2009</rng:value>
</rng:attribute>
</rng:define>
<rng:define name="anyElement">
<rng:zeroOrMore>
<rng:element>
<rng:anyName/>
<rng:zeroOrMore>
<rng:choice>
<rng:attribute>
<rng:anyName/>
</rng:attribute>
<rng:text/>
<rng:ref name="anyElement"/>
</rng:choice>
</rng:zeroOrMore>
</rng:element>
</rng:zeroOrMore>
</rng:define>
</rng:grammar>
答案 0 :(得分:2)
如果您在oXygen中运行XSD,Xerces会显示更具信息性的问题:
发动机名称:Xerces
开始发现了一个问题
严重性:错误
描述:s4s-elt-must-match.1:'ArchiveTransfer'的内容必须匹配(注释?,(simpleType | complexType)?,(unique | key | keyref)*))。从:element。
并显示xsd:element
后面有xsd:element
。由于这一次重复了很多次,删除这个元素无济于事。你需要仔细重新考虑设计,例如,沿着这些方面的东西(不理想,但可能适用于你的情况):
<xsd:element name="ArchiveTransfer" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="test1"></xsd:element>
<xsd:element name="test2"></xsd:element>
<xsd:element name="test3"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
考虑使用众多XSD设计工具之一以图形方式设计您的XSD,这样您就不必担心这些语法错误。
接下来,Xerces展示了一大堆其他错误,但首先是第一件事。
在修复之前,JABX将无法使用XSD。