TextXML Format
Sponge uses a predefined form of XML called »TextXML« to denote the coloring and styling of text. A description of the elements and attributes are as follows:
Element |
Attribute |
Beskrivelse |
---|---|---|
a (anchor) |
href |
anchor element; Indicates that this text will open the link in the |
b (bold) |
Bolds the text. |
|
c (color) |
n |
Applies a color indicated by the |
i (italics) |
Italicizes the text. |
|
o (obfuscated) |
Obfuscates the text (replaces the characters with random characters that change continuously). |
|
s (strikethrough) |
Strikes through the text. |
|
span |
onClick, onHover |
Generic holder element that can have click and/or hover actions indicated by the
|
tr (translation) |
key |
Indicates a text translation |
u (underline) |
Underlines the text. |
For example, the text »Hello World!«, formatted with the color red and an underline would have the following representation in the TextXML format:
<c n="red">
<u>Hello World!</u>
</c>
This output can be produced using the following code:
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.format.TextStyles;
import org.spongepowered.api.text.serializer.TextSerializers;
Text text = Text.of(TextColors.RED, TextStyles.UNDERLINE, "Hello World!");
String xmlText = TextSerializers.TEXT_XML.serialize(text);