I'm looking to add a thirdparty target type to NLog.xsd. You would normally create a nlog.config file like this:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
...>
...
<targets>
<target name="file" xsi:type="File" />
</targets>
...
</nlog>
Now I want to add a new target:
<targets>
<target name="file" xsi:type="File" />
<target name="file" xsi:type="MyTarget" />
</targets>
XSD validation warns inside Visual Studio, since MyTarget isn't defined anywhere. I have tried adding MyTarget to NLog.xsd and reference the updated NLog.xsd, but then I get no intellisense what so ever:
<nlog xmlns="http://my-project.com/NLog.xsd" ...>
Any ideas how to implement this?
The custom Syslog target (NLog.Targets.Syslog) has created a custom XSD that extends the XSD of NLog.
Content:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NLog.Targets.Syslog"
elementFormDefault="qualified"
targetNamespace="http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sl="http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd"
xmlns:nlog="http://www.nlog-project.org/schemas/NLog.xsd">
<xs:import namespace="http://www.nlog-project.org/schemas/NLog.xsd" />
<xs:complexType name="Syslog">
<xs:complexContent>
<xs:extension base="nlog:Target">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="layout" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="enforcement" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="throttling" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="limit" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="strategy" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="delay" type="xs:decimal" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="limit" type="xs:integer" />
<xs:attribute name="strategy" type="xs:string" />
<xs:attribute name="delay" type="xs:decimal" />
</xs:complexType>
</xs:element>
<xs:element name="messageProcessors" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="splitOnNewLine" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="transliterate" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="replaceInvalidCharacters" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="truncateFieldsToMaxLength" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="truncateMessageTo" type="xs:integer" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="messageProcessors" type="xs:integer" />
<xs:attribute name="splitOnNewLine" type="xs:boolean" />
<xs:attribute name="transliterate" type="xs:boolean" />
<xs:attribute name="replaceInvalidCharacters" type="xs:boolean" />
<xs:attribute name="truncateFieldsToMaxLength" type="xs:boolean" />
<xs:attribute name="truncateMessageTo" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="messageCreation" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="facility" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="rfc" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="rfc3164" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="hostname" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="tag" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="hostname" type="xs:string" />
<xs:attribute name="tag" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="rfc5424" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="hostname" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="appName" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="procId" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="msgId" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="structuredData" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="1">
<xs:element name="fromEventProperties" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="sdElement" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="sdParam" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="value" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="sdId" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="disableBom" type="xs:boolean" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="hostname" type="nlog:SimpleLayoutAttribute" />
<xs:attribute name="appName" type="nlog:SimpleLayoutAttribute" />
<xs:attribute name="procId" type="nlog:SimpleLayoutAttribute" />
<xs:attribute name="msgId" type="nlog:SimpleLayoutAttribute" />
<xs:attribute name="disableBom" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="messageSend" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="protocol" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="udp" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="server" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="port" type="xs:integer" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="server" type="xs:string" />
<xs:attribute name="port" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="tcp" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="server" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="port" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="keepAlive" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="enabled" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="timeout" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="interval" type="xs:integer" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="enabled" type="xs:boolean" />
<xs:attribute name="timeout" type="xs:integer" />
<xs:attribute name="interval" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="reconnectInterval" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="useTls" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="framing" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="dataChunkSize" type="xs:integer" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="server" type="xs:string" />
<xs:attribute name="port" type="xs:integer" />
<xs:attribute name="reconnectInterval" type="xs:integer" />
<xs:attribute name="useTls" type="xs:boolean" />
<xs:attribute name="framing" type="xs:string" />
<xs:attribute name="dataChunkSize" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="layout" type="nlog:SimpleLayoutAttribute" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Usage: (this one is published on http://nlog-project.org/)
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sl="http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd">
and
<target xsi:type="sl:Syslog" name="syslog3164-tgt">
instead of
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
See also https://github.com/NLog/NLog.github.io/pull/56
Update: Visual Studio also needed this:
<nlog xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd" .. >
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 create reusable element declarations for a web service to insert and update. I have the following declarations:
<xs:complexType name="commonEntity">
<xs:sequence>
<xs:element name="id" type="snt-common:id" minOccurs="0"
maxOccurs="1" />
<xs:element name="createdByID" type="snt-common:id"
minOccurs="0" maxOccurs="1" />
<xs:element name="createDate" type="snt-common:dateTime"
minOccurs="0" maxOccurs="1" />
<xs:element name="modifiedByID" type="snt-common:id"
minOccurs="0" maxOccurs="1" />
<xs:element name="modifyDate" type="snt-common:dateTime"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="contact">
<xs:complexContent>
<xs:extension base="snt-common:commonEntity">
<xs:sequence>
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element id="update" name="ContactUpdateRequest">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="snt:contact">
<xs:sequence>
<xs:element name="id" type="snt-common:id" minOccurs="1"
maxOccurs="1" />
<xs:element name="modifyDate" type="snt-common:dateTime"
minOccurs="1" maxOccurs="1" />
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element id="insert" name="ContactInsertRequest">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="snt:contact">
<xs:sequence>
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
What I am trying to achieve is to create an insert and an update request, both of which are restrictions of contact. Contact in turn is an extension of commonEntity, which is used for all schemas as a base.
Insert works fine since there are no additional restrictions, but for update we require the id and modifyDate (this is how we enforce versioning) in the request. However, I get the following error when validating the schema:
Error for type '#AnonType_ContactUpdateRequest'. The particle of the type is not a valid restriction of the particle of
the base.
It seems as though I cannot restrict elements in the base element, commonEntity. I have tried reordering without success. Is this a nuance of XSD or am I missing something?
Update:
common.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" targetNamespace="http://predictivesolutions.com/schema/common"
xmlns:snt-common="http://predictivesolutions.com/schema/common"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc" elementFormDefault="qualified"
jaxb:version="2.0">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<xjc:javaType name="java.util.Calendar" xmlType="xs:dateTime"
adapter="com.ps.snt.ws.util.CalendarDateTimeAdapter" />
<xjc:javaType name="java.util.Calendar" xmlType="xs:date"
adapter="com.ps.snt.ws.util.CalendarDateAdapter" />
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
<!-- Creating this id type to use in the event we need to change to a long,
we can just do it here. -->
<xs:simpleType name="id">
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="dateTime">
<xs:restriction base="xs:dateTime">
<!-- 2013-11-06T11:17:17.043-05:00 -->
<xs:pattern value="\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d\d\d[+\-]\d\d:\d\d" />
<!-- 2013-11-06T11:17:17-05:00 -->
<xs:pattern value="\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d[+\-]\d\d:\d\d" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="string255">
<xs:restriction base="xs:string">
<xs:maxLength value="255" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="commonEntity">
<xs:sequence>
<xs:element name="id" type="snt-common:id" minOccurs="0"
maxOccurs="1" />
<xs:element name="createdByID" type="snt-common:id"
minOccurs="0" maxOccurs="1" />
<xs:element name="createDate" type="snt-common:dateTime"
minOccurs="0" maxOccurs="1" />
<xs:element name="modifiedByID" type="snt-common:id"
minOccurs="0" maxOccurs="1" />
<xs:element name="modifyDate" type="snt-common:dateTime"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>
contact.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://predictivesolutions.com/schema/v1_1" xmlns:snt="http://predictivesolutions.com/schema/v1_1"
xmlns:snt-common="http://predictivesolutions.com/schema/common"
elementFormDefault="qualified">
<xs:import namespace="http://predictivesolutions.com/schema/common"
schemaLocation="../common.xsd" />
<xs:complexType name="contact">
<xs:complexContent>
<xs:extension base="snt-common:commonEntity">
<xs:sequence>
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- For transporting data -->
<xs:element id="contact" name="contact" type="snt:contact">
</xs:element>
</xs:schema>
ContactService.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://predictivesolutions.com/schema/v1_1" xmlns:snt="http://predictivesolutions.com/schema/v1_1"
xmlns:snt-common="http://predictivesolutions.com/schema/common"
elementFormDefault="qualified">
<xs:import namespace="http://predictivesolutions.com/schema/common"
schemaLocation="../common.xsd" />
<xs:include schemaLocation="contact.xsd" />
<!-- Request/Response for inserting data -->
<xs:element id="insert" name="ContactInsertRequest">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="snt:contact">
<xs:sequence>
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
<!-- Request/Response for updating data -->
<xs:element id="update" name="ContactUpdateRequest">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="snt:contact">
<xs:sequence>
<xs:element name="id" type="snt-common:id" minOccurs="1"
maxOccurs="1" />
<xs:element name="modifyDate" type="snt-common:dateTime"
minOccurs="1" maxOccurs="1" />
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
I have a complex type called SafetyTiming and it has 2 elements value and margin. Both value and margin are based on a simpletype called Timing.
<xs:simpleType name="Timing">
<xs:restriction base="xs:unsignedInt">
<xs:minInclusive value="0" />
<xs:maxInclusive value="999" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="SafetyTiming">
<xs:sequence>
<xs:element name="Value" type="Timing" minOccurs="1" maxOccurs="1" />
<xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:element name="SafetyTimings">
<xs:complexType>
<xs:all>
<xs:element name="A" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="B" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="C" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="D" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
</xs:all>
</xs:complexType>
</xs:element>
This was fine until I found out that elements A and B need to have a minimum of 0 for simpletype "value" and, C and D a minimum of 1.
How can I elegantly solve this?
I tried the following but I think it looks rather messy and I wonder if there is a better solution.
<!--Safety timing type containing the timing value (minimum 0) and the value margin-->
<xs:complexType name="SafetyTiming_min0">
<xs:sequence>
<xs:element name="Value" type="Timing" minOccurs="1" maxOccurs="1" />
<xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<!--Safety timing type containing the timing value (minimum 1) and the value margin-->
<xs:complexType name="SafetyTiming_min1">
<xs:sequence>
<xs:element name="Value" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="Timing">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
You can derive a restricted type from Timing:
<xs:simpleType name="CDTiming">
<xs:restriction base="Timing">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
It's simpler to just create a new type for C and D which has the restricted Value:
<xs:complexType name="CDSafetyTiming">
<xs:sequence>
<xs:element name="Value" type="CDTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
You don't need to change anything for A and B since the original type already has a minimum of 0.
If you can change your original XSD, you can use the new type in the definition of your elements:
<xs:element name="SafetyTimings">
<xs:complexType>
<xs:all>
<xs:element name="A" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="B" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="C" type="CDSafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="D" type="CDSafetyTiming" minOccurs="1" maxOccurs="1" />
</xs:all>
</xs:complexType>
</xs:element>
I would like to validate this XML:
<meta>
<house>
<big ... />
<little ... />
<big ... />
</house>
<flat>
<red ... />
<red ... />
<yellow ... />
</flat>
</meta>
I wrote that.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="meta">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="house">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name='big' />
<xs:element name='little' />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="flat">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name='red'/>
<xs:element name='yellow'/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
But that does not validate my example.
Without 'house' or 'flat', and only meta, that worked.
Where could be my problem ?
Found !
The solution: add a "xs:choice" for each "xs:sequence", like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="meta">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element name="house">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element name='big' />
<xs:element name='little' />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="flat">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element name='red'/>
<xs:element name='yellow'/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I want to define a complex type that contains elements that may or may not exist, and also allows for additional undefined elements so I've got something like this:
<xs:complexType name="MyType">
<xs:sequence>
<xs:element name="A" type="xs:float" minOccurs="0" maxOccurs="1" />
<xs:element name="B" type="xs:float" minOccurs="0" maxOccurs="1" />
<xs:element name="C" type="xs:float" minOccurs="0" maxOccurs="1" />
<xs:any minOccurs="0" processContents="skip"/>
</xs:sequence>
</xs:complexType>
I don't want to force the order using <xs:sequence> so I want to change the <xs:sequence> to <xs:all> but then <xs:any> isn't allowed. Is there some way to accomplish this?
To allow any order, use this:
<xs:complexType name="MyType">
<xs:all minOccurs="1" maxOccurs="1">
<xs:element name="A" type="xs:float" minOccurs="0" maxOccurs="1" />
<xs:element name="B" type="xs:float" minOccurs="0" maxOccurs="1" />
<xs:element name="C" type="xs:float" minOccurs="0" maxOccurs="1" />
</xs:all>
</xs:complexType>
But then, you can't have an <any> inside an <all>.
Nor can you have them both inside one type, either directly or as an extension.