After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 584385 - Inserting XML Schema default attributes does not work when parsing with SAX-plug
Inserting XML Schema default attributes does not work when parsing with SAX-plug
Status: RESOLVED OBSOLETE
Product: libxml2
Classification: Platform
Component: xmlschema
2.7.3
Other All
: Normal minor
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2009-05-31 18:40 UTC by Stefan Behnel
Modified: 2021-07-05 13:24 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Stefan Behnel 2009-05-31 18:40:21 UTC
Please describe the problem:
Inserting XML Schema default attributes does not work when parsing with the SAX-plug (i.e. when validating at parse time). It would be really nice if this worked, as applying the validation afterwards to insert the 'missing' attributes requires an additional step, so the parser itself cannot currently return the 'complete' document as seen by the external schema.

Steps to reproduce:
1. create a validation context and set the XML_SCHEMA_VAL_VC_I_CREATE option
2. insert the validator into a parser using xmlSchemaSAXPlug()
3. validate a document against a schema that contains default attributes

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>
'''


Actual results:
The default attributes defined in the schema do not end up in the document tree.

Expected results:


Does this happen every time?


Other information:
I debugged into this a bit and found line 25351 in xmlschemas.c (libxml2 2.7.3), where it says:

'''
    /*
    * 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;
    }
'''

"ielem->node" is NULL every time it gets there, so the attributes do not get inserted.
Comment 1 GNOME Infrastructure Team 2021-07-05 13:24:34 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME/libxml2/-/issues/

Thank you for your understanding and your help.