edu.mit.csail.sdg.alloy4
Class XMLNode

java.lang.Object
  extended by edu.mit.csail.sdg.alloy4.XMLNode
All Implemented Interfaces:
java.lang.Iterable<XMLNode>

public final class XMLNode
extends java.lang.Object
implements java.lang.Iterable<XMLNode>

Immutable; this class represents an XML element node.


Constructor Summary
XMLNode(java.io.File file)
          Constructs the root XMLNode by parsing an entire XML document.
XMLNode(java.io.Reader reader)
          Constructs the root XMLNode by parsing an entire XML document, then close the reader afterwards.
XMLNode(java.io.Reader reader, boolean parseText)
          Constructs the root XMLNode by parsing an entire XML document, then close the reader afterwards.
 
Method Summary
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> attributes()
          Returns an unmodifiable view of the attributes.
 int count()
          Returns the number of direct subnodes.
 java.lang.String getAttribute(java.lang.String name)
          Returns the value associated with the given attribute name; if the attribute doesn't exist, return "".
 java.lang.String getAttribute(java.lang.String name, java.lang.String defaultValue)
          Returns the value associated with the given attribute name; if the attribute doesn't exist, return the defaultValue.
 java.lang.Iterable<XMLNode> getChildren(java.lang.String type)
          Returns a read-only iteration of the immediate subelements whose type is equal to the given type.
 java.lang.String getText()
          Returns the text if this is a text node, returns "" otherwise.
 java.lang.String getType()
          Returns the type of the element.
 boolean is(java.lang.String type)
          Returns true if the type of this element is equal to the given type.
 java.util.Iterator<XMLNode> iterator()
          Returns a read-only iterator over the immediate subelements.
 java.lang.String toString()
          Dump the content to a String.
 void toString(java.lang.StringBuilder sb, int indent)
          Dump the content to a StringBuilder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLNode

public XMLNode(java.io.Reader reader,
               boolean parseText)
        throws java.io.IOException
Constructs the root XMLNode by parsing an entire XML document, then close the reader afterwards.

Throws:
java.io.IOException

XMLNode

public XMLNode(java.io.Reader reader)
        throws java.io.IOException
Constructs the root XMLNode by parsing an entire XML document, then close the reader afterwards.

Throws:
java.io.IOException

XMLNode

public XMLNode(java.io.File file)
        throws java.io.IOException
Constructs the root XMLNode by parsing an entire XML document.

Throws:
java.io.IOException
Method Detail

count

public int count()
Returns the number of direct subnodes.


attributes

public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> attributes()
Returns an unmodifiable view of the attributes.


toString

public java.lang.String toString()
Dump the content to a String.

Overrides:
toString in class java.lang.Object

toString

public void toString(java.lang.StringBuilder sb,
                     int indent)
Dump the content to a StringBuilder.


getType

public java.lang.String getType()
Returns the type of the element.


getText

public java.lang.String getText()
Returns the text if this is a text node, returns "" otherwise.


is

public boolean is(java.lang.String type)
Returns true if the type of this element is equal to the given type.


iterator

public java.util.Iterator<XMLNode> iterator()
Returns a read-only iterator over the immediate subelements.

Specified by:
iterator in interface java.lang.Iterable<XMLNode>

getChildren

public java.lang.Iterable<XMLNode> getChildren(java.lang.String type)
Returns a read-only iteration of the immediate subelements whose type is equal to the given type.


getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns the value associated with the given attribute name; if the attribute doesn't exist, return "".


getAttribute

public java.lang.String getAttribute(java.lang.String name,
                                     java.lang.String defaultValue)
Returns the value associated with the given attribute name; if the attribute doesn't exist, return the defaultValue.