[jdom-interest] Philosophical XML (was API Inertia)
Paul Philion
philion at acmerocket.com
Wed May 2 10:21:39 PDT 2001
Rusty -
Forgive me for using the term "Element". Perhaps I should use Node...
public class TextNode implements Node {
private String text;
private Node parent;
public String getValue() { return this.text; }
public String getAttribute(String name) { return null; }
public Iterator getAttributeNames() { return EmptyIterator.instance(); }
public Iterator children() { return EmptyIterator.instance(); }
public Element getParent() { return this.parent; }
public boolean hasChildren() { return false; }
public int numChildren() { return 0; }
public Element getChild(int i) { return null; /* or throw Exception */ }
public String getName() { return "#text"; }
public Namespace getNamespace() { return null; }
}
Note: EmptyIterator is a singleton that always returns false for hasNext()
and null for next(). Very useful (replacing null, with negligible overhead)
when dealing with any sort of recursive algorithms or patterns.
CommentNode and ProcessingInstructionNode would be *very* similar. In fact,
I would recommend an AbstractNode based on the above implementation (class
is flagged abstract, all methods are implemented) that ElementNode would
extend to implement the child and attribute handling code.
Another note: Ordering of child nodes within a parent is significant.
Ordering of attributes of an element is not. Order of attributes is not (and
should not) validated. IMHO, attribute name-value pairs can easily be stored
in a Map structure (as Strings) and referenced the same way. I strongly
question the need for a separate Attribute class/interface.
- Paul Philion
> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Elliotte Rusty Harold
> Sent: Wednesday, May 02, 2001 12:16 PM
> To: jdom-interest at jdom.org
> Subject: RE: [jdom-interest] Philosophical XML (was API Inertia)
>
>
> At 11:39 AM -0400 5/2/01, Paul Philion wrote:
> >The below case is very simple. Element <p> contains three elements:
> >
> >- a text element with the value "This is..."
> >- an element <strong>, containing one text element "word"
> >- a text element containing "in the middle."
> >
>
> No, they're not elements. They have no start and end tags. They can't
> have attributes. They can't contain other nodes. Your mental model
> does not match what XML 1.0 actually specifies!
>
> >Personally, I have never understood the need for "mixed
> content". There are
> >only elements.
> >
>
> That's because you're thinking of data-oriented, record-oriented
> applications. These application have various other characteristics
> you're implicitly assuming; for instance, that order isn't very
> important.
>
> However, order, mixed content, and other features of XML are crucial
> for narrative documents such as books, articles, essays, letters,
> pamphlets, and so forth. If JDOM ignores this, then it is not a
> faithful XML API.
> --
>
> +-----------------------+------------------------+-------------------+
> | Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
> +-----------------------+------------------------+-------------------+
> | The XML Bible (IDG Books, 1999) |
> | http://metalab.unc.edu/xml/books/bible/ |
> | http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/ |
> +----------------------------------+---------------------------------+
> | Read Cafe au Lait for Java News: http://metalab.unc.edu/javafaq/ |
> | Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/ |
> +----------------------------------+---------------------------------+
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yourad
dr at yourhost.com
More information about the jdom-interest
mailing list