libxml2: Fixed/default attributes in XSD

39 views Asked by At

I would like to use fixed/default attributes in XSD validation with libxml2, to “apply” to an xml document fixed attributes only defined in the schema but not in the real xml content. I see that if I call

xmlSchemaSetValidOptions(ctx, XML_SCHEMA_VAL_VC_I_CREATE);

on the context before the validation I correctly get the fixed/default attributes on the xml DOM, but when I re-save the xml to disk after some modification all the fixed attributes are saved as well…

I am porting an existing Win32 application from MSXML, in that case there is a “specified” property on each attribute (default and fixed attribute have specified=false), and only the really “explicit” attributes are really saved to disk.

It is possible to have this behaviour is some way? Is it by design or a bug? Thanks!

test schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
    <xs:complexType name="Troot">
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="fixedattr" type="xs:string" fixed="fixedvalue"/>
    </xs:complexType>
    <xs:element name="root" type="Troot"/>
</xs:schema>

test xml loaded:

<root name="x"/>

test xml saved (fixedattr is wrongly added):

<root name="x" fixedattr="fixedvalue"/>
0

There are 0 answers