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.
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'm trying to write a function to get the description of some values from a XSD file, with a structure like this
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:element name="File">
<xs:annotation>
<xs:documentation>List of centers</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Register">
<xs:annotation>
<xs:documentation>Center list registers</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="CenterType">
<xs:annotation>
<xs:documentation>Type of center </xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:totalDigits value="1"/>
<xs:enumeration value="1">
<xs:annotation>
<xs:documentation>Own center</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="2">
<xs:annotation>
<xs:documentation>External center</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="3">
<xs:annotation>
<xs:documentation>Associated center</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="4">
<xs:annotation>
<xs:documentation>Other</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
By example, if I put
get_value("CenterType", "1")
my function might return "Own center"
I'm using Python 3.8 with XMLSchema.
I wrote this snippet, and I get to print the tag of all elements
xsd_xml = xmlschema.XMLSchema(xsd_file)
fichero = xsd_xml.elements["File"][0]
for elem in fichero:
print(elem.tag)
But I need to access to the enumeration and documentation fields.
How can I extract this data?
Use untangle
import untangle
xsd_file = "C:\\code\\python\\xsd\\test.xsd"
obj = untangle.parse(xsd_file)
res = obj.xs_schema.xs_element.xs_complexType.xs_sequence.xs_element.xs_complexType.xs_sequence.xs_element.xs_simpleType.xs_restriction.xs_enumeration
Finally, I solved my problem using LXML and XMLSchema namespace
def get_value(self, field: str, code: str, file: str):
desc = ""
xsd_xml = ET.parse(file)
search_elem = f".//{{http://www.w3.org/2001/XMLSchema}}element[#name='{field}']"
element = xsd_xml.find(search_elem)
search_enum = f".//{{http://www.w3.org/2001/XMLSchema}}enumeration[#value='{code}']"
enumeration = element.find(search_enum)
if enumeration is not None:
documentation = enumeration.find(".//{http://www.w3.org/2001/XMLSchema}documentation")
desc = documentation.text
else:
desc = "N/A"
return desc
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 an XSD that I created. A Transaction Header can one or more Transaction-Items. This XSD will only allow ONE Transaction Header and multiple Transaction-Items in an XML file. I am looking for MULTIPLE Transaction Headers with it's related multiple Transaction-Items. What is missing in the XSD to allow me to do this? Thanks.
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2010 (http://www.altova.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="transaction-item">
<xs:complexType>
<xs:sequence>
<xs:element ref="StartDate"/>
<xs:element ref="EndDate"/>
<xs:element ref="Amount"/>
<xs:element ref="BusinessPartnerID"/>
<xs:element ref="Description"/>
</xs:sequence>
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Production or Import"/>
<xs:enumeration value="Transfer: Release Obligation"/>
<xs:enumeration value="Transfer: Retain Obligation"/>
<xs:enumeration value="Acquire: Without Obligation"/>
<xs:enumeration value="Acquire: With Obligation"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="Amount">
<xs:simpleType>
<xs:restriction base="xs:positiveInteger"/>
</xs:simpleType>
</xs:element>
<xs:element name="Year">
<xs:simpleType>
<xs:restriction base="xs:short"/>
</xs:simpleType>
</xs:element>
<xs:element name="TransactionHeader">
<xs:complexType>
<xs:sequence>
<xs:element ref="Quarter"/>
<xs:element ref="Year"/>
<xs:element ref="FuelPathwayCode"/>
<xs:element ref="PhysicalPathwayCode"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="StartDate">
<xs:simpleType>
<xs:restriction base="xs:date"/>
</xs:simpleType>
</xs:element>
<xs:element name="Quarter">
<xs:simpleType>
<xs:restriction base="xs:byte"/>
</xs:simpleType>
</xs:element>
<xs:element name="PhysicalPathwayCode">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="PP001"/>
<xs:enumeration value="PP002"/>
<xs:enumeration value="PP003"/>
<xs:enumeration value="PP004"/>
<xs:enumeration value="PP005"/>
<xs:enumeration value="PP006"/>
<xs:enumeration value="PP007"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="LCFS-report">
<xs:complexType>
<xs:sequence>
<xs:element ref="TransactionHeader"/>
<xs:element ref="transaction-item" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="total-sum" use="required">
<xs:simpleType>
<xs:restriction base="xs:byte"/>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="detailed" type="xs:boolean" use="required"/>
<xs:attribute name="currency" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="USD"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="FuelPathwayCode">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="CARBOB001"/>
<xs:enumeration value="CARBOB002-HIGH"/>
<xs:enumeration value="CARBOB002-INC"/>
<xs:enumeration value="Ethanol001"/>
<xs:enumeration value="Ethanol002"/>
<xs:enumeration value="Ethanol003"/>
<xs:enumeration value="Ethanol004"/>
<xs:enumeration value="Ethanol005"/>
<xs:enumeration value="Ethanol006"/>
<xs:enumeration value="Ethanol007"/>
<xs:enumeration value="Ethanol008"/>
<xs:enumeration value="Ethanol009"/>
<xs:enumeration value="Ethanol0010"/>
<xs:enumeration value="Ethanol0012"/>
<xs:enumeration value="Fossil CNG001"/>
<xs:enumeration value="Fossil CNG002"/>
<xs:enumeration value="Biogas CNG001"/>
<xs:enumeration value="Electricity001_30"/>
<xs:enumeration value="Electricity002_27"/>
<xs:enumeration value="ULSD-CA Diesel Fuel"/>
<xs:enumeration value="Compressed Hydrogen001"/>
<xs:enumeration value="Liquid Hydrogen001"/>
<xs:enumeration value="Compressed Hydrogen002"/>
<xs:enumeration value="Compressed Hydrogen003"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="EndDate">
<xs:simpleType>
<xs:restriction base="xs:date"/>
</xs:simpleType>
</xs:element>
<xs:element name="Description">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:element>
<xs:element name="BusinessPartnerID">
<xs:simpleType>
<xs:restriction base="xs:short"/>
</xs:simpleType>
</xs:element>
</xs:schema>
First, I would convert your TransactionHeader to a separate type:
<xs:complexType name="TransactionHeaderType">
<xs:sequence>
<xs:element ref="Quarter"/>
<xs:element ref="Year"/>
<xs:element ref="FuelPathwayCode"/>
<xs:element ref="PhysicalPathwayCode"/>
</xs:sequence>
</xs:complexType>
Then you can define a new element of complex type that can contain any number of transaction headers:
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="TransactionHeader"
type="TransactionHeaderType"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
By default, in XML Schema, minOccurs and maxOccurs both are set to 1 - but in a sequence, you can change that number to anything you like - including the "unbounded" for maxOccurs.
Marc
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>