Validate Fixml Against Schema (Xsd)
I'm Trying to Validate Some Fixml Messages That I Received from a Business Partner but I Couldn't. I Think Should Be a Namespace Problem Because the Parser...
I'm trying to validate some FIXML messages that I received from a business partner but I couldn't. I think should be a namespace problem because the parser don't identify the root tag (FIXML). Any thoughts?
Thanks a lot for any help.
Java Schema Validator
static boolean validateAgainstXSD(InputStream xml, InputStream xsd) {
try {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new StreamSource(xsd));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(xml));
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
FIXML to be validated
<?xml version="1.0" encoding="utf-8"?>
<FIXML v="FIX.5.0SP2" xmlns:xs="">
<TrdCaptRpt TrdID="32KGWND0000000099@20220411" ExecID="ExecID" TrdDt="2022-04-11" BizDt="2022-04-11" LastUpdateTm="2022-04-11T09:27:23.404Z" LastQty="1" LastPx="101.1" MktSegID="XEUR" LastMkt="XEUR" VenuTyp="E" TrdTyp="0" AsOfInd="0" TransTyp="0" MtchID="1" TrnsfrRsn="004" MLegRptTyp="1" Clrd="0">
<Hdr SeqNum="2587905699377885" SID="CM1_EU" TID="CM1_EU" Snt="2022-04-11T14:14:59.407564Z" SSub="FIS CD"/>
<RegTrdID Evnt="2" Typ="0" ID="E01XEURECAGWC00000000000099KGWND0000000002"/>
<Instrmt Exch="XEUR" Sym="DBK9" CFI="OCXXXN" MatDt="2023-03-31" MMY="202303" PutCall="1" StrkPx="100.0"/>
<RptSide Side="1" TrdID="32KGWND0000000099" PosEfct="O" CustOrdHdlInst="D">
<Pty ID="CM1_EU" R="1"/>
<Pty ID="CLIENT1UK_ACC1_DEFACCREF" R="24"/>
<Pty ID="A1" R="38"/>
<Pty ID="CM1_EU" R="4"/>
<Pty ID="ECAG" R="21"/>
<Pty ID="TRADER" R="12"/>
<TrdRegTS TS="2022-04-11T08:18:03.689Z" Typ="1"/>
<TrdRegTS TS="2022-04-11T14:14:59.391Z" Typ="13"/>
<TrdRegTS TS="2022-04-11T08:18:03.689Z" Typ="19"/>
<TrdRptOrdDetl OrdID="ORDERID"/>
</RptSide>
</TrdCaptRpt>
</FIXML>
XML Schema to validate
<?xml version="1.0" encoding="utf-8"?>
<!-- FIXML Schema Version FIX.5.0SP2 EP240 Generated: 2017-12-29T02:42:44.519Z
Copyright(c) FIX Protocol Limited. All rights reserved. Comments and errors
should be posted on the FIX protocol web-site -->
<xs:schema xmlns:xs=""
xmlns=""
xmlns:fm=""
xmlns:xsi=""
xsi:schemaLocation=" fixml-metadata-5-0-SP2.xsd"
targetNamespace=""
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:include schemaLocation="fixml-tradecapture-base-5-0-SP2.xsd"/>
</xs:schema>
PS: All included schemas are available in the same folder where the referenced is, as you can see below.
1 Answer
I think the problem is the XML:
<FIXML v="FIX.5.0SP2" xmlns:xs="">
This assigns alias xs to the namespace but then it is not used at all in the xml. So basically the xml is in no namespace whereas according to the schema, the xml should be in the specific namespace .
So either remove the alias:
<FIXML v="FIX.5.0SP2" xmlns="">
Or use the alias in all element tags like this:
<xs:FIXML v="FIX.5.0SP2" xmlns:xs="">