You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Xan Gregg <xa...@tibco.com> on 2001/07/02 15:18:03 UTC

RE: crimson remove attr bug?

OK, below is a small test program and its output. --xan

------PROGRAM-------
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;

/**
 * Test file to demonstrate inability to add an atttribute
 * node to an element node.  In this case we are trying
 * to add the attribute to the element that created it, and
 * we get the INUSE_ATTRIBUTE_ERR exception.  
 * 
 * @author Xan Gregg
 */
public class AttrTest {

public static void main(final String args[]) {
  try {
      Document doc = newDocument();
      Element root = doc.createElement("root");
      doc.appendChild(root);
      root.setAttribute("foo", "213");        // adds attribute "foo"
      System.out.println("# attrs = " + root.getAttributes().getLength());
      Attr attr = root.getAttributeNode("foo");   // gets the Attr node
      root.removeAttributeNode(attr);         // removes the attr
      System.out.println("# attrs = " + root.getAttributes().getLength());
      root.setAttributeNode(attr);            // fails
      System.out.println("# attrs = " + root.getAttributes().getLength());
  }
  catch (Exception x) {
      x.printStackTrace();
  }
  System.out.println("done");
}

protected static DocumentBuilder s_builder;

public static DocumentBuilder getDocumentBuilder()
      throws SAXException {
  if (s_builder == null){
      try{
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(false);
        dbf.setNamespaceAware(true);
        s_builder = dbf.newDocumentBuilder();
      }
      catch (ParserConfigurationException x) {
        throw new SAXException(x);
      }
  }
  return s_builder;
}

public static Document newDocument()
          throws SAXException {
  DocumentBuilder db = getDocumentBuilder();
  return db.newDocument();
}
}
------OUTPUT-------------
# attrs = 1
# attrs = 0
org.apache.crimson.tree.DomEx: INUSE_ATTRIBUTE_ERR: The attribute is bound
to a different element.
  at
org.apache.crimson.tree.AttributeSet.setNamedItem(AttributeSet.java:340)
  at
org.apache.crimson.tree.ElementNode.setAttributeNode(ElementNode.java:537)
  at AttrTest.main(AttrTest.java:18)
done
--------END-------------

-----Original Message-----
From: Edwin Goei [mailto:edwingo@sun.com]
Sent: Thursday, June 28, 2001 4:45 PM
To: general@xml.apache.org
Subject: Re: crimson remove attr bug?


Xan Gregg wrote:
> 
> I'm having problems removing and re-adding attributes in Crimson. If I
> remove an attribute and then add it to the same element, I get an
> INUSE_ATTRIBUTE_ERR exception.
> 
> I think the problem is that the ownerElement field of the attribute is not
> cleared on the remove operation.
> 
> Is that behavior intentional or is it a bug?

Could very well be a bug.  Could you provide a simple test program?

-Edwin

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Re: crimson remove attr bug?

Posted by Edwin Goei <ed...@sun.com>.
Xan Gregg wrote:
> 
> OK, below is a small test program and its output. --xan

Thanks for the test program.  It's fixed in CVS.

-Edwin

PS: Sorry for the slow response I was out the week of July 4th (forced
vacation).

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org