[jdom-interest] Processing instruction map issues
Elliotte Rusty Harold
elharo at metalab.unc.edu
Sun May 4 11:35:21 PDT 2003
I'm resending this proposal from last April with slight modifications
to get it back into the queue:
Consider the following code fragment:
try {
ProcessingInstruction pi
= new ProcessingInstruction("target",
"some random non-attribute-like data");
pi.setValue("name", "value");
pi.setValue("name2", "value2");
XMLOutputter outputter = new XMLOutputter();
outputter.output(pi, System.out);
}
catch (Exception e) {
System.err.println(e);
}
What output do you expect? I wasn't sure which is why I wrote the
code, but the result surprised me. It is:
<?target name="value" name2="value2"?>
The original data has been completely overridden with no warning by
the pseudo-attributes. I'm not sure what to do here. There are a
couple of possible solutions:
1. setValue() should throw an exception if the Map is null; i.e. if
the PI was not initially set up with a pseudo-attribute format.
2. The pseudo-atts should just be appended to the data; i.e.:
<?target some random non-attribute-like data name="value" name2="value2"?>
3. Get rid of all this Map data craziness, and just have string
target and a string value.
I think I prefer option 3, and last year Bradley Huffman and Alex
Rosen agreed. Whatever we choose, even sticking with the current
behavior, the behavior should be documented in the JavaDoc
Issue 2:
The name setValue() is misleading. It sounds like it sets the entire
value of the PI. What it really does is add a pseudo-attribute. The
following names all strike me as more accurate:
addValue()
addPseudoAttribute()
setPseudoAttribute()
I think I prefer addPseudoAttribute()
though if we get rid of the Map we coudl probably just throw this away too.
--
Elliotte Rusty Harold
elharo at metalab.unc.edu
Processing XML with Java (Addison-Wesley, 2002)
http://www.cafeconleche.org/books/xmljava
http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA
More information about the jdom-interest
mailing list