[jdom-interest] Processing instruction map issues

Jason Hunter jhunter at servlets.com
Sun May 4 23:32:28 PDT 2003


I've given a lot of talks on JDOM and almost no one in the audience ever
raises wheir hand when I ask who's used PIs.  Few people even know what
PIs are.  So while I like the JDOM support for PIs with attribute-style
name/value pairs, I'm not sure how many people out there even care about
the work we put into the special parse logic.  I don't even use it
myself.  It reminds me of EntityRef where we had known bugs for months
and no one ever reported it.  Some corners of XML just rarely get used
by Java programmers.

But still, seems to me like if we have the logic already written to
support pulling name/value pairs out of a PI data string we might as
well keep it.  It's a pain to write, and it's better for us to write it
once and share it than make the people out there (however few) write it
themselves.  So we should at least keep the getters.

If you have getters, it seems to make sense to have setters/adders.  I'm
OK with addPseudoAttribute().  So then should it get
getPseudoAttribute()?  Guess so.

We could remove it, but PI's a simple class so having a few convenience
functions doesn't hurt, and it's not like it's easy for users to do the
attribute parse work themselves.

-jh-

Elliotte Rusty Harold wrote:
> 
> 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
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list