I wrote a Python script allowing to parse a csv file into a xml file following a xsd schema file. The output xml file gets validated against the xsd schema using lxml.etree
's XMLSchema
method.
I am currently handling missing values by replacing them with a dummy number (-999), as detailed in this question, but I was recently provided with a new xsd file allowing nillable elements:
<xs:element name="ProfileValue" type="xs:double" nillable="true"/>
1. Following this SO post, I tried using xml_data.append('<ProfileValue xsi:nil="true"/>')
to pass on "missing" values to the xml file, but this leads to the following error:
Namespace prefix xsi for nil on ProfileValue is not defined
2. After reading that xsi and xs prefixes were interchangeable, I also tried xml_data.append('<ProfileValue xs:nil="true"/>')
, but sure enough, this also returns a XMLSyntaxError:
Namespace prefix xs for nil on ProfileValue is not defined
3. I tried omitting the prefix (xml_data.append('<ProfileValue nil="true"/>')
) , but this then leads to this error:
Element 'ProfileValue': '' is not a valid value of the atomic type 'xs:double'.
4. I aslo tried xml_data.append('<ProfileValue nil="true"> </ProfileValue>')
following this SO post, but also got an error:
Element 'ProfileValue': ' ' is not a valid value of the atomic type 'xs:double'.
What am I doing wrong here? Is it even possible to set double type values as nillable?