org.newsml.toolkit
Interface DataContent

All Superinterfaces:
BaseNode, IdNode

public interface DataContent
extends BaseNode, IdNode

Raw inline data in leaf content.

Currently, this interface returns the raw inline data as a DOM node list. That will be awkward for some implementations, especially for any future implementations not based on a DOM tree. Possible future alternatives include returning all of the inline data as a string, and providing mechanisms for decoding encoded inline data (i.e. base64 and similar) to produce binary objects.

Version:
2.0
Author:
Reuters PLC

Method Summary
 org.w3c.dom.NodeList getDOMNodes()
          Get the inline data as a list of DOM nodes.
 String getText()
          Get the inline data as plain text, ignoring any XML markup.
 String getXMLString()
          Get the inline data as a fragment of XML markup.
 void setDOMNodes(org.w3c.dom.NodeList nodes)
          Set the inline data as a list of DOM nodes.
 void setText(String text)
          Set the inline data as plain text, escaping special characters.
 void setXMLString(String xml)
          Parse the supplied string as XML and use it as the inline data.
 
Methods inherited from interface org.newsml.toolkit.BaseNode
getAttr, getChild, getChild, getChild, getChild, getChildCount, getChildCount, getParent, getPath, getSession, getXMLName, getXPath, insertAfter, insertAfter, insertAfter, insertAfter, insertAfterDuid, insertAfterDuid, insertBefore, insertBefore, insertBefore, insertBefore, insertBeforeDuid, insertBeforeDuid, insertChild, insertChild, insertFirst, insertFirst, insertLast, insertLast, removeChild, removeChild, removeSelf, replaceChild, replaceChild, replaceChild, replaceChild, replaceChild, replaceChild, setAttr, setAttr, toXML, toXML, unsetAttr, unsetAttr, writeXML, writeXML
 
Methods inherited from interface org.newsml.toolkit.IdNode
getDuid, getEuid
 

Method Detail

getDOMNodes

public org.w3c.dom.NodeList getDOMNodes()
Get the inline data as a list of DOM nodes.

This method may return more than one top-level node, possibly accompanied by text and whitespace.

Returns:
The list of DOM nodes inside the DataContent element.

setDOMNodes

public void setDOMNodes(org.w3c.dom.NodeList nodes)
Set the inline data as a list of DOM nodes.

This method allows the application to copy a set of already-existing DOM nodes as inline content. The NewsML document will always contain a copy of the nodes supplied, not the originals.

Parameters:
nodes - The nodes to copy into the DataContent.

getText

public String getText()
Get the inline data as plain text, ignoring any XML markup.

This method is most useful when the inline content is base64-encoded binary data or something similar, where XML markup is not relevant and XML character escaping is undesirable.

Returns:
A string of raw text, with no XML character escaping.

setText

public void setText(String text)
Set the inline data as plain text, escaping special characters.

This method is useful for setting inline text without worrying about escaping special XML characters. An application would use this for embedded base64-encoded files, for example.


getXMLString

public String getXMLString()
Get the inline data as a fragment of XML markup.

This method is most useful when the inline content is NITF or XHTML XML markup or something similar, where the markup needs to be preserved for parsing by another software component. Note that the string is *not* guaranteed to be a well-formed XML document, since it may contain more than one top-level element.

Returns:
A string containing a logically-equivalent (*not* identical) XML document that can be passed to a parser for further processing.
See Also:
BaseNode.toXML(boolean), BaseNode.writeXML(java.io.Writer, boolean)

setXMLString

public void setXMLString(String xml)
                  throws NewsMLException
Parse the supplied string as XML and use it as the inline data.

This method is useful when a user wants to construct a string including XML markup and not have the markup escaped in the document. The string must contain a well-formed XML document with a single root element.

Parameters:
xml - The XML string to parse: it must be a well-formed XML document. That means that the return value of #getXMLString is not always acceptable.
Throws:
NewsMLException - If there is an error parsing the XML string.