I am using the below dependencies in my pom.xml
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.1.14</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>2.0.2</version>
<scope>compile</scope>
</dependency>
binding.xjb :
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="../../../../xsd/icmarchitecture/mom/log/RetrieveExecutionInfo.xsd" node="/xs:schema">
<jxb:globalBindings>
<jxb:javaType name="com.pcm.icm.architecture.util.Timestamp" xmlType="icm:Timestamp" printMethod="toXsdString" parseMethod="create"/>
</jxb:globalBindings>
RetrieveExecutionInfo.xsd :
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v2004 rel. 2 U (http://www.xmlspy.com) by pcm (pcm) -->
<!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by bbl (bbl) -->
<xs:schema
targetNamespace="http://www.pcm.com/icm/architecture/mom/log/payload"
xmlns="http://www.pcm.com/icm/architecture/mom/log/payload"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://www.pcm.com/icm/architecture/status/payload"
xmlns:icm="http://www.pcm.com/icm/architecture/common/payload"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xs:import
namespace="http://www.pcm.com/icm/architecture/status/payload"
schemaLocation="../../status/status.xsd"/>
<xs:import
namespace="http://www.pcm.com/icm/architecture/common/payload"
schemaLocation="../../common/ICMTypedefinitions.xsd"/>
<xs:complexType name="FilterKeyValueType">
<xs:annotation>
<xs:documentation>Filter on key value pair</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="Key" type="xs:string"/>
<xs:element ref="Operator"/>
<xs:element name="Value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="FilterKey">
<xs:annotation>
<xs:documentation>Filter on Key</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="Operator"/>
<xs:element name="Value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="KeyValueType">
<xs:annotation>
<xs:documentation>Key value pair</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="Key" type="xs:string"/>
<xs:element name="Value" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Operator">
<xs:annotation>
<xs:documentation>Operator for a filter</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="greater_equal"/>
<xs:enumeration value="greater"/>
<xs:enumeration value="less"/>
<xs:enumeration value="less_equal"/>
<xs:enumeration value="not_equal"/>
<xs:enumeration value="equal"/>
<xs:enumeration value="like"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="FilterService">
<xs:annotation>
<xs:documentation>Filter on service</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="ServiceAddress"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="FilterTimestamp">
<xs:annotation>
<xs:documentation>Filter on timestamp</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="Operator"/>
<xs:element name="Value" type="icm:Timestamp"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ExecutionInfoElement">
<xs:annotation>
<xs:documentation>Reply element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="ServiceAddress"/>
<xs:element name="RequestTimestamp" type="icm:Timestamp" minOccurs="0"/>
<xs:element name="DurationInMillis" type="xs:long" minOccurs="0"/>
<xs:element name="RequestLogMsgId" type="xs:string" minOccurs="0"/>
<xs:element name="KeyValue" type="KeyValueType" minOccurs="0" maxOccurs="999"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="FilterMillis">
<xs:annotation>
<xs:documentation>Filter on millis</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="Operator"/>
<xs:element name="Value" type="xs:long"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ServiceAddress">
<xs:annotation>
<xs:documentation>Service address</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="service" type="xs:string" minOccurs="0"/>
<xs:element name="protocol" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="RetrieveExecutionInfoRq">
<xs:annotation>
<xs:documentation>Request to get execution info elements</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="FilterService" minOccurs="0" maxOccurs="999"/>
<xs:element ref="FilterTimestamp" minOccurs="0" maxOccurs="999"/>
<xs:element ref="FilterMillis" minOccurs="0" maxOccurs="999"/>
<xs:element name="AndFilterKeyValue" type="FilterKeyValueType" minOccurs="0" maxOccurs="999"/>
<xs:element name="OrFilterKeyValue" type="FilterKeyValueType" minOccurs="0" maxOccurs="999"/>
<xs:element ref="FilterKey" minOccurs="0" maxOccurs="999"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="RetrieveExecutionInfoRs">
<xs:annotation>
<xs:documentation>Reply with execution info elements</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="statusInfo" type="ns1:statusType"/>
<xs:element ref="ExecutionInfoElement" minOccurs="0" maxOccurs="999"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Maven version - 3.1
Java Version - 1.7
Error :
org.xml.sax.SAXParseException; systemId: file:/C:/Data/NewGitRepo/TestICMGitRepo/ICMTrunk/icmarchitecture/src/main/resources/xjb/icmarchitecture/mom/log/binding.xjb; lineNumber: 7; columnNumber: 136; UndeclaredPrefix: Cannot resolve 'icm:Timestamp' as a QName: the prefix 'icm' is not declared.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
org.xml.sax.SAXParseException; systemId: file:/binding.xjb; lineNumber: 7; columnNumber: 136; cvc-attribute.3: The value 'icm:Timestamp' of attribute 'xmlType' on element 'jxb:javaType' is not valid with respect to its type, 'QName'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
I am getting the above exception when do maven clean install through eclipse with java 1.7 compiler
But If i change the java compiler to 1.8 its working fine. but i want to deploy this jar in JBoss server which is having the java 1.7 version.
Please help on this. Thanks in Advance.
You should declare your icm prefix in the bindings file.
Add xmlns:icm="<URI of the icm namespace here>" to the root element.
This has less to do with JAXB and more with XML. JAXB expects a "qualified name" as #xmlType. "Qualified name" means the prefix must be defined and point to the correct namespace.
Related
I am currently working in CICS web services and new to XML/WSDL concepts. I got a WSDL file from middleware team and tried to execute the DFHWS2LS utility to create a COBOL language structure from that WSDL. I am getting the following error and was not able to fix this. And suggestions?
DFHPI9027E The XML parser has found an error: "XSD: The attribute
'minOccurs' is not permitted" at line "1" and column"19,015" in
document "file:/AIGNDVR/DEVL1/ELC/WSDL/MakeOkToSellServiceSOAP.wsdl".
DFHPI9558E ERRORS have been generated processing file
"/AIGNDVR/DEVL1/ELC/WSDL/ MakeOkToSellServiceSOAP.wsdl".
XML:
<?xml version="1.0" encoding="EBCDIC-CP-US"?>
<wsdl:definitions name="MakeOkToSell" targetNamespace="http://MakeOkToSell/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:impl="http://MakeOkToSell/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl/" >
<wsdl:types>
<xs:schema targetNamespace="http://MakeOkToSell/">
<xs:element name="MakeOkToSellRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="RequestSystemName" type="xs:string"/>
<xs:element name="RequestSystemGearID" type="xs:int"/>
<xs:element name="transactionIdentifier" type="xs:string" minOccurs="0"/>
<xs:element name="OkToSellDetails">
<xs:complexType>
<xs:sequence>
<xs:element name="CompanyCode" type="xs:string" minOccurs="0"/>
<xs:element name="PolicyNumber" type="xs:string" minOccurs="0"/>
<xs:element name="UplineID" type="xs:string" minOccurs="0"/>
<xs:element name="SSN" type="xs:int" minOccurs="0"/>
<xs:element name="NPN" type="xs:string" minOccurs="0"/>
<xs:element name="AgencyCode" type="xs:string" minOccurs="0"/>
<xs:element name="First5digitSSNandLastName" type="xs:string" minOccurs="0"/>
<xs:element name="RequestType" type="xs:string" minOccurs="0"/>
<xs:element name="AgentPositionID" type="xs:string" minOccurs="0"/>
<xs:element name="PrimaryAgentID" type="xs:string" minOccurs="0"/>
<xs:element name="AgentFirstName" type="xs:string" minOccurs="0"/>
<xs:element name="AgentLastName" type="xs:string" minOccurs="0"/>
<xs:element name="ApplicationState" type="xs:string"/>
<xs:element name="ProductID" type="xs:string"/>
<xs:element name="ProductType" type="xs:string" minOccurs="0"/>
<xs:element name="ApplicationReceivedDate" type="xs:date"/>
<xs:element name="ApplicationSignedDate" type="xs:date"/>
<xs:element name="GrossPremium" type="xs:decimal" minOccurs="0"/>
<xs:element name="NetPremium" type="xs:decimal" minOccurs="0"/>
<xs:element name="AdditionalData" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Property" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string" minOccurs="1">
<xs:attribute type="xs:string" name="name"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="MakeOkToSellResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="UID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="EvaluationStatus">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="TaskID" type="xs:string" minOccurs="0"/>
<xs:element name="ErrorDetails" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ErrorCode" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ErrorType" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ErrorMessage" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ObjectType" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ObjectID" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Warnings" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="WarningCode" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="WarningType" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="WarningMessage" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ObjectType" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ObjectID" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="MakeOkToSellFault">
<xs:complexType>
<xs:all>
<xs:element name="errorMessage" type="xs:string" minOccurs="0"/>
<xs:element name="errorCode" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="MakeOkToSellRequest">
<wsdl:part element="impl:MakeOkToSellRequest" name="parameters"/>
</wsdl:message>
<wsdl:message name="MakeOkToSellResponse">
<wsdl:part element="impl:MakeOkToSellResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="MakeOkToSellFault">
<wsdl:part element="impl:MakeOkToSellFault" name="parameters"/>
</wsdl:message>
<wsdl:portType name="MakeOkToSellService">
<wsdl:operation name="MakeOkToSell">
<wsdl:input message="impl:MakeOkToSellRequest" name="MakeOkToSellRequest"/>
<wsdl:output message="impl:MakeOkToSellResponse" name="MakeOkToSellResponse"/>
<wsdl:fault message="impl:MakeOkToSellFault" name="MakeOkToSellFault"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MakeOkToSellServiceBinding" type="impl:MakeOkToSellService">
<wsaw:UsingAddressing wsdl:required="false"/>
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="MakeOkToSell">
<wsdlsoap:operation soapAction="urn:MakeOkToSell"/>
<wsdl:input name="MakeOkToSellRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="MakeOkToSellResponse">
<wsdlsoap:body use="literal"/>enter code here
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MakeOkToSellService">
<wsdl:documentation>WSDL File for MakeOkToSell</wsdl:documentation>
<wsdl:port binding="impl:MakeOkToSellServiceBinding" name="MakeOkToSellServiceSOAP">
<wsdlsoap:address location="http://localhost:9080/MakeOkToSellService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
DFHWS2Ls is presumably being run from JCL on the MF. I note that the WSDL document has an encoding of EBCDIC-CP-US, which makes sense, but that's not the encoding we're viewing it in. I presume that the WSDL has either been pretty-printed here for legibility, or a transcoding error caused everything to flow into one long line in the EBCDIC version.
I've loaded the WSDL up in a WSDL validator (I used the validator in the Eclipse Web Tools project). It reported the same problem, only this time at line 39: <xs:extension base="xs:string" minOccurs="1"> . I'm not sure what the WSDL author was trying to achieve, but that minOccurs is invalid in XML, I'd suggest deleting it.
[edited to correct markup on XML tags]
I am trying to map XSD to another XSD that has some different elements in Smooks. When I add both XSDs in Smooks it is not allowing me to map the elements. Is it possible in Smooks to map two different XSDs?
XSD1:CDM
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:RequestResponse="http://example.com/cdm/xsd/Person_01_RequestResponse_001"
xmlns:prsn="http:/example.com/cdm/xsd/Person_01"
attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="http://example.com/cdm/xsd/Person_01_RequestResponse_001">
<!-- ************ import Employee Model ************ -->
<xs:import namespace="http://example.com/cdm/xsd/Person_01" schemaLocation="Person_01.xsd"/>
<!-- ********************************************* -->
<!-- Request Response Types -->
<!-- ********************************************* -->
<!-- For CreatePerson operation-->
<xs:element name="CreatePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonDetail" type="prsn:Person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CreatePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For GetPerson operation-->
<xs:element name="GetPersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonId" type="prsn:PersonIdType" nillable="false"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetPersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="prsn:Person" minOccurs="0" nillable="true"/>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XSD2:LEGACY
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:RequestResponse="http://example.com/xsd/Person_01_RequestResponse_001"
xmlns:prsn="http://example.com/xsd/Person_01"
attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="http://example.com/xsd/Person_01_RequestResponse_001">
<!-- ************ import Employee Model ************ -->
<xs:import namespace="http://example.com/xsd/Person_01" schemaLocation="Person_01.xsd"/>
<!-- ********************************************* -->
<!-- Request Response Types -->
<!-- ********************************************* -->
<!-- For CreatePerson operation-->
<xs:element name="CreatePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonDetail" type="prsn:Person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CreatePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For GetPerson operation-->
<xs:element name="GetPersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="CNIC" type="xs:string" nillable="false" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetPersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="prsn:Person" minOccurs="0" nillable="true"/>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For UpdatePerson operation-->
<xs:element name="UpdatePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="prsn:Person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="UpdatePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For deletePerson operation-->
<xs:element name="DeletePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="CNIC" type="xs:string" nillable="false" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DeletePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Hi again SO community,
got another request regarding how to define an XSD schema correctly.
Given I have an XML file like:
<?xml version="1.0" encoding="UTF-8" ?>
<transformation xmlns="http://www.denktmit.de/pdi/ktr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.w3.org/2001/XMLSchema-instance
./test.xsd">
<info>
<name>TrafoName</name>
<description>TrafoDescription</description>
</info>
<changedby>LastUser</changedby>
<step>
<type>FileInput</type>
<description>FileInput Step description</description>
<FileInputParameterOne>FileInputParam</FileInputParameterOne>
<another>1</another>
</step>
<step>
<type>Select</type>
<description>Select Step description</description>
<SelectParameterOne>SelectParameterOne</SelectParameterOne>
<SelectParameterTwo>SelectParameterTwo</SelectParameterTwo>
<another>2</another>
</step>
</transformation>
This resembles the style of the transformation files as produced by http://community.pentaho.com/projects/data-integration/
As you can see, each step contains several sequence nodes on top
<type>Select</type>
<description>Select Step description</description>
and on bottom:
<another>2</another>
In between, arbitrary complex xml subtrees may occur. But what exactely max occur is determined by the value in "type". The use case is to store specific configurations for concrete Java classes, that all implement an interface, defining getters/setter for "type", "description" and "another" and defining addtional object structure themself. It would also be sufficient to neglect the order, as long as all the elements, needed for a specific class are somehow present.
I already read:
How to group types & subtypes in XSD
xsd: How to extend a type with an unordered list of elements
Use <xs:all> in XML schema's complexType?
xsd: How to extend a type with an unordered list of elements
And I tried something like
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.denktmit.de/pdi/ktr" elementFormDefault="qualified"
attributeFormDefault="unqualified" xmlns="http://www.denktmit.de/pdi/ktr">
<xs:element name="transformation">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="step" type="fileInputStep"></xs:element>
<xs:element name="step" type="selectStep"></xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="stepComplexType" abstract="true"></xs:complexType>
<xs:complexType name="fileInputStep">
<xs:complexContent>
<xs:extension base="stepComplexType">
<xs:sequence>
<xs:element name="type" minOccurs="1"
maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="description" type="xs:string"
minOccurs="1" maxOccurs="1"></xs:element>
<xs:element name="FileInputParameterOne" type="xs:string">
</xs:element>
<xs:element name="another" type="xs:int" minOccurs="1"
maxOccurs="1"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="selectStep">
<xs:complexContent>
<xs:extension base="stepComplexType">
<xs:sequence>
<xs:element name="type" minOccurs="1"
maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="Select"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="description" type="xs:string"
minOccurs="1" maxOccurs="1"></xs:element>
<xs:element minOccurs="1" name="SelectParameterOne"
type="xs:string">
</xs:element>
<xs:element minOccurs="1" name="SelectParameterTwo"
type="xs:string">
</xs:element>
<xs:element name="another" type="xs:int" minOccurs="1"
maxOccurs="1"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
But it is not working, telling me:
Multiple annotations found at this line: validation against this
schema, ambiguity would be created for those two particles.
- Start tag of element
- cos-element-consistent: Error for type '#AnonType_transformation'. Multiple elements with name 'step', with different types, appear in
the model group.
Any ideas?
You may use xsd Group. Here's an sample for your reference
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="transformation">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="step" type="stepType"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="stepComplexType" abstract="true"></xs:complexType>
<xs:group name="selectParamGroup">
<xs:sequence>
<xs:element name="SelectParameterOne" type="xs:string" minOccurs="1" maxOccurs="1">
</xs:element>
<xs:element name="SelectParameterTwo" type="xs:string" minOccurs="1" maxOccurs="1">
</xs:element>
</xs:sequence>
</xs:group>
<xs:group name="paramGroup">
<xs:choice>
<xs:element name="FileInputParameterOne" type="xs:string">
</xs:element>
<xs:group ref="selectParamGroup">
</xs:group>
</xs:choice>
</xs:group>
<xs:complexType name="stepType">
<xs:complexContent>
<xs:extension base="stepComplexType">
<xs:sequence>
<xs:element name="type" minOccurs="1"
maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="description" type="xs:string"
minOccurs="1" maxOccurs="1"></xs:element>
<xs:group ref="paramGroup"></xs:group>
<xs:element name="another" type="xs:int" minOccurs="1"
maxOccurs="1"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
XML:
<?xml version="1.0" encoding="UTF-8" ?>
<transformation>
<step>
<type>FileInput</type>
<description>FileInput Step description</description>
<FileInputParameterOne>FileInputParam</FileInputParameterOne>
<another>1</another>
</step>
<step>
<type>Select</type>
<description>Select Step description</description>
<SelectParameterOne>SelectParameterOne</SelectParameterOne>
<SelectParameterTwo>SelectParameterTwo</SelectParameterTwo>
<another>2</another>
</step>
</transformation>
I would like to write a XSD element that permit something like that :
<CustomFields>
<CustomField id="1">some text data</CustomField>
<CustomField id="2">some text data</CustomField>
</CustomFields>
But I have some restrictions : I have to restrict the text (maxLenght = 36). And I would like to be impossible to have 2 CustomField with the same id.
So far I wrote this, but it not what I want :
<xs:element name="CustomFields" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomField" minOccurs="0" maxOccurs="20">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:integer" use="required"></xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Thanks for any help.
Regards.
You could use following attempt
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:simpleType name="restrictedString">
<!-- Make a new type to be a "descendant" of string-->
<xs:restriction base="xs:string">
<xs:maxLength value="36"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="CustomFields">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomField" minOccurs="0" maxOccurs="20">
<xs:complexType>
<xs:simpleContent>
<!-- reference new type you declared above -->
<xs:extension base="restrictedString">
<xs:attribute name="id" type="xs:integer" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<!-- Restrict #id to be unique-->
<xs:unique name="id_uq">
<xs:selector xpath="CustomField"/>
<xs:field xpath="#id"/>
</xs:unique>
</xs:element>
</xs:schema>
Below is the sample xml which has multiple <rulex> that starts with sequence 1 and it can end up to many rule like <rule1> , <rule2>, <rule3> etc....
<?xml version="1.0" encoding="UTF-8"?>
<AddressChange_181>
<rules>
<rule1>
<conditions>xya</conditions>
<response_path>abc</response_path>
</rule1>
<rule2>
<conditions>xxxx</conditions>
<response_path>aaaa</response_path>
</rule2>
<rule3>
<conditions>yyyyy</conditions>
<response_path>ffff</response_path>
</rule3>
<rule4>
<conditions>zzzz</conditions>
<response_path>yyyy</response_path>
</rule4>
<default>
<response_path>uuuuu</response_path>
</default>
</rules>
</AddressChange_181>
Below is the schema where i tried creating dynamic <rulex> element name for the above xml.
when i generate xml from this schema i do not get the same xml format as above xml.
can you please let me know how to create schema with multiple element name that starts with a sequence number.
My requirement is to add more than one rule (<rule1>,<rule2>,<rule3> etc...) in xml file and this xml file should be validated against schema.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mock_rule_list">
<xs:complexType>
<xs:sequence>
<xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rules">
<xs:complexType>
<xs:sequence>
<xs:element ref="rule" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="default" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rule">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="xs:anyType">
<xs:pattern value="rule/d{1,3}"></xs:pattern>
</xs:restriction>
</xs:simpleContent>
<xs:sequence>
<xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
<xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="default">
<xs:complexType>
<xs:sequence>
<xs:element ref="response_path"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="conditions" type="xs:string">
</xs:element>
<xs:element name="response_path" type="xs:string"/>
</xs:schema>
Thanks,
Madhu
There is no way to define such a structure using XSD if the number of ruleX tags is arbitrarily defined. If you can constrain the upper bound to a maximum, and you really have to stick with ruleX naming convention, than you can define a complex type such as ruleType, then a bunch of rule1, rule2,... , ruleN elements of that type - I would call this messy... I wouldn't recommend this.
XSD (with a maximum of 6):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mock_rule_list">
<xs:complexType>
<xs:sequence>
<xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rules">
<xs:complexType>
<xs:sequence>
<xs:element ref="rule1" minOccurs="0"/>
<xs:element ref="rule2" minOccurs="0"/>
<xs:element ref="rule3" minOccurs="0"/>
<xs:element ref="rule4" minOccurs="0"/>
<xs:element ref="rule5" minOccurs="0"/>
<xs:element ref="rule6" minOccurs="0"/>
<xs:element ref="default"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ruleType">
<xs:sequence>
<xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
<xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:element name="default">
<xs:complexType>
<xs:sequence>
<xs:element ref="response_path"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="conditions" type="xs:string">
</xs:element>
<xs:element name="response_path" type="xs:string"/>
<xs:element name="rule1" type="ruleType"/>
<xs:element name="rule2" type="ruleType"/>
<xs:element name="rule3" type="ruleType"/>
<xs:element name="rule4" type="ruleType"/>
<xs:element name="rule5" type="ruleType"/>
<xs:element name="rule6" type="ruleType"/>
</xs:schema>
Alternatively, you could have a tag named "rule" with a #sequence attribute.
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mock_rule_list">
<xs:complexType>
<xs:sequence>
<xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rules">
<xs:complexType>
<xs:sequence>
<xs:element ref="rule" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="default"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="SequenceKey">
<xs:selector xpath="rule"/>
<xs:field xpath="#sequence"/>
</xs:unique>
</xs:element>
<xs:complexType name="ruleType">
<xs:sequence>
<xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
<xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="sequence" type="xs:int" use="required"/>
</xs:complexType>
<xs:element name="default">
<xs:complexType>
<xs:sequence>
<xs:element ref="response_path"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="conditions" type="xs:string">
</xs:element>
<xs:element name="response_path" type="xs:string"/>
<xs:element name="rule" type="ruleType"/>
</xs:schema>
Sample XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rule sequence="1">
<conditions>conditions1</conditions>
<response_path>response_path1</response_path>
</rule>
<rule sequence="2">
<conditions>conditions2</conditions>
<response_path>response_path2</response_path>
</rule>
<default>
<response_path>response_path1</response_path>
</default>
</rules>
Or it could also be that one could simply use the index of the <rule/> within the parent collection .