|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsugar4xml.Sugar4Xml<T>
public abstract class Sugar4Xml<T extends Sugar4Xml<?>>
Writes arbitrary xml to a Writer destination using only the two methods
element() and end().
element(String, Object...) starts an element, end() ends the last written
element.
element() expects its parameters as follows:
For nested elements, it is suggested to nest the element() and end()
calls as well.
Example:
element("html");
{
element("body");
{
element("h1", "hello world").end();
}
end();
}
end();
-->
<page><body><h1>hello world</h1></body></page>
| Nested Class Summary | |
|---|---|
static class |
Sugar4Xml.Default
Default, type-argument less implementation. |
| Field Summary | |
|---|---|
static String |
xmlns
The xmlns attribute used for namespace declaration with an empty prefix. |
| Constructor Summary | |
|---|---|
Sugar4Xml()
Constructs with a null writer. |
|
Sugar4Xml(Writer writer)
Constructs with the given writer |
|
| Method Summary | |
|---|---|
T |
characters(char[] ch,
int start,
int length)
Outputs the given characters. |
T |
create()
Creates this xml. |
T |
element(String name,
Object... attributesAndOptionalValue)
Starts an element (namespace element with an empty prefix), its attributes and an optional value. |
T |
embedd(Sugar4Xml<?> xml)
|
T |
end()
Ends the last written element. |
String |
getDefaultElementNsPrefix()
Returns the default prefix for all elements written if no prefix is given in nselement(). |
Writer |
getWriter()
Returns the output destination for this xml. |
static String |
nsattr(String prefix,
String name)
Returns the attribute name for the given namespace prefix. |
T |
nselement(String nsPrefix,
String name,
Object... attributesAndOptionalValue)
Starts a namespace prefixed element, its attributes and an optional value. |
T |
nsembedd(String nsPrefix,
Sugar4Xml<?> xml)
|
void |
setDefaultElementNsPrefix(String defaultElementNsPrefix)
Sets the default prefix for all elements written if no prefix is given in nselement(). |
void |
setWriter(Writer writer)
Sets the writer to which to output the xml. |
T |
text(String text)
Outputs the given text using a character() call. |
static String |
xmlns(Object prefix)
Returns an xmlns attribute for the given prefix used for a namespace
declaration. |
| Field Detail |
|---|
public static final String xmlns
xmlns attribute used for namespace declaration with an empty prefix.
Example:
element("schema", xmlns, "http://www.w3.org/2001/XMLSchema").end();
-->
<schema xmlns='http://www.w3.org/2001/XMLSchema'/>
xmlns(Object),
Constant Field Values| Constructor Detail |
|---|
public Sugar4Xml()
null writer.
Note that setWriter(Writer) must be called before the xml is created or else a
Sugar4XmlException will occur.
public Sugar4Xml(Writer writer)
writer - Where to write this xml to| Method Detail |
|---|
public static String xmlns(Object prefix)
xmlns attribute for the given prefix used for a namespace
declaration.
Example:
nselement("xs", "schema", xmlns("xs"), "http://www.w3.org/2001/XMLSchema").end();
-->
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'/>
prefix -
public static String nsattr(String prefix,
String name)
Example:
element("content", xmlns("a"), "com.acme", nsattr("a", "id"), "zx500").end();
-->
<content xmlns:a='com.acme' a:id='zx500'/>
prefix - name -
public T create()
this
Sugar4XmlException - if element() and end() calls do not
match (mal-formed xml output).public T text(String text)
character() call.
text -
this
public T characters(char[] ch,
int start,
int length)
ch - start - length -
thisContentHandler.characters(char[], int, int)
public T element(String name,
Object... attributesAndOptionalValue)
name - The name of the elementattributesAndOptionalValue - attribute [name, value] pairs, optionally followed by a
single value. If the length of the array is odd, the last element designates the
value for the element. May be empty. An attribute name may be namespace-prefixed.
thisnselement(String, String, Object...)
public T nselement(String nsPrefix,
String name,
Object... attributesAndOptionalValue)
nsPrefix - Namespace prefixname - The name of the elementattributesAndOptionalValue - attribute [name, value] pairs, optionally followed by a
single value. If the length of the array is odd, the last element designates the
value for the element. May be empty. An attribute name may be namespace-prefixed.
thispublic T end()
thispublic T embedd(Sugar4Xml<?> xml)
public T nsembedd(String nsPrefix,
Sugar4Xml<?> xml)
public Writer getWriter()
public void setWriter(Writer writer)
This method should not be called within the creation of the xml.
writer - public String getDefaultElementNsPrefix()
nselement().
public void setDefaultElementNsPrefix(String defaultElementNsPrefix)
nselement().
defaultElementNsPrefix -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||