public class XmlAst extends AnnotatedAst implements XmlTokenTypes
The token types of an XML AST represent the structural elements of an XML Document Object Model (e.g., DTD, element, attribute, text node, etc.).
Currently, line and column number and filename information is not used.
XmlTokenTypes
,
Serialized FormModifier and Type | Field and Description |
---|---|
private static java.util.Map |
TOKEN_NAMES
Map of token types to token names
|
private static java.util.Map |
TOKEN_TYPES
Map of token names to token types
|
ATTR_SET, ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, CONTENT, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, INTERNAL_SUBSET, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, PUBLIC_ID, SYSTEM_ID, TEXT_NODE
Constructor and Description |
---|
XmlAst()
Default constructor.
|
XmlAst(Aast parent,
int type,
java.lang.String text)
Convenience constructor to set token type, text, and parent.
|
XmlAst(int type,
java.lang.String text)
Convenience constructor to set token type and text.
|
XmlAst(antlr.Token token)
Constructor which accepts and wrappers token.
|
Modifier and Type | Method and Description |
---|---|
static org.w3c.dom.Document |
astToDom(XmlAst ast)
Generate a DOM
Document object based upon an XML AST. |
static org.w3c.dom.Node |
astToDomNode(XmlAst ast,
org.w3c.dom.Document doc,
org.w3c.dom.Node parent)
Generate a DOM hierarchy based upon an XML AST.
|
static XmlAst |
domToAst(Aast parent,
org.w3c.dom.Node domNode,
boolean trimWhite)
Generate an AST based upon a Document Object Model node hierarchy.
|
static XmlAst |
domToAst(org.w3c.dom.Node domNode)
Generate an AST based upon a Document Object Model node hierarchy.
|
java.lang.String |
getSymbolicTokenType()
Returns the symbolic representation of this AST's token type.
|
java.lang.String |
lookupTokenName(int type)
Translates an integer value of a token type into the associated
human readable text representation.
|
int |
lookupTokenType(java.lang.String tokenName)
Translates a text representation of a token type into the
actual integer value.
|
static void |
main(java.lang.String[] args)
Test harness.
|
static java.lang.Object |
resolveConstant(java.lang.String tokenName)
Resolve the given token name to a numeric token type.
|
absolutePath, ancestor, ancestor, ancestor, annotationCount, annotationKeys, annotationSize, brainwash, brainwash, clearAnnotations, clearIds, compareWith, compareWith, descendant, descendant, descendant, downPath, dumpTree, dumpTree, duplicate, duplicate, duplicateFresh, duplicateFresh, fixupParent, fixups, fixups, getAncestor, getAncestor, getAncestor, getAnnotation, getAnnotation, getAnnotationList, getChildAt, getColumn, getDepth, getDescriptiveTokenText, getFilename, getId, getImmediateChild, getImmediateChild, getIndexPos, getLastImmediateChild, getLeftShadowNode, getLine, getLocal, getNumChildren, getNumImmediateChildren, getNumImmediateChildren, getNumLeftSiblings, getNumRightSiblings, getParent, getPath, getPrevSibling, getRightShadowNode, getShadowNodeList, graft, graftAt, graftCopyTo, graftCopyTo, initialize, initialize, intern, isAncestorOf, isAnnotation, isHidden, isLeaf, isRoot, iterator, iterator, iterator, move, nearestEnclosing, putAnnotation, putAnnotation, putAnnotation, putAnnotation, putAnnotation, putAnnotation, putAnnotation, putAnnotation, putAnnotation, putAnnotationObject, relativePath, remove, removeAnnotation, removeAnnotation, setColumn, setHidden, setId, setLine, setLocal, setParent, sibling, toString, toStringVerbose, upPath
addChild, decode, encode, equals, equalsList, equalsListPartial, equalsTree, equalsTreePartial, findAll, findAllPartial, getFirstChild, getNextSibling, getNumberOfChildren, getTokenNames, removeChildren, setFirstChild, setNextSibling, setVerboseStringConversion, toStringList, toStringTree, xmlSerialize, xmlSerializeNode, xmlSerializeRootClose, xmlSerializeRootOpen
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addChild, equals, equalsList, equalsListPartial, equalsTree, equalsTreePartial, findAll, findAllPartial, getFirstChild, getNextSibling, getNumberOfChildren, getText, getType, initialize, setFirstChild, setNextSibling, setText, setType, toStringList, toStringTree
private static final java.util.Map TOKEN_NAMES
private static final java.util.Map TOKEN_TYPES
public XmlAst()
public XmlAst(antlr.Token token)
token
- Token upon which this node is based.public XmlAst(int type, java.lang.String text)
type
- Token type.text
- AST text. May be null
.public XmlAst(Aast parent, int type, java.lang.String text)
parent
, and parent
is set as this AST's parent.parent
- Parent AST. If null
, the resulting AST is an
orphan.type
- Token type.text
- AST text. May be null
.public static java.lang.Object resolveConstant(java.lang.String tokenName)
tokenName
- String constant representing token name.null
if name could not
be resolved.public static org.w3c.dom.Document astToDom(XmlAst ast) throws javax.xml.parsers.ParserConfigurationException
Document
object based upon an XML AST.
Assumes the AST hierarchy is not malformed.ast
- XML AST upon which the DOM node hierarchy will be based.
This AST node must be the document root (i.e., type
DOCUMENT_NODE
).ast
.javax.xml.parsers.ParserConfigurationException
- if the XML parser has been configured incorrectly.public static org.w3c.dom.Node astToDomNode(XmlAst ast, org.w3c.dom.Document doc, org.w3c.dom.Node parent) throws javax.xml.parsers.ParserConfigurationException
ast
represents an XML document root, no other parameters are necessary.
This method recursively calls itself to populate each level of nodes
with its appropriate children. Assumes the AST hierarchy is not
malformed.ast
- XML AST upon which the DOM node hierarchy will be based.doc
- Document Object Model document which is used to create
all necessary subnodes. Should be null
iff
ast
represents the document root (i.e., is of
type DOCUMENT_NODE
. In this case, a Document
instance will be created and passed recursively for use
at lower levels.parent
- The DOM node to which the newly created child node will be
appended. It should be null
if ast
represents the document root.ast
.javax.xml.parsers.ParserConfigurationException
- if the XML parser has been configured incorrectly.public static XmlAst domToAst(org.w3c.dom.Node domNode)
domNode
- A DOM node whose structure and contents will be used to
generate the AST.domNode
.public static XmlAst domToAst(Aast parent, org.w3c.dom.Node domNode, boolean trimWhite)
parent
- Optional parent AST for the new AST. May be null
.domNode
- A DOM node whose structure and contents will be used to
generate the AST.trimWhite
- If true
, leading and trailing whitespace will
be trimmed from the value string (if any) of a node before
inserting that text into a content AST. Extra space and
formatting characters, such as newlines, which are embedded
within the value text are not
removed. This flag also causes empty TEXT nodes to be
discarded, such that no corresponding AST is created for
such nodes.domNode
.public int lookupTokenType(java.lang.String tokenName)
lookupTokenType
in interface Aast
lookupTokenType
in class AnnotatedAst
tokenName
- The text representation of the token type.public java.lang.String lookupTokenName(int type)
lookupTokenName
in interface Aast
lookupTokenName
in class AnnotatedAst
type
- The integer token type.null
if
no match was found.public java.lang.String getSymbolicTokenType()
getSymbolicTokenType
in interface Aast
getSymbolicTokenType
in class AnnotatedAst
public static void main(java.lang.String[] args)
stdout
;
xml_ast_test.xml
in the
current directory.
args
- Expects a single argument: the name of the XML file to parse.