Xml

Wrapper for a native XML tree.

This class is an implementation of a simple XML tree. It is not XML DOM-compliant, cannot mix text nodes with tags and does not support comments. It does not support XML validation against DTD or RELAX NG either. However, it is much faster.

Since it is based on Pointer, all methods in this class do not require to be run on the main thread, however they require you to run them always on the same thread. To pass it to a different thread, you can change its thread but beware of the possible consequences.

Please read documentation of Pointer on how you should manage pointers lifetime.

Constructors

Link copied to clipboard
constructor(@NonNull name: String)
Construct an empty XML root.
constructor(@NonNull name: String, @Nullable value: String)
Construct XML root with a value.

Functions

Link copied to clipboard
open fun changeThread()
Change thread this pointer can be accessed from to the current one.
Link copied to clipboard
open fun clone(): Xml
Deep-copy the XML tree.
Link copied to clipboard
open fun close()
Close the native pointer.
abstract fun close()
Link copied to clipboard
open fun copyChild(@NonNull child: Xml): Xml
Deep copy a child into the tree.
Link copied to clipboard
open fun createChild(@NonNull name: String): Xml
Create an empty child node.
open fun <T> createChild(@NonNull name: String, @NonNull value: T): Xml
open fun createChild(@NonNull name: String, @NonNull value: Boolean): Xml
open fun createChild(@NonNull name: String, @Nullable value: String): Xml
Create a child node with a value.
Link copied to clipboard
open fun <T> createChildren(@NonNull name: String, @NonNull values: Array<T>): Array<Xml>
Create child nodes with values.
Link copied to clipboard
open fun dump(@NonNull stream: OutputStream)
Dump the XML tree to an output stream.
Link copied to clipboard
open fun equals(@Nullable o: Any): Boolean
Check if this XML tree is equal to another object.
Link copied to clipboard
Get an attribute from the tree.
Link copied to clipboard
Get all attributes.
Link copied to clipboard
open fun getChild(@NonNull name: String): Xml
Get a child node by name.
Link copied to clipboard
Get child node at path.
Link copied to clipboard
Opinionated version of getOrCreateChild which created empty nodes if the children don't exist.
Link copied to clipboard
Get all children.
Link copied to clipboard
Get a child's value.
Link copied to clipboard
open fun getChildWithAttribute(@NonNull name: String, @NonNull attributeName: String, @Nullable attributeValue: String): Xml
Get first child with a specified attribute.
Link copied to clipboard
open fun getName(): String
Get name of the node.
Link copied to clipboard
open fun <T> getOrCreateChild(@NonNull name: String, @NonNull defaultValueSupplier: Supplier<T>): Xml
Create a child node with a value.
Link copied to clipboard
open fun getRoot(): Xml
Get the tree root.
Link copied to clipboard
Get value of the node.
Link copied to clipboard
Get child node value or child node attribute value at path.
Link copied to clipboard
open fun hasAttribute(@NonNull name: String): Boolean
Check if the node has an attribute.
open fun hasAttribute(@NonNull name: String, @NonNull value: String): Boolean
Check if this node has an attribute with a specified value.
Link copied to clipboard
open fun hashCode(): Int
Get hash code.
Link copied to clipboard
open fun isClosed(): Boolean
Check if the native pointer is closed.
Link copied to clipboard
open fun isMutable(): Boolean
Check if the native pointer is mutable.
Link copied to clipboard
open fun isRoot(): Boolean
Check if this tree is the root.
Link copied to clipboard
open fun isSamePointer(@NonNull other: Pointer): Boolean
Check if the pointer is the same as in another pointer.
Link copied to clipboard
open fun load(@NonNull file: File): Xml
open fun load(@NonNull file: String): Xml
Load a XML file into a tree.
Link copied to clipboard
open fun parse(@Nullable stream: InputStream): Xml
Parse a XML stream into a tree.
open fun parse(@Nullable xml: String): Xml
Parse a XML string into a tree.
Link copied to clipboard
open fun removeAttribute(@NonNull name: String)
Remove an attribute.
Link copied to clipboard
open fun removeChild(@NonNull name: String): Boolean
Remove a child from the tree.
Link copied to clipboard
open fun removeChildAtIndex(index: Int): Boolean
Remove a child from the tree.
Link copied to clipboard
open fun replaceChild(@NonNull child: Xml): Boolean
open fun replaceChild(@NonNull name: String, @Nullable value: String): Boolean
Replace a child.
Link copied to clipboard
open fun save(@NonNull file: File): Boolean
open fun save(@NonNull file: String): Boolean
Save a XML tree into a file.
Link copied to clipboard
open fun setAttribute(@NonNull name: String, @Nullable value: String)
Set an attribute.
Link copied to clipboard
open fun setChild(@NonNull child: Xml): Xml
Move a child into the tree.
Link copied to clipboard
open fun setChildValue(@NonNull name: String, @Nullable value: String)
Set a child's value.
Link copied to clipboard
open fun setValue(@Nullable value: String)
Set value of the node.
Link copied to clipboard
open fun toString(): String
open fun toString(pretty: Boolean): String
Return the XML tree as a XML string.
Link copied to clipboard
open fun toXml(@NonNull name: String, @Nullable object: Any): Xml
Create XML tree from Java object.
Link copied to clipboard
open fun withAttribute(name: String, value: String): Xml
Fluent wrapper for setAttribute.
Link copied to clipboard
open fun withAttributes(attributes: Map<String, String>): Xml
Fluent wrapper for setAttribute.