I am receiving this XML file which I would like to validate. Ideally I should not edit this XML file at all. What tool can I use to do that ? I tried python/lxml and xmllint but none of them allow setting the default namespace for the XML instance:
<?xml version="1.0" encoding="UTF-8"?>
<CsaMscData>
<MscHeader Version="SV10"/>
<REGISTRATION_MATRIX>
<BASE_OBJECT_INFO>
<PADDING_DATA_FLAG>false</PADDING_DATA_FLAG>
<NO_DATA_FLAG>true</NO_DATA_FLAG>
</BASE_OBJECT_INFO>
<MATRIX>0.99768257087730505,-0.06775286248296480,0.00624799111837611,-13.94377645859601600,0.06131919890246099,0.93512585266229120,0.34896933322081974,305.74417624498307000,-0.02948632926647999,-0.34777749971495792,0.93711331602875081,35.13001338466752800,3*0.00000000000000000,1.00000000000000020</MATRIX>
<MATRIX_ID>1.3.12.2.1107.5.1.4.28334.4.0.4056501222952849:1.3.12.2.1107.5.1.4.28334.4.0.4056484330893172_1.3.12.2.1107.5.2.32.35065.2010021811070138240320629.0.0.0:1.3.12.2.1107.5.2.32.35065.1.20100218105150375.0.0.0</MATRIX_ID>
<MATRIX_TYPE>8</MATRIX_TYPE>
<CENTER_DS1>1064</CENTER_DS1>
<WIDTH_DS1>200</WIDTH_DS1>
<CENTER_DS2>479</CENTER_DS2>
<WIDTH_DS2>994</WIDTH_DS2>
<LUT_DS1>GrayScale08.clut</LUT_DS1>
<LUT_DS2>HotBody08.clut</LUT_DS2>
<MIX>0.50000000000000000</MIX>
<THRMIN_DS1>0</THRMIN_DS1>
<THRMAX_DS1>4095</THRMAX_DS1>
<THRMIN_DS2>0</THRMIN_DS2>
<THRMAX_DS2>4095</THRMAX_DS2>
</REGISTRATION_MATRIX>
</CsaMscData>
The XSD is (truncated)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.siemens.com/med/syngo/SiemensNonImageCSAData"
xmlns:NS="http://www.siemens.com/med/syngo/SiemensNonImageCSAData" targetNamespace="http://www.siemens.com/med/syngo/SiemensNonImageCSAData" version="1.0">
<xs:annotation>
<xs:documentation>
In a registration context, instances of this schema are written into the
"Siemens Non Image IOD::CSA Non Image::CSA Data Info" (0029,xx10) attribute.
Note: we assume all elements to be mandatory, i.e. minOccurs="1" and maxOccurs="1".
</xs:documentation>
</xs:annotation>
<xs:element name="CsaMscData">
Thanks for any hints !
Without modifying something, there is no way you can successfully validate the instance XML against the provided XSD; you’re showing the XSD as having the target namespace
http://www.siemens.com/med/syngo/SiemensNonImageCSAData; your XML has only unqualified content.The XSD has no elementFormDefault schema attribute set; it means the default is used (unqualified). However, this is not applicable to global element definitions, therefore
CsaMscDatamust be qualified in valid instance documents.If you insist on a workaround without modifying the XML, then you have to modify the XSD. I don’t see any xs:include or xs:import which means it should be easy to do it.
Manually, remove the xmlns and targetNamespace from your XSD; validate the XSD to make sure it is still valid. Then use it to validate your XML. If all works, then either use the modified XSD or do that modification on the flight: load it as XML at runtime, alter it as you did manually, write it back, then load it as XSD for validation.