Hi,

as a quick follow-up: injecting default attributes works when applying the
schema *after* the parsing step, it does *not* work when validating inside
the parser using the SAX plug.

Stefan


Stefan Behnel wrote:
> I'm trying to inject default attributes into a document from an XML Schema
> during parsing. I set up a validation context and set the
> XML_SCHEMA_VAL_VC_I_CREATE option on it, which, if I understand the docs
> correctly, tells the validator to create defaulted/fixed attributes if they
> do not exist already. Then I inject the validation context into the parser
> using "xmlSchemaSAXPlug()".
> 
> The schema document I use is
> 
> '''
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
>   <xsd:element name="a" type="AType"/>
>   <xsd:complexType name="AType">
>     <xsd:sequence minOccurs="4" maxOccurs="4">
>       <xsd:element name="b" type="BType" />
>     </xsd:sequence>
>   </xsd:complexType>
>   <xsd:complexType name="BType">
>     <xsd:attribute name="hardy" type="xsd:string" default="hey" />
>   </xsd:complexType>
> </xsd:schema>
> '''
> 
> The document I parse is
> 
> '''
> <a><b hardy="ho"/><b/><b hardy="ho"/><b/></a>
> '''
> 
> The document validates. However, no default attributes are inserted,
> neither with my code nor with xmllint (which doesn't seem to support that
> anyway). When I debug into the validator code in xmlschemas.c, I get to
> line 25351 (libxml2 2.7.3):
> 
> '''
>     /*
>     * Get the owner element; needed for creation of default attributes.
>     * This fixes bug #341337, reported by David Grohmann.
>     */
>     if (vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) {
>         xmlSchemaNodeInfoPtr ielem = vctxt->elemInfos[vctxt->depth];
> ==>     if (ielem && ielem->node && ielem->node->doc)
>             defAttrOwnerElem = ielem->node;
>     }
> '''
> 
> but "ielem->node" is NULL every time it gets there, so this doesn't fly.
> 
> Is there anything else I have to do to make this work?
> 
> Thanks,
> 
> Stefan
> _______________________________________________
> xml mailing list, project page  http://xmlsoft.org/
> [email protected]
> http://mail.gnome.org/mailman/listinfo/xml
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to