[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [xml] Inserting XML Schema default attributes
- From: Stefan Behnel <stefan_ml behnel de>
- To: xml gnome org
- Subject: Re: [xml] Inserting XML Schema default attributes
- Date: Sun, 31 May 2009 15:02:16 +0200
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/
> xml gnome org
> http://mail.gnome.org/mailman/listinfo/xml
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]