Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Swap Node.toString() and Node.toXML()

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Swap Node.toString() and Node.toXML()
  • Date: Fri, 05 Dec 2003 15:56:27 -0800

Hi,

Please consider swapping the meaning of Node.toString() and Node.toXML() and renaming the new toXML() --> toShortString() or toDebugXML() or similar.

IMHO, and the principle of least surprise, the standard string representation of an XML Object, i.e. toString() should not yield a debug info, but the full XML. Whoever needs abbreviated debug info should explicitly call toShortString().

In my experience, even for logging, most of the time one needs the full XML (new toString()), rather than some abbreviated data with max. 40 chars per Text object.

I think this would be easier and more intuitive, for example when passing xom objects to third parties.

Also, one might even have toString() delegate to a serializer configured for indented pretty printing, since this is what one wants most of the time anyway. (This would, of course, not preclude other explicit serializations such as canonical, etc.)

If this is indeed deemed a good idea, we should do it before API freeze, as this might break existing code in not so easily detectable cases.

If not, please let me know the reasoning for the current behaviour.

To recap, here is the current javadoc:

/**
* <p>
* Returns a string representation of this node suitable for
* debugging and diagnosis. This is <em>not</em>
* the XML representation of this node.
* </p>
*
* @return a non-XML string representation of this node
* @see java.lang.Object#toString()
*/
public abstract String toString();


/**
* <p>
* Returns the actual XML form of this node, such as might be
* copied and pasted from the original document.
* </p>
*
* @return a String containing an XML representation of this node
*/
public abstract String toXML();







Archive powered by MHonArc 2.6.24.

Top of Page