Class XmlNode
java.lang.Object
org.libxmq.imp.xml.XmlNode
- All Implemented Interfaces:
XMQNode
- Direct Known Subclasses:
XmlAttr, XmlComment, XmlDocument, XmlDtd, XmlDtdDecl, XmlElement, XmlEntityDecl, XmlEntityRef, XmlPI, XmlText, XPathNamespaceNode
Base class of all nodes in the xmq DOM.
The DOM is modelled after libxml2 (Copyright (C) 1998-2012 Daniel Veillard,
MIT license), since the C version of xmq uses libxml2 and the java version
must behave identically. Like libxml2, the nodes are linked with
parent/children/last/next/prev pointers, entity references are kept as
nodes, and adding a text node next to another text node merges them.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd a child like libxml2 xmlAddChild.Insert a sibling after this node, like libxml2 xmlAddNextSibling (but without text merging).Insert a sibling before this node, like libxml2 xmlAddPrevSibling (but without text merging).Append a child without merging adjacent text nodes.children()Returns a new list with the children of this node.content()Returns the text content of text like nodes (text, cdata, comment, pi).doc()Returns the document owning this node.Returns the first child.fullName()Returns the full name, ie prefix:name if the node has a namespace with a prefix.booleanReturns true if this node has children.Returns the last child.intline()Returns the source line of the node, like libxml2 xmlGetLineNo: elements get the line where their start tag ends, text the line where its first chunk was read, comments, processing instructions and cdata sections the line where they end.name()Returns the name of the node.next()Returns the next sibling.intCount the children.parent()Returns the parent node.prev()Returns the previous sibling.voidReplace this node with another node, like libxml2 xmlReplaceNode.voidsetContent(String content) Set the content of a text like node.voidsetLine(int line) Set the source line of the node.voidSet the name of the node.Returns the string value of the node, like libxml2 xmlNodeGetContent.toString()abstract XMQNodeTypetype()Returns the type of this node.voidunlink()Remove this node from its parent and siblings, like libxml2 xmlUnlinkNode.
-
Constructor Details
-
XmlNode
Create a node with a name.- Parameters:
name- The node name, null for nameless nodes.
-
-
Method Details
-
type
Returns the type of this node. -
name
-
setName
-
line
public int line()Returns the source line of the node, like libxml2 xmlGetLineNo: elements get the line where their start tag ends, text the line where its first chunk was read, comments, processing instructions and cdata sections the line where they end. -
setLine
-
parent
-
firstChild
Returns the first child.- Specified by:
firstChildin interfaceXMQNode- Returns:
- The first child or null.
-
lastChild
-
next
-
prev
-
doc
Returns the document owning this node. -
hasChildren
public boolean hasChildren()Returns true if this node has children.- Returns:
- True if there is at least one child.
-
children
-
numChildren
public int numChildren()Count the children.- Specified by:
numChildrenin interfaceXMQNode- Returns:
- The number of children.
-
content
Returns the text content of text like nodes (text, cdata, comment, pi). Returns null for other nodes, usetextContent()for the concatenated text of an element. -
setContent
Set the content of a text like node. For an element, all children are replaced with a single text node, like libxml2 xmlNodeSetContent.- Specified by:
setContentin interfaceXMQNode- Parameters:
content- The new content.
-
textContent
Returns the string value of the node, like libxml2 xmlNodeGetContent. For an element this is the concatenation of all descendant text, where entity references contribute nothing (entities are never expanded implicitly) and character references kept as nodes their character.- Specified by:
textContentin interfaceXMQNode- Returns:
- The text content, never null.
-
appendRaw
-
addChild
Add a child like libxml2 xmlAddChild. If the child is a text node and the current last child is also a text node, then the text is merged into the existing last child, and the existing node is returned. -
addPrevSibling
Insert a sibling before this node, like libxml2 xmlAddPrevSibling (but without text merging).- Specified by:
addPrevSiblingin interfaceXMQNode- Parameters:
n- The node to insert.- Returns:
- The inserted node.
-
addNextSibling
Insert a sibling after this node, like libxml2 xmlAddNextSibling (but without text merging).- Specified by:
addNextSiblingin interfaceXMQNode- Parameters:
n- The node to insert.- Returns:
- The inserted node.
-
unlink
-
replaceWith
Replace this node with another node, like libxml2 xmlReplaceNode.- Specified by:
replaceWithin interfaceXMQNode- Parameters:
n- The replacement.
-
fullName
-
toString
-