Re: [xml] Inserting XML Schema default attributes



On Sat, May 09, 2009 at 06:56:59AM +0200, Stefan Behnel wrote:
Hi,

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?

  Sorry, no idea :-\

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]