[jdom-interest] Setting value of an attribute resets its type
Edelson, Justin
Justin.Edelson at mtvn.com
Wed Apr 19 15:01:45 PDT 2006
Here's a patch against the current HEAD that adds two new setAttribute()
methods, both with a type parameter. There's probably a more clever way
to add code into AttributeList so that you don't have to always pass in
the correct type, but that seemed it could have unintended consequences.
Justin
-----Original Message-----
From: jdom-interest-bounces at jdom.org
[mailto:jdom-interest-bounces at jdom.org] On Behalf Of Victor Toni
Sent: Wednesday, April 19, 2006 5:31 PM
To: jdom-interest at jdom.org
Subject: [jdom-interest] Setting value of an attribute resets its type
I have written already on the subject but got no response so I'll try it
again.
Having noticed that setting the value of an attribute via the
convenience methods in the Element class ("setAttribute(String name,
String value)" and "setAttribute(String name, String value, Namespace
ns)") will reset its type I wonder if this is on purpose.
Maybe this functionality is not widely used and it went unnoticed?
Sorry for the noise if this is not an issue
Victor
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
-------------- next part --------------
Index: src/java/org/jdom/Element.java
===================================================================
RCS file: /home/cvspublic/jdom/src/java/org/jdom/Element.java,v
retrieving revision 1.154
diff -u -r1.154 Element.java
--- src/java/org/jdom/Element.java 11 Dec 2004 00:27:38 -0000 1.154
+++ src/java/org/jdom/Element.java 19 Apr 2006 21:57:43 -0000
@@ -1117,6 +1117,26 @@
*
* @param name name of the attribute to set
* @param value value of the attribute to set
+ * @param type type of the attribute to set
+ * @return this element modified
+ * @throws IllegalNameException if the given name is illegal as an
+ * attribute name.
+ * @throws IllegalDataException if the given attribute value is
+ * illegal character data (as determined by
+ * {@link org.jdom.Verifier#checkCharacterData}).
+ */
+ public Element setAttribute(String name, String value, int type) {
+ return setAttribute(new Attribute(name, value, type));
+ }
+
+ /**
+ * <p>
+ * This sets an attribute value for this element. Any existing attribute
+ * with the same name and namespace URI is removed.
+ * </p>
+ *
+ * @param name name of the attribute to set
+ * @param value value of the attribute to set
* @param ns namespace of the attribute to set
* @return this element modified
* @throws IllegalNameException if the given name is illegal as an
@@ -1138,6 +1158,30 @@
* with the same name and namespace URI is removed.
* </p>
*
+ * @param name name of the attribute to set
+ * @param value value of the attribute to set
+ * @param type type of the attribute to set
+ * @param ns namespace of the attribute to set
+ * @return this element modified
+ * @throws IllegalNameException if the given name is illegal as an
+ * attribute name, or if the namespace is an unprefixed default
+ * namespace
+ * @throws IllegalDataException if the given attribute value is
+ * illegal character data (as determined by
+ * {@link org.jdom.Verifier#checkCharacterData}).
+ * @throws IllegalAddException if the attribute namespace prefix
+ * collides with another namespace prefix on the element.
+ */
+ public Element setAttribute(String name, String value, int type, Namespace ns) {
+ return setAttribute(new Attribute(name, value, type, ns));
+ }
+
+ /**
+ * <p>
+ * This sets an attribute value for this element. Any existing attribute
+ * with the same name and namespace URI is removed.
+ * </p>
+ *
* @param attribute <code>Attribute</code> to set
* @return this element modified
* @throws IllegalAddException if the attribute being added already has a
More information about the jdom-interest
mailing list