|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Base interface for all NewsML objects.
The base interface provides basic services for navigation,
modification, and serialization, as well as access to the NewsMLSession
, which allows the client application to execute
queries against the NewsML object tree. All NewsML nodes implement
this interface, directly or indirectly.
For navigation, the primitive methods are getChildCount()
, getChild(int)
, getParent()
,
and getAttr(String)
. For modification, the primitive
methods are insertChild(int,BaseNode)
, replaceChild(int,BaseNode)
, removeChild(int)
, setAttr(Text)
, and unsetAttr(Text)
. There are also many
derived methods for convenience.
Method Summary | |
Text |
getAttr(String xmlName)
Get an attribute-based node by name. |
BaseNode[] |
getChild()
Get an array of child nodes. |
BaseNode |
getChild(int index)
Get a child of the node by position. |
BaseNode[] |
getChild(String xmlName)
Get an array of child nodes with the specified XML name. |
BaseNode |
getChild(String xmlName,
int index)
Get a child of the node by name and position. |
int |
getChildCount()
Count the children for this node. |
int |
getChildCount(String xmlName)
Count the children with the specified name. |
BaseNode |
getParent()
Get the parent of the node in the NewsML content tree. |
BaseNode[] |
getPath()
Get the path from the root node to this node. |
NewsMLSession |
getSession()
Get the NewsML session associated with the package. |
String |
getXMLName()
Get the XML element name associated with the node. |
String |
getXPath()
Get the XPath from the document root to this node. |
BaseNode |
insertAfter(String xmlName,
BaseNode child)
Insert a new child after an existing named child. |
BaseNode[] |
insertAfter(String xmlName,
BaseNode[] children)
Insert new child nodes after the last existing named child. |
BaseNode |
insertAfter(String xmlName,
int index,
BaseNode child)
Insert a new child after an existing named child. |
BaseNode[] |
insertAfter(String xmlName,
int index,
BaseNode[] children)
Insert an array of child nodes after a named node. |
BaseNode |
insertAfterDuid(String duid,
BaseNode child)
Insert a new child after one with a specific Duid. |
BaseNode[] |
insertAfterDuid(String duid,
BaseNode[] children)
Insert new child nodes after one with a specific Duid. |
BaseNode |
insertBefore(String xmlName,
BaseNode child)
Insert a new child before the first existing named child. |
BaseNode[] |
insertBefore(String xmlName,
BaseNode[] children)
Insert an array of child nodes before the first named node. |
BaseNode |
insertBefore(String xmlName,
int index,
BaseNode child)
Insert a new child before an existing named child. |
BaseNode[] |
insertBefore(String xmlName,
int index,
BaseNode[] children)
Insert an array of child nodes before a named node. |
BaseNode |
insertBeforeDuid(String duid,
BaseNode child)
Insert a new child before one with a specific Duid. |
BaseNode[] |
insertBeforeDuid(String duid,
BaseNode[] children)
Insert new child nodes before one with a specific Duid. |
BaseNode |
insertChild(int index,
BaseNode child)
Insert a new child into the node. |
BaseNode[] |
insertChild(int index,
BaseNode[] children)
Insert an array of new children into the node. |
BaseNode |
insertFirst(BaseNode child)
Insert a new child before all existing children (prepend). |
BaseNode[] |
insertFirst(BaseNode[] children)
Insert new child nodes before all existing children (prepend). |
BaseNode |
insertLast(BaseNode child)
Insert a new child after all existing children (append). |
BaseNode[] |
insertLast(BaseNode[] children)
Insert new child nodes after all existing children (append). |
BaseNode |
removeChild(int index)
Remove a child of this node. |
BaseNode |
removeChild(String xmlName,
int index)
Remove an existing child node. |
void |
removeSelf()
Remove this node from the NewsML tree. |
BaseNode |
replaceChild(int index,
BaseNode child)
Replace an existing child with another node. |
BaseNode |
replaceChild(int index,
BaseNode[] children)
Replace an existing child with an array of nodes. |
BaseNode |
replaceChild(String xmlName,
BaseNode child)
Replace the first named child node. |
BaseNode |
replaceChild(String xmlName,
BaseNode[] children)
Replace the first named child node with an array of nodes. |
BaseNode |
replaceChild(String xmlName,
int index,
BaseNode child)
Replace a named child node. |
BaseNode |
replaceChild(String xmlName,
int index,
BaseNode[] children)
Replace a named child node with an array of nodes. |
Text |
setAttr(String name,
String value)
Set an attribute value directly from a string. |
Text |
setAttr(Text attr)
Set an attribute-based node, replacing any existing value. |
String |
toXML(boolean isDocument)
Get an XML rendition of this node. |
String |
toXML(String encoding,
String internalSubset)
Get an XML document rendition of this node. |
Text |
unsetAttr(String name)
Remove an attribute by name. |
Text |
unsetAttr(Text attr)
Unset an attribute-based node. |
void |
writeXML(Writer output,
boolean isDocument)
Serialize this node as XML. |
void |
writeXML(Writer output,
String encoding,
String internalSubset)
Serialize a node as an XML document. |
Method Detail |
public String getXMLName()
public String getXPath()
public NewsMLSession getSession()
public BaseNode getParent()
getChild(int)
public int getChildCount()
See getChild(int)
for information on what is and is
not counted as a child here.
getChildCount(String)
public int getChildCount(String xmlName)
See getChild(int)
for information on what
is and is not counted as a child here.
xmlName
- The XML name of the children to count.getXMLName()
,
getChildCount()
public BaseNode getChild(int index)
This method uses the XML notion of parent/child, not the NewsML notion. That difference can matter quite a bit; for example, while the get* methods for information in subelements and information in attributes are indistinguishable in the NewsML Toolkit API, this method will deal only with the element children.
Some elements in the XML are not represented directly in the NewsML toolkit, such as the content of the DataContent element; in that case, the element will not be counted as a child.
Since the result of invoking this method can be
unpredictable in so many ways, it is recommend to use the named
getChild(String, int)
method whenever possible.
index
- The index of the child, zero-based, numbered
sequentially, or -1 for the last child.getParent()
,
getChild(String,int)
public BaseNode getChild(String xmlName, int index)
See getChild(int)
for information on what
is and is not counted as a child here.
xmlName
- The XML name of the children to use.index
- The index of the child, zero-based, numbered
sequentially, counting only children with the given XML name, or
-1 for the last child with the name specified.getChild(int)
public BaseNode[] getChild()
See getChild(int)
for information on what
is and is not counted as a child here.
public BaseNode[] getChild(String xmlName)
See getChild(int)
for information on what
is and is not counted as a child here.
xmlName
- The XML name of the child nodes to return.public BaseNode insertChild(int index, BaseNode child)
This method works only for NewsML nodes based on XML elements.
index
- If 0 or greater, the position at which to insert the
new child (increasing the index of all subsequent children); if -1,
insert the child at the end of the existing children.child
- The new node to add.insertChild(int,BaseNode[])
public BaseNode[] insertChild(int index, BaseNode[] children)
This method works only for NewsML nodes based on XML elements.
index
- If 0 or greater, the position at which to insert the
new children (increasing the index of all subsequent children); if -1,
insert the child at the end of the existing children.children
- An array of new nodes to add.insertChild(int,BaseNode)
public BaseNode insertFirst(BaseNode child)
child
- The new child to insert in the first position.public BaseNode[] insertFirst(BaseNode[] children)
children
- The new child nodes to insert in the first position.public BaseNode insertLast(BaseNode child)
child
- The new child to insert in the last position.public BaseNode[] insertLast(BaseNode[] children)
children
- The new child nodes to insert in the last position.public BaseNode insertBefore(String xmlName, int index, BaseNode child)
xmlName
- The XML name of the existing child.index
- The index of the existing child relative to others
with the same name, or -1 for the last one.child
- The new child to insert before the existing one.public BaseNode insertBefore(String xmlName, BaseNode child)
xmlName
- The XML name of the existing child.child
- The new child to insert before the existing one.public BaseNode[] insertBefore(String xmlName, int index, BaseNode[] children)
xmlName
- The name of the existing node.index
- The index of the existing node, relative to other
nodes with the same name, or -1 for the last one.children
- The array of child nodes to insert before the
existing one.public BaseNode[] insertBefore(String xmlName, BaseNode[] children)
xmlName
- The name of the existing node.children
- The array of child nodes to insert before the
existing one.public BaseNode insertBeforeDuid(String duid, BaseNode child)
Note that this method works only on the immediate children
of a node; it does not search the entire document for the Duid
required (see NewsMLSession.getNodeByDuid(String)
).
Duid
- the Duid of the existing child.child
- The new child to insert before the existing one.public BaseNode[] insertBeforeDuid(String duid, BaseNode[] children)
Note that this method works only on the immediate children
of a node; it does not search the entire document for the Duid
required (see NewsMLSession.getNodeByDuid(String)
).
Duid
- the Duid of the existing child.children
- The new child nodes to insert before the
existing one.public BaseNode insertAfter(String xmlName, int index, BaseNode child)
xmlName
- The XML name of the existing child.index
- The index of the existing child relative to others
with the same name, or -1 for the last one.child
- The new child to insert after the existing one.public BaseNode insertAfter(String xmlName, BaseNode child)
xmlName
- The XML name of the existing child.child
- The new child to insert after the existing one.public BaseNode[] insertAfter(String xmlName, int index, BaseNode[] children)
xmlName
- The name of the existing node.index
- The index of the existing node, relative to other
nodes with the same name, or -1 for the last one.children
- The array of child nodes to insert after the
existing one.public BaseNode[] insertAfter(String xmlName, BaseNode[] children)
xmlName
- The XML name of the existing child.children
- The new child nodes to insert before the existing one.public BaseNode insertAfterDuid(String duid, BaseNode child)
Note that this method works only on the immediate children
of a node; it does not search the entire document for the Duid
required (see NewsMLSession.getNodeByDuid(String)
).
Duid
- the Duid of the existing child.child
- The new child to insert after the existing one.public BaseNode[] insertAfterDuid(String duid, BaseNode[] children)
Note that this method works only on the immediate children
of a node; it does not search the entire document for the Duid
required (see NewsMLSession.getNodeByDuid(String)
).
Duid
- the Duid of the existing child.children
- The new child nodes to insert after the existing one.public BaseNode replaceChild(int index, BaseNode child)
This method works only for NewsML nodes based on XML elements.
index
- The position of the child to replace, or -1 for
the last child.child
- The new child to be inserted.public BaseNode replaceChild(int index, BaseNode[] children)
This method works only for NewsML nodes based on XML elements.
index
- The position of the child to replace, or -1 for
the last child.children
- The new child nodes to be inserted.public BaseNode replaceChild(String xmlName, int index, BaseNode child)
xmlName
- The name of the child node to replace.index
- The index of the existing child node relative to
others with the same name, or -1 for the last one.child
- The new replacement child.replaceChild(int,BaseNode)
public BaseNode replaceChild(String xmlName, BaseNode child)
xmlName
- The name of the child node to replace.child
- The new replacement child.replaceChild(int,BaseNode)
public BaseNode replaceChild(String xmlName, int index, BaseNode[] children)
xmlName
- The name of the child node to replace.index
- The index of the existing child node relative to
others with the same name, or -1 for the last one.children
- An array of nodes to replace the node.replaceChild(int,BaseNode)
public BaseNode replaceChild(String xmlName, BaseNode[] children)
xmlName
- The name of the child node to replace.children
- An array of nodes to replace the node.replaceChild(int,BaseNode)
public BaseNode removeChild(int index)
This method works only for NewsML nodes based on XML elements.
index
- The index of the child to remove, or -1 for the
last child.public BaseNode removeChild(String xmlName, int index)
xmlName
- The name of the child node to remove.index
- The index of the child node to remove releative to
others with the same name, or -1 for the last one.removeChild(int)
public void removeSelf() throws NewsMLException
WARNING: removing a node may result in an invalid NewsML tree. Don't use this method unless you know what you're doing.
This method will work for nodes represented as XML elements, but not for nodes represented as XML attributes. It will also fail for the root node of the NewsML tree (often, but not always "NewsML") and will throw a NewsMLException for all failures.
If the implementation does not support modification, it may also throw an exception.
NewsMLException
- if the implementation cannot remove
this node for any reason.public Text getAttr(String xmlName)
xmlName
- The XML name of the attribute (with the leading
'@').public Text setAttr(Text attr)
node
- A BaseNode based on an XML attribute.public Text setAttr(String name, String value)
This method invokes the Text.setString(String)
method on the Text node associated with the named attribute,
creating the Text node first if necessary.
name
- The XML name of the attribute, including leading '@'.value
- The string value of the attribute.setAttr(Text)
.setAttr(Text)
,
unsetAttr(String)
public Text unsetAttr(Text attr)
node
- A BaseNode based on an XML attribute. The value
doesn't matter; only the XML name will be used.public Text unsetAttr(String name)
This method removes any attribute with the name specified.
name
- The name of the attribute to remove.unsetAttr(Text)
,
setAttr(String,String)
public BaseNode[] getPath()
public void writeXML(Writer output, boolean isDocument) throws IOException
This method will create XML markup representing the current node and all of its descendants. It will not reproduct the original XML markup character-for-character, but will create a structurally-equivalent version. The method works on the raw XML level, and has no specialized knowledge of Namespaces (yet).
output
- The character stream to which the XML should
be written (this method will not close the stream).isDocument
- True if this node is to represent a complete
XML document (with DOCTYPE declaration and prolog), false
otherwise.IOException
- if there is an error writing the
document.toXML(boolean)
public void writeXML(Writer output, String encoding, String internalSubset) throws IOException
This method serializes a NewsML node like writeXML(Writer,boolean)
, except that the node is
always made into a full XML docuument, and that the
provided character encoding and internal DTD subset will be
used in place of the defaults.
output
- The character stream to which the XML should
be written (this method will not close the stream).encoding
- The encoding string to be used in the XML
declaration, or null to use the default. Note that this will
not affect the encoding actually used by the Writer -- it is
the application's responsibility to ensure that the two
correspond.internalSubset
- The internal DTD subset to use, the empty
string for an empty subset, or null to use the default.toXML(String,String)
public String toXML(boolean isDocument)
See writeXML(Writer,boolean)
for information on the
serialization.
isDocument
- True if this node is to represent a complete
XML document (with DOCTYPE declaration and prolog), false
otherwise.writeXML(Writer,boolean)
public String toXML(String encoding, String internalSubset)
See writeXML(Writer,String,String)
for details.
encoding
- The encoding to include in the XML declaration,
or null to use the default.internalSubset
- The internal DTD subset to use, the empty
string for an empty subset, or null to use the default.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |