Attribute with default value not immediately replaced... !?

Discussion in 'XML' started by Nicolas, Feb 24, 2006.

  1. Nicolas

    Nicolas Guest

    Hi everybody...

    In Xerces 2.7.0 it is explicitly stated that, no matter how one removes
    an attribute
    (attList->removeNamedItem, attList->removeNamedItemNS,
    domElement->removeAttributeNode, domElement->removeAttribute,
    domElement->removeAttributeNS), if that attribute has a default value
    it is immediately replaced.
    However I cannot obtain that behaviour...

    Check out the following schema and document:

    SCHEMA
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://schema1"
    targetNamespace="http://schema1"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">
    <xsd:element name="subelement" type="subelementType"/>
    <xsd:element name="rootelement">
    <xsd:complexType>
    <xsd:choice maxOccurs="unbounded">
    <xsd:element ref="subelement"/>
    </xsd:choice>
    </xsd:complexType>
    </xsd:element>
    <xsd:attribute name="myat" type="xsd:string" default="123"/>
    <xsd:complexType name="subelementType">
    <xsd:attribute ref="myat"/>
    </xsd:complexType>
    </xsd:schema>

    DOCUMENT
    <?xml version="1.0" encoding="UTF-8"?>
    <rootelement xmlns="http://schema1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://schema1 schema.xsd">
    <subelement/>
    </rootelement>

    I load the document to a DOM like this:

    DOMParser->setDoNamespaces(true);
    DOMParser->setDoSchema(true);
    DOMParser->setValidationSchemaFullChecking(true);
    DOMParser->parse(FileName);

    In the DOM constructed, as expected, there is a "myat" attribute for
    element "subelement"
    having the value of "123". As the latter was declared as a global
    attribute in the schema,
    it is namespace-qualified (getNamespaceURI() GIVES "http://schema1")
    even though
    schema has attributeFormDefault="unqualified" (correct me if I'm
    wrong...).

    So far so good.

    Now I'm trying to remove that attribute. No matter which of the above
    methods I choose,
    I cannot obtain the immediate replacement of this attribute, although
    it has a default value.

    removeNamedItem causes the creation of a "myat" element, but with no
    namespace. All
    other methods just remove the attribute and no replacement occurs.

    What is going on? Am I missing something?...

    Any help would be GREATLY appreciated...

    Thanks in advance.

    Nicolas
    Nicolas, Feb 24, 2006
    #1
    1. Advertising

  2. Traditionally, default-attribute reinstantiation only worked for
    defaults specified in DTDs, not in schemas. As of DOM Level 3, that
    *may* (not must) be supported for schemas too. I'd suggest talking to
    the folks who wrote your DOM implementation -- the Xerces mailing list
    at Apache -- to ask whether that's supported and whether there's a
    switch you have to set to enable it.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Feb 24, 2006
    #2
    1. Advertising

  3. Nicolas

    Nicolas Guest

    Ok Joseph, you' re clear....

    Thanks!

    Nicolas
    Nicolas, Feb 24, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shawn Modersohn

    replaced vs non replaced

    Shawn Modersohn, Jul 19, 2004, in forum: HTML
    Replies:
    4
    Views:
    959
    Shawn Modersohn
    Jul 20, 2004
  2. Replies:
    1
    Views:
    4,237
    Joe Kesselman
    Aug 2, 2006
  3. Replies:
    8
    Views:
    513
  4. Replies:
    4
    Views:
    3,295
  5. dkmd_nielsen
    Replies:
    6
    Views:
    198
    Joel VanderWerf
    Nov 26, 2008
Loading...

Share This Page