Can anyone point me as to why the unique element in my XSD is not forcing unique-ness? This should throw an error because the last ScreenResult element does not contain a unique value for the Type attribute. I should also note that I'm truly after forcing one of each Type within ScreenResults (ScreenResult is required to exist 3 times, there are 3 types of screens and I am requiring unique-ness) so if there is a better way to accomplish that, I'm all for that as well.
Thank you.
Here is my XML snippet:
<ScreenResults>
<ScreenResult Type="Screen Type A">1</ScreenResult>
<ScreenResult Type="Screen Type B">1</ScreenResult>
<ScreenResult Type="Screen Type B">2</ScreenResult>
</ScreenResults>
Here is my XSD snippet (also note that my original XSD snippets span multiple files but I have verified all of my namespaces are correct):
<xs:element name="ScreenResults" type="import:ScreenResults" minOccurs="0" maxOccurs="1">
<xs:unique name="UniqueScreenResults">
<xs:selector xpath="ScreenResult" />
<xs:field xpath="#Type" />
</xs:unique>
</xs:element>
<!--============ ScreenResults =============-->
<xs:complexType name="ScreenResults">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="ScreenResult" minOccurs="3" maxOccurs="3">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="enum:ScreenResult">
<xs:attribute name="Type" type="enum:ScreenType" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<!--============= ScreenType =============-->
<xs:simpleType name="ScreenType">
<xs:restriction base='xs:token'>
<xs:enumeration value='Screen Type A' >
<xs:annotation>
<xs:documentation>1</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value='Screen Type B' >
<xs:annotation>
<xs:documentation>2</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value='Screen Type C' >
<xs:annotation>
<xs:documentation>3</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<!--============ ScreenResult ============-->
<xs:simpleType name="ScreenResult">
<xs:restriction base='xs:token'>
<xs:enumeration value='1' >
<xs:annotation>
<xs:documentation>Positive</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value='2' >
<xs:annotation>
<xs:documentation>Negative</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value='3' >
<xs:annotation>
<xs:documentation>Not administered</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
I'm posting my solution for anyone else who runs into this problem.
Although I had asserted that all of my namespaces were correct, that was, of course the problem. All of the namespaces were correct except on the unique element itself.
I erroneously assumed that the unique element would not need to prefix a namespace as it was within the context. But that is not the case. Since I did declare a default namespace for the file, I still needed the prefix.
So my only change, and the solution, is as follows:
<xs:element name="ScreenResults" type="import:ScreenResults" minOccurs="0" maxOccurs="1">
<xs:unique name="UniqueScreenResults">
<xs:selector xpath="import:ScreenResult" />
<xs:field xpath="#Type" />
</xs:unique>
</xs:element>
Related
Working with XML 1.1 in Oxygen XML Editor version 23.1.
Originally I wandted to make an xsd schema that can have a complexType-element with a child-element, an extension and a bunch of attributes. A first possible solution I was able to get here but figured out it didn't fit to my problem, because the child-element itself consists of several elements and attributes which makes the original approach invalid, causing the error message: "The content type of a derived type and that of its base must both be mixed or both be element-only. Type 'complexTypeContent' is mixed, but its base type is not".
To my problem itself: The aim is for the child-element random to only be used when the attribute until has the value 'random'. So in the end a XML-file like this should be valid:
<instruction>
<type repeat='1' until='random'><random start='1' end='6'/>Dice Roll</type>
</instruction>
Instead - if the attribute until has not the value "random" - the element random must not be allowed. So something like this should be forbidden:
<instruction>
<type repeat='1' until='2'><random start='1' end='6'/>Dice Roll</type>
</instruction>
With help from here I was able to modify my xsd-scheme to something like this. But as already stated, it doesn't compile without an error message:
<xs:element name="root">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="instruction" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="type">
<xs:alternative test="#until = 'random'" type="complexTypeContent"/>
<xs:alternative type="simpleTypeContent"/>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="complexTypeContent" mixed="true">
<xs:complexContent>
<xs:extension base="simpleTypeContent">
<xs:sequence>
<xs:element name="random" type="random" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="random">
<xs:attribute name="start">
<xs:simpleType>
<xs:restriction base="xs:integer"/>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="end">
<xs:simpleType>
<xs:restriction base="xs:integer"/>
</xs:simpleType>
</xs:attribute>
<xs:assert test="#start le #end"/>
</xs:complexType>
<xs:complexType name="simpleTypeContent" mixed="true">
<xs:simpleContent>
<xs:extension base="type2">
<xs:attribute name="until">
<xs:simpleType>
<xs:union memberTypes="type2 annotation xs:integer until"/>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="condition">
<xs:simpleType>
<xs:union memberTypes="type2 annotation extended"/>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="repeat" type='xs:integer'/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="type2">
<xs:restriction base="xs:string">
<xs:enumeration value="Dice Roll"/>
<xs:enumeration value="Wait"/>
<xs:enumeration value="Repeat"/>
<xs:enumeration value="Double Roll"/>
<xs:enumeration value="Instruction"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="until">
<xs:restriction base="xs:string">
<xs:enumeration value="end"/>
<xs:enumeration value="random"/>
<xs:enumeration value="Instruction"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="annotation">
<xs:restriction base="xs:string">
<xs:enumeration value="rolltwice"/>
<xs:enumeration value="halfcount"/>
<xs:enumeration value="doublecount"/>
<xs:enumeration value="roll-"/>
<xs:enumeration value="roll+"/>
<xs:enumeration value="numberChange"/>
<xs:enumeration value="NoNumberChange"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="extended">
<xs:restriction base="xs:string">
<xs:enumeration value="noRolling"/>
<xs:enumeration value="noEven"/>
<xs:enumeration value="noUneven"/>
<xs:enumeration value="stopped"/>
</xs:restriction>
</xs:simpleType>
The error messages I had now all imply that this solution is invalid because of the not mixed content of simpleTypeContent or because it has simpleContent which cannot be derived from the complex content of complexTypeContent. So, how do I get it working? I cannot figure out any working solution for the problem I am facing.
As far as I understand, XSD (not even 1.1) doesn't offer a way to restrict the mixed content text to some simple type, so the only way, if you really need that single element together with a certain list of values seems to be an assertion; that means, unfortunately, you need to duplicate the values you also want for an attribute.
So some (slightly adapted, see my comment about the `#until = 'random' check) sample schema would be
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
<xs:element name="root">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="instruction" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="type">
<xs:alternative test="#until = 'random'" type="complexTypeContent"/>
<xs:alternative type="simpleTypeContent"/>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="complexTypeContent" mixed="true">
<xs:complexContent>
<xs:extension base="simpleTypeContent">
<xs:sequence>
<xs:element name="random" type="random" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="random">
<xs:attribute name="start">
<xs:simpleType>
<xs:restriction base="xs:integer"/>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="end">
<xs:simpleType>
<xs:restriction base="xs:integer"/>
</xs:simpleType>
</xs:attribute>
<xs:assert test="#start le #end"/>
</xs:complexType>
<xs:complexType name="simpleTypeContent" mixed="true">
<xs:attribute name="until">
<xs:simpleType>
<xs:union memberTypes="type2 annotation xs:integer until"/>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="condition">
<xs:simpleType>
<xs:union memberTypes="type2 annotation extended"/>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="repeat" type='xs:integer'/>
<xs:assert test=". = ('Dice Roll', 'Wait', 'Repeat', 'Double Roll', 'Instruction')"/>
</xs:complexType>
<xs:simpleType name="type2">
<xs:restriction base="xs:string">
<xs:enumeration value="Dice Roll"/>
<xs:enumeration value="Wait"/>
<xs:enumeration value="Repeat"/>
<xs:enumeration value="Double Roll"/>
<xs:enumeration value="Instruction"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="until">
<xs:restriction base="xs:string">
<xs:enumeration value="end"/>
<xs:enumeration value="random"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="annotation">
<xs:restriction base="xs:string">
<xs:enumeration value="rolltwice"/>
<xs:enumeration value="halfcount"/>
<xs:enumeration value="doublecount"/>
<xs:enumeration value="roll-"/>
<xs:enumeration value="roll+"/>
<xs:enumeration value="numberChange"/>
<xs:enumeration value="NoNumberChange"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="extended">
<xs:restriction base="xs:string">
<xs:enumeration value="noRolling"/>
<xs:enumeration value="noEven"/>
<xs:enumeration value="noUneven"/>
<xs:enumeration value="stopped"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
and that then makes the first instruction in below sample (also slightly adapted as there was a spelling difference between the schema and the sample (Dice roll vs. Dice Roll) in your snippets) valid while the second is invalid:
<root>
<instruction>
<type repeat='1' until='random'><random start='1' end='6'/>Dice Roll</type>
</instruction>
<instruction>
<type repeat='1' until='2'><random start='1' end='6'/>Dice Roll</type>
</instruction>
</root>
I work for a financial firm who are required to report trades, sales data etc. to the regulator. At the moment we are doing this per individual because we cannot get their XML schema template to work. I am trying to import this into excel using the xml source pane.
The problem we have is that when we come to export the document, there is a denormalized data error which we can't get around. Unfortunately, myself and the team haven’t got much experience in mapping XML to know how to properly troubleshoot it. I’ve changed various bits of code to no success and even contacted the FCA (who say there is nothing wrong with it or dead links…lol).
Can someone offer some insight or guidance on how we can correct this issue?
The Schema is as follows:
<?xml version="1.0" encoding="utf-8"?>
<!-- edited with XMLSpy v2005 U (http://www.xmlspy.com) by Clive Raven (LogicaCMG) -->
<!--
********************************************************************************
*
* Project Name : FSA Transaction Reporting System
* Reference :
* Description : Definition For FSA High-Street Firms Feed For Retail Investment Products
* Dependencies : http://www.fsa.gov.uk/XMLSchema/FSAFeedCommon-v1-1.xsd
*
* Revision History
* Version Author Date Description
* 1.1 FSA 07/04/2004 First published draft
* 1.2 FSA 22/11/2004 Final draft
* 1.3 FSA 19/02/2007 Added Self Invested Personal Pensions (SIPPs) product type in TypeOfPolicyType
*
* Copyright Financial Services Authority 2004
********************************************************************************
-->
<xs:schema xmlns="http://www.fsa.gov.uk/XMLSchema/FSAHSFFeedRI-v1-2"
xmlns:cmn="http://www.fsa.gov.uk/XMLSchema/FSAFeedCommon-v1-2"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.fsa.gov.uk/XMLSchema/FSAHSFFeedRI-v1-2"
elementFormDefault="qualified"
version="1.0"
id="FSAHSFFeedRI-v1-3">
<xs:import namespace="http://www.fsa.gov.uk/XMLSchema/FSAFeedCommon-v1-2"
schemaLocation="https://gabriel.fca.org.uk/specifications/MER/DRG/PSD-CommonTypes/v1.2/FSAFeedCommon-v1-2.xsd"/>
<!--Types used in FSAHSFFeedRI-->
<xs:simpleType name="TypeOfPolicyType">
<xs:annotation>
<xs:documentation>Retail Investment Product Code. </xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="01">
<xs:annotation>
<xs:documentation>Unit trust/OEIC</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="02">
<xs:annotation>
<xs:documentation>Investment trust</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="03">
<xs:annotation>
<xs:documentation>ISA</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="04">
<xs:annotation>
<xs:documentation>Structured capital at risk product</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="05">
<xs:annotation>
<xs:documentation>With profit bond</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="06">
<xs:annotation>
<xs:documentation>Unit linked bond</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="07">
<xs:annotation>
<xs:documentation>Distribution bond</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="08">
<xs:annotation>
<xs:documentation>With profit endowment</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="09">
<xs:annotation>
<xs:documentation>Endowment savings plan</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="10">
<xs:annotation>
<xs:documentation>Mortgage endowment</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="11">
<xs:annotation>
<xs:documentation>Guaranteed income/growth/investment bond</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="12">
<xs:annotation>
<xs:documentation>Trustee investment bond</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="13">
<xs:annotation>
<xs:documentation>Life annuity</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="14">
<xs:annotation>
<xs:documentation>Pension annuity</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="15">
<xs:annotation>
<xs:documentation>Long term care insurance</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="16">
<xs:annotation>
<xs:documentation>Stakeholder pension</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="17">
<xs:annotation>
<xs:documentation>Personal pension</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="18">
<xs:annotation>
<xs:documentation>Group personal pension</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="19">
<xs:annotation>
<xs:documentation>FSAVC</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="20">
<xs:annotation>
<xs:documentation>Individual pension transfer</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="21">
<xs:annotation>
<xs:documentation>Pension opt out</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="22">
<xs:annotation>
<xs:documentation>Section 32 buy out</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="23">
<xs:annotation>
<xs:documentation>Group section 32 buy out</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="24">
<xs:annotation>
<xs:documentation>Income drawdown</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="25">
<xs:annotation>
<xs:documentation>Executive pension</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="26">
<xs:annotation>
<xs:documentation>SSAS</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="27">
<xs:annotation>
<xs:documentation>Group money purchase</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="28">
<xs:annotation>
<xs:documentation>AVC final salary</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="29">
<xs:annotation>
<xs:documentation>AVC group money purchase</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="30">
<xs:annotation>
<xs:documentation>Self Invested Personal Pensions (SIPPs)</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="99">
<xs:annotation>
<xs:documentation>Other. Use this when product is not one of above.</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<!--Structures used in FSAHSFFeedRI -->
<xs:complexType name="RetailInvestmentStructure">
<xs:sequence>
<xs:element name="PrincipalOrNetworkFSARef" type="cmn:FSARefType" minOccurs="0">
<xs:annotation>
<xs:documentation>This field only applies if the sale has been made by an intermediary who has a principal or is part of a network. </xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="TypePolicy" type="TypeOfPolicyType">
<xs:annotation>
<xs:documentation>Type of policy.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="AdvisedSale" type="cmn:YNType" minOccurs="0">
<xs:annotation>
<xs:documentation>This field is optional until July 2006, when it will become mandatory. Y = Sale was Advised, N = Sale was non-Advised. For PSD reporting purposes non-Advised includes execution only and direct offer transactions.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="CustPostCode" type="cmn:PostCodeType" minOccurs="0">
<xs:annotation>
<xs:documentation>Full U.K postcode of customer.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="PremPaymentMethod" type="cmn:PremiumPaymentMethodType">
<xs:annotation>
<xs:documentation>Method of premium/ contribution payment.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="TotalPremAmt" type="cmn:HSFStdSterlingAmountType">
<xs:annotation>
<xs:documentation>Total premium/contribution amount. Annualised amount rounded to nearest pound.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="CustDOB" type="xs:date" minOccurs="0">
<xs:annotation>
<xs:documentation>Date of birth of customer. Applies to first named customer at time of sale i.e. age obtained at proposal stage. Must represent an age up to and including 115.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="DateInForce" type="xs:date"/>
</xs:sequence>
</xs:complexType>
<!--FSAHSFFeedRI -->
<xs:element name="FSAHSFFeedRI">
<xs:complexType>
<xs:sequence>
<xs:element ref="cmn:FSAFeedHeader"/>
<xs:element name="FSAHSFFeedRIMsg" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>Defines the inidividual transactions</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="cmn:CoreItems"/>
<xs:element name="RetailInvestment" type="RetailInvestmentStructure">
<xs:annotation>
<xs:documentation>Defines the elements that are specific to a Retail Investment transaction.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
When importing the schema there is an error importing the common feed due to a dead link referenced in the schema:
SchemaLocation="https://gabriel.fca.org.uk/specifications/MER/DRG/PSD-CommonTypes/v1.2/FSAFeedCommon-v1-2.xsd
This can be downloaded separately from the FCA resources section and the schema can be edited to point to the file locally. See below:
<?xml version="1.0" encoding="utf-8"?>
<!-- edited with XMLSpy v2005 U (http://www.xmlspy.com) by Clive Raven (LogicaCMG) -->
<!--
********************************************************************************
*
* Project Name : FSA Transaction Reporting System
* Reference :
* Description : Common Definitions For FSA Feeds
* Dependencies :
*
* Revision History
* Version Author Date Description
* 1.1 FSA 07/04/2004 Published with early draft of SBD Schema's
* 1.2 FSA 22/11/2004 Published with final draft of all TRS Schema's
*
* Copyright Financial Services Authority 2004
********************************************************************************
-->
<xs:schema xmlns="http://www.fsa.gov.uk/XMLSchema/FSAFeedCommon-v1-2"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.fsa.gov.uk/XMLSchema/FSAFeedCommon-v1-2"
elementFormDefault="qualified"
version="1.2"
id="FSAFeedCommon-v1-2">
<!--Common Types -->
<xs:simpleType name="NonEmptyString">
<xs:annotation>
<xs:documentation>Defines a string type that may not be the empty string. Values of this type are also whitespace normalized meaning all-whitespace strings are also invalid.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="FSARefType">
<xs:annotation>
<xs:documentation>FSA Reference Number. Either a 6 or 7 digit number. Leading zeroes are not expected.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="[1-9]{1}[0-9]{5,6}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="PostCodeType">
<xs:annotation>
<xs:documentation>Full or abbreviated UK postcode.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="YNType">
<xs:annotation>
<xs:documentation>Y or N</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="Y"/>
<xs:enumeration value="N"/>
</xs:restriction>
</xs:simpleType>
<!--Common SBD Types -->
<xs:simpleType name="HSFStdSterlingAmountType">
<xs:annotation>
<xs:documentation>Integer from 1 to 999999999. Representing sterling-equivalent amount.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:positiveInteger">
<xs:totalDigits value="9"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="PremiumPaymentMethodType">
<xs:annotation>
<xs:documentation>Method of Premium/Contribution payment. Single or Regular.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="S">
<xs:annotation>
<xs:documentation>Single payment.</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="R">
<xs:annotation>
<xs:documentation>Regular payment.</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<!--Common Structures -->
<xs:element name="CoreItems">
<xs:annotation>
<xs:documentation>Defines the elements that are common to all transactions.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="FirmFSARef" type="FSARefType">
<xs:annotation>
<xs:documentation>The FSA code of the reporting firm for this transaction.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="TransRef">
<xs:annotation>
<xs:documentation>The unique reference, internal to the reporting firm, that will enable the firm to provide the FSA with more information concerning the trade if required. This reference must be unique within each report file, with the exception that a reference can occur twice if one occurrence is a cancellation. </xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="NonEmptyString">
<xs:maxLength value="25"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Cancellation" type="xs:boolean" minOccurs="0">
<xs:annotation>
<xs:documentation>Indicates if the transaction is a cancellation. If ommitted this is logically the same as providing a value of 'false'.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="FSAFeedHeader">
<xs:annotation>
<xs:documentation>Defines the report header, common to all reports.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="FeedTargetSchemaVersion" type="xs:string">
<xs:annotation>
<xs:documentation>Identifies the version of the business specific schema to which this report conforms.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="Submitter">
<xs:complexType>
<xs:sequence>
<xs:element name="SubmittingFirm" type="FSARefType">
<xs:annotation>
<xs:documentation>The FSA code of the firm submitting the report.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="SubmittingDept" minOccurs="0">
<xs:annotation>
<xs:documentation>The identifier of the department within the submitting firm who created this report - optional.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="NonEmptyString">
<xs:maxLength value="20"/>
<xs:pattern value="[a-zA-Z0-9]+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ReportDetails">
<xs:complexType>
<xs:sequence>
<xs:element name="ReportCreationDate" type="xs:date">
<xs:annotation>
<xs:documentation>Report creation date.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="ReportIdentifier">
<xs:annotation>
<xs:documentation>Unique identifier for the report (wthin the context of the submitter, submitting firm, submitting department and report creation date).</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="NonEmptyString">
<xs:maxLength value="25"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Resources:
https://regdata.fca.org.uk/specifications/DRG/PSD002/v1.5/FSAHSFFeedRI-v1-3.xsd - Full Schema
https://regdata.fca.org.uk/specifications/DRG/PSD-CommonTypes/v1.2/FSAFeedCommon-v1-2.xsd - Schema referenced using a dead link
https://regdata.fca.org.uk/#/layout/resources - General Resources
I'm not sure what your question is exactly. You point to 2 problems:
"denormalized data error": what do you mean? how is this related to the schema?
The broken link in the main schema file. You solved it yourself by editing the schemaLocation in the main schema. If you need a way to automatically correct the location without editing the main schema file, you can use an XML Catalog. Is it what you're looking for?
What do you mean also by "importing" the schema? Are you importing it in your own schema?
A catalog would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD XML Catalogs V1.1//EN" "http://www.oasis-open.org/committees/entity/release/1.1/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<uri name="http://www.fsa.gov.uk/XMLSchema/FSAFeedCommon-v1-2"
uri="path/to/local/copy/of/FSAFeedCommon-v1-2.xsd"/>
</catalog>
Then, you need to configure your parser (validation tool) to use that catalog.
I'm looking for a way to realize a scheme, where an element does have an attribute "topic" only when its enumeration has a specific value like in the upcoming example:
<article>
<type>Blogpost</type>
</article>
<article>
<type topic='news'>Article</type>
</article>
<article>
<type>Comment</type>
</article>
The challenge is to make it that the attribute will only be used when the value "Article" or "Documentary" is chosen. Furthermore I want only enumerations from predefined list to be valid. In case the right enumeration is chosen I want the attribute to be required in all other cases I don't want to have the attribute at all.
So far I tried the following schemes in order to do so but it doesn't work at all:
<xs:element name="type" minOccurs="0">
<xs:alternative test="#name='type'" type="type1"/>
<xs:alternative test="#name='type'" type="type2"/>
<xs:alternative type="xs:error"/>
</xs:element>
(...)
<xs:simpleType name="type1">
<xs:restriction base="xs:string">
<xs:enumeration value="Blogpost"/>
<xs:enumeration value="Comment"/>
<xs:enumeration value="Sentence"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="type2">
<xs:simpleContent>
<xs:extension base="type1">
<xs:attribute name="topic" type="topics" use='required'>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Article"/>
<xs:enumeration value="Documentary"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType-->
I always get an error that any chosen element is 'not a valid value of "error"'. The other example I tried worked to make use the attribute however it allowed any text and didn't care about the enumeration restrictions making it basicly useless:
<xs:element name="type" minOccurs="0">
<xs:alternative test="#ItemType='type'" type="type1"/>
<xs:alternative test="#ItemType='type'" type="type2"/>
</xs:element>
(...)
How do I do it that the same element does only have the attribute when it is actually the right enumeration and still the restrictions to enumerations are valid? Is my approach to work with xs:alternative the right one in order to have a same element one time with and one time without an attribute?
I was not able to figure out right test conditions in order to work with xs:assert.
I now have a useful answer - sorry for the non-useful comments!
This question is almost identical yours: XSD 1.1 alternative test the contents of text()
. On that basis, I suggest that you try something like this (not tested, because I don't have a XSD1.1 processor)
<xs:element name="type" type="type2" minOccurs="0"/>
<xs:complexType name="type2">
<xs:simpleContent>
<xs:extension base="type1">
<xs:attribute name="topic" type="topics" use='required'/>
<xs:assert test="not ( #topic or ( #topic and ($value eq 'Article' or $value eq 'Documentary'))"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="type1">
<xs:restriction base="xs:string">
<xs:enumeration value="Article"/>
<xs:enumeration value="Documentary"/>
<xs:enumeration value="Blogpost"/>
<xs:enumeration value="Comment"/>
<xs:enumeration value="Sentence"/>
</xs:restriction>
</xs:simpleType>```
Thank you again for your approach #kimbert.
With your help I was able to figure out the assertion that is fullfilling the demand. I just had to adjust your idea slightly:
<xs:element name="type" type="type2" minOccurs="0"/>
<xs:complexType name="type2">
<xs:simpleContent>
<xs:extension base="type1">
<xs:attribute name="topic" type="topics"/>
<xs:assert test="#topic and ($value eq 'Article' or $value eq 'Documentary') or not ($value eq 'Article' or $value eq 'Documentary')"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="type1">
<xs:restriction base="xs:string">
<xs:enumeration value="Article"/>
<xs:enumeration value="Documentary"/>
<xs:enumeration value="Blogpost"/>
<xs:enumeration value="Comment"/>
<xs:enumeration value="Sentence"/>
</xs:restriction>
</xs:simpleType>
Like this the compiler now always demands the attribute "topic" in case the value "Article" or "Documentary" is asked for. In all other cases the attribute is ignored as it should be.
I have problem with my XSD schema. Task is simple, a have this xml:
<?xml version="1.0" encoding="UTF-8"?>
<Pisemnost nazevSW="EPO MF ČR" verzeSW="40.23.1">
<DPPDP8 verzePis="04.01">
<VetaP>
<VetaO>
<VetaU> All these elements can be repeated and have any order.
<VetaE> They can have any attributes, but they have no content.
<VetaF>
<VetaS>
<VetaUA>
<VetaUB>
<VetaUD>
<Prilohy>
-- Any content ---
</Prilohy>
</DPPDP8>
-- Any content ---
</Pisemnost>
I make this XSD schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Pisemnost">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:element name="DPPDP8">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element name="VetaD" />
<xs:element name="VetaE" />
<xs:element name="VetaF" />
<xs:element name="VetaO" />
<xs:element name="VetaP" />
<xs:element name="VetaS" />
<xs:element name="VetaU" />
<xs:element name="VetaUA" />
<xs:element name="VetaUB" />
<xs:element name="VetaUD" />
</xs:choice>
</xs:sequence>
<xs:attribute name="verzePis" />
</xs:complexType>
</xs:element>
<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="nazevSW" />
<xs:attribute name="verzeSW" />
</xs:complexType>
</xs:element>
</xs:schema>
I would like to add "Prilohy" element with any content to XSD, but all my ideas ends with an invalid XSD. Please, can anybody help me? I ask for help, because I cant XSD and it is complicated for me. Thanks for any ideas :)
According to the reference DPPDP8 schema from here It should look like this:
<xs:element maxOccurs="1" minOccurs="0" name="Prilohy">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="ObecnaPriloha">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute name="cislo" use="required">
<xs:annotation>
<xs:documentation>Pořadové číslo přílohy</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:totalDigits value="4"/>
<xs:fractionDigits value="0"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="nazev" use="optional">
<xs:annotation>
<xs:documentation>Popis přiloženého souboru</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="jm_souboru" use="optional">
<xs:annotation>
<xs:documentation>
<strong>Název přiloženého souboru.</strong><br/>povolené typy souborů jsou: DOC, DOCX, RTF, XLS, XLSX, PDF, JPG, TXT a TXT/CSV. Dále je možné přiložit podepsané (formát PKCS#7) a komprimované (formát ZIP) soubory, vždy však jde o jeden podepsaný nebo jeden komprimovaný soubor některého z podporovaných formátů. Součet velikostí všech souborů přiložených v elektronické podobě (tzv. e-příloh) může být nejvýše 4 000 kilobajtů.
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="kodovani" use="optional">
<xs:annotation>
<xs:documentation>Kódování přiloženého souboru</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="base64"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="1" minOccurs="0" name="PredepsanaPriloha">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute name="cislo" use="required">
<xs:annotation>
<xs:documentation>Pořadové číslo přílohy</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:totalDigits value="4"/>
<xs:fractionDigits value="0"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="nazev" use="optional">
<xs:annotation>
<xs:documentation>Popis přiloženého souboru</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="jm_souboru" use="optional">
<xs:annotation>
<xs:documentation>
<strong>Název přiloženého souboru.</strong><br/>povolené typy souborů jsou: DOC, DOCX, RTF, XLS, XLSX, PDF, JPG, TXT a TXT/CSV. Dále je možné přiložit podepsané (formát PKCS#7) a komprimované (formát ZIP) soubory, vždy však jde o jeden podepsaný nebo jeden komprimovaný soubor některého z podporovaných formátů. Součet velikostí všech souborů přiložených v elektronické podobě (tzv. e-příloh) může být nejvýše 4 000 kilobajtů.
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="kodovani" use="optional">
<xs:annotation>
<xs:documentation>Kódování přiloženého souboru</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="base64"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="kod" use="required">
<xs:annotation>
<xs:documentation>Kód přiloženého souboru</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(PP_OPISPUV){1}"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
I have the following schema which works fine:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bindings">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="bind">
<xs:complexType>
<xs:attribute name="trigger" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute> <!-- trigger -->
<xs:attribute name="command" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute> <!-- command -->
</xs:complexType>
</xs:element> <!-- bind -->
</xs:sequence>
</xs:complexType>
</xs:element> <!-- bindings -->
</xs:schema>
However, when I try to define an attribute for the top level bindings element, I get an error no matter where I place the attribute code. What am I missing or doing wrong?
EDIT: It looks like there's some problem with either my Java XML code or Xerces. If I change the XSD to give the top-level element the optional "parent" attribute, Xerves gives me the error "Problem: schema_reference.4: Failed to read schema document 'null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>." However, if I give the attribute any name //other// than "parent", it reports Attribute 'parent' is not allowed to appear in element 'bindings'., just as you'd expect.
My Java code regarding XSD and Xerces is:
bindingsDocumentBuilderFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilderFactory bdbf = bindingsDocumentBuilderFactory;
bdbf.setValidating(true);
// I get the input stream here as "is"
bdbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
bdbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", is);
EDIT 2:
The XML file which is being validated:
<bindings parent="game/movement">
<bind trigger="i" command="INVENTORY"/>
</bindings>
This works (see attribute named code):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bindings">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="bind">
<xs:complexType>
<xs:attribute name="trigger" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<!-- trigger -->
<xs:attribute name="command" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<!-- command -->
</xs:complexType>
</xs:element>
<!-- bind -->
</xs:sequence>
<xs:attribute name="code"/>
</xs:complexType>
</xs:element>
<!-- bindings -->
</xs:schema>