Skip to content
mtopolnik edited this page Nov 5, 2015 · 3 revisions

A JdomBuilder instance is obtained from the global function xml().

###el(name, & ns) Adds an element below the current element and the new element becomes the current element. The ns parameter is of type Namespace, usually obtained from the ns global function. Example:

xml('root').el('xorg',ns('xa','http://example.org'));

Resulting XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <xa:xorg xmlns:xa="http://example.org" />
</root>

###end(& name) Ends (closes) the current element. Its parent becomes the new current element. If name is given, it must match the simple name (ignoring namespace) of the element being closed. Example:

xml('root').el('x').el('y').text('aoeu').end('y').el('z').text('snth');

Resulting XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <x>
    <y>aoeu</y>
    <z>snth</z>
  </x>
</root>

###att(nameValuePairs...) Adds attributes to the current element. attValuePairs is a list of attribute-value pairs. Example:

xml('root').att('a','1', 'b','2');

Resulting XML:

<?xml version="1.0" encoding="UTF-8"?>
<root a="1" b="2" />

###text(strs...) Adds text below the current element. strs are any objects whose toString values are concatenated and added as element text. Example:

xml('root').text('a','1','b','2');

Resulting XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>a1b2</root>

###emptyel(name, attrValuePairs...) Adds an empty element below the current element. The current element remains the same. attValuePairs is a list of attribute-value pairs, as accepted by the att method. Example:

xml('root').emptyel('empty', 'a','1', 'b','2');

Resulting XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <empty a="1" b="2" />
</root>

###textel(nameValuePairs...) Adds simple elements below the current element. The current element remains the same. A simple element is one which only contains text (no attributes, no subelements). Example:

xml('root').textel('a','1', 'b','2');

Resulting XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <a>1</a>
  <b>2</b>
</root>
Clone this wiki locally