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 FormModifier and Type | Class and Description |
---|---|
protected static class |
XmlModel.RawEnvelope
Raw XML code envelope
|
Modifier and Type | Field and Description |
---|---|
protected Map<String,Object> |
attributes
Attributes
|
protected List<Object> |
children
Child elements with a
null items |
protected String |
name
Element name
|
HIDDEN_NAME
Constructor and Description |
---|
XmlModel(String name) |
XmlModel(String name,
XmlModel parent)
New element with a parent
|
Modifier and Type | Method and Description |
---|---|
XmlModel |
addCDATA(CharSequence charData)
Add a character data in
CDATA format to XML only. |
XmlModel |
addComment(CharSequence comment)
Add a comment text.
|
XmlModel |
addElement(String name)
Create a new
XmlModel for a required name and add it to children. |
XmlModel |
addElement(XmlModel element)
Add a child element
|
protected void |
addChild(Object child)
Add a child entity
|
XmlModel |
addRawText(Object value)
Add an native text with no escaped characters, for example: XML code, JavaScript, CSS styles
|
XmlModel |
addText(Object value)
Add a text and escape special character
|
XmlModel |
addTextTemplated(CharSequence template,
Object... values)
Message template with hight performance.
|
void |
close()
An empty method
|
protected Map<String,Object> |
getAttribs()
Return attributes
|
Map<String,Object> |
getAttributes()
Get an unmodifiable map of attributes
|
List<Object> |
getChildren()
Get an unmodifiable list of children
|
String |
getName()
Get an element name
|
XmlModel |
setAttribute(String name,
Object value)
Set one attribute
|
String |
toString()
Render the XML code including header
|
XmlWriter |
toWriter(int level,
XmlWriter out)
Render the XML code without header
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
setAttrib
public XmlModel(@Nonnull 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 String getName()
ApiElement
getName
in interface ApiElement<XmlModel>
@Nonnull public final XmlModel addElement(@Nonnull XmlModel element)
element
- Add a child element is required. An undefined argument is ignored.@Nonnull public XmlModel addElement(@Nonnull 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.@Nonnull public final XmlModel setAttribute(@Nonnull String name, @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.@Nonnull public final XmlModel addText(@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.@Nonnull public final XmlModel addTextTemplated(@Nullable CharSequence template, @Nonnull Object... values)
addTextTemplated
in interface ApiElement<XmlModel>
template
- Message template where parameters are marked by the {}
symbolvalues
- argument values@Nonnull public final XmlModel addRawText(@Nullable Object value)
addRawText
in interface ApiElement<XmlModel>
value
- The null
value is ignored.@Nonnull public final XmlModel addComment(@Nullable CharSequence comment)
addComment
in interface ApiElement<XmlModel>
comment
- A comment text must not contain a string -->
.@Nonnull public final XmlModel addCDATA(@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.@Nonnull public Map<String,Object> getAttributes()
public final void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in interface ApiElement<XmlModel>
@Nonnull public XmlWriter toWriter(int level, @Nonnull XmlWriter out) throws IOException
IOException
Copyright 2019-2022, Pavel Ponec