public class XmlModel extends Object implements ApiElement<XmlModel>, Serializable
XmlElement root = new XmlElement("root");
root.addElement("childA")
.setAttrib("x", 1)
.setAttrib("y", 2);
root.addElement("childB")
.setAttrib("x", 3)
.setAttrib("y", 4)
.addText("A text message <&\">");
root.addRawText("\n<rawXml/>\n");
root.addCDATA("A character data <&\">");
String result = root.toString();
HtmlElement,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
protected static class |
XmlModel.RawEnvelope
Raw XML code envelope
|
| Modifier and Type | Field and Description |
|---|---|
protected @Nullable Map<String,Object> |
attributes
Attributes
|
protected @Nullable List<Object> |
children
Child elements with a
null items |
protected @Nullable String |
name
Element name
|
HIDDEN_NAME| Constructor and Description |
|---|
XmlModel(@NotNull String name) |
XmlModel(@NotNull String name,
@NotNull XmlModel parent)
New element with a parent
|
| Modifier and Type | Method and Description |
|---|---|
@NotNull XmlModel |
addCDATA(@Nullable CharSequence charData)
Add a character data in
CDATA format to XML only. |
@NotNull XmlModel |
addComment(@Nullable CharSequence comment)
Add a comment text.
|
@NotNull XmlModel |
addElement(@NotNull String name)
Create a new
XmlModel for a required name and add it to children. |
@NotNull XmlModel |
addElement(@NotNull XmlModel element)
Add a child element
|
protected void |
addChild(@Nullable Object child)
Add a child entity
|
@NotNull XmlModel |
addRawText(@Nullable Object value)
Add an native text with no escaped characters, for example: XML code, JavaScript, CSS styles
|
@NotNull XmlModel |
addText(@Nullable Object value)
Add a text and escape special character
|
@NotNull XmlModel |
addTextTemplated(@Nullable CharSequence template,
Object... values)
Message template with hight performance.
|
void |
close()
An empty method
|
protected @NotNull Map<String,Object> |
getAttribs()
Return attributes
|
@NotNull Map<String,Object> |
getAttributes()
Get an unmodifiable map of attributes
|
@NotNull List<Object> |
getChildren()
Get an unmodifiable list of children
|
@Nullable String |
getName()
Get an element name
|
@NotNull XmlModel |
setAttribute(@NotNull String name,
@Nullable Object value)
Set one attribute
|
@NotNull String |
toString()
Render the XML code including header
|
@NotNull XmlWriter |
toWriter(int level,
@NotNull XmlWriter out)
Render the XML code without header
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitsetAttrib@Nullable protected final @Nullable String name
public XmlModel(@NotNull
@NotNull String name)
name - The element name must not be special HTML characters.
The null value is intended to build a root of AJAX queries.@Nullable public @Nullable String getName()
ApiElementgetName in interface ApiElement<XmlModel>@NotNull
protected void addChild(@Nullable
@Nullable Object child)
@NotNull public final @NotNull XmlModel addElement(@NotNull @NotNull XmlModel element)
element - Add a child element is required. An undefined argument is ignored.@NotNull public @NotNull XmlModel addElement(@NotNull @NotNull String name)
XmlModel for a required name and add it to children.addElement in interface ApiElement<XmlModel>name - A name of the new XmlElement is required.@NotNull public final @NotNull XmlModel setAttribute(@NotNull @NotNull String name, @Nullable @Nullable Object value)
setAttribute in interface ApiElement<XmlModel>name - Required element namevalue - The null value is ignored. Formatting is performed by the
XmlWriter#writeValue(java.lang.Object, org.ujorm.tools.dom.XmlElement, java.lang.String, java.io.Writer)
method, where the default implementation calls a toString() only.@NotNull public final @NotNull XmlModel addText(@Nullable @Nullable Object value)
addText in interface ApiElement<XmlModel>value - The null value is allowed. Formatting is performed by the
XmlWriter#writeValue(java.lang.Object, org.ujorm.tools.dom.XmlElement, java.lang.String, java.io.Writer)
method, where the default implementation calls a toString() only.@NotNull public final @NotNull XmlModel addTextTemplated(@Nullable @Nullable CharSequence template, @NotNull Object... values)
addTextTemplated in interface ApiElement<XmlModel>template - Message template where parameters are marked by the {} symbolvalues - argument values@NotNull public final @NotNull XmlModel addRawText(@Nullable @Nullable Object value)
addRawText in interface ApiElement<XmlModel>value - The null value is ignored.@NotNull public final @NotNull XmlModel addComment(@Nullable @Nullable CharSequence comment)
addComment in interface ApiElement<XmlModel>comment - A comment text must not contain a string --> .@NotNull public final @NotNull XmlModel addCDATA(@Nullable @Nullable CharSequence charData)
CDATA format to XML only.
The CDATA structure isn't really for HTML at all.addCDATA in interface ApiElement<XmlModel>charData - A text including the final DATA sequence. An empty argument is ignored.@NotNull public @NotNull Map<String,Object> getAttributes()
@NotNull public @NotNull List<Object> getChildren()
public final void close()
close in interface Closeableclose in interface AutoCloseableclose in interface ApiElement<XmlModel>@NotNull public @NotNull String toString()
@NotNull public @NotNull XmlWriter toWriter(int level, @NotNull @NotNull XmlWriter out) throws IOException
IOExceptionCopyright 2015, Pavel Ponec