[jdom-interest] Processing instruction map issues

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Apr 29 19:14:14 PDT 2002


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"?>

I think I prefer option 1, but I'm not sure. Whatever we choose, eve 
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()

-- 
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+ 
|           The XML Bible, 2nd Edition (IDG Books, 2001)             |
|             http://www.cafeconleche.org/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:   http://www.cafeaulait.org/     | 
|  Read Cafe con Leche for XML News:  http://www.cafeconleche.org/   |
+----------------------------------+---------------------------------+






More information about the jdom-interest mailing list