Skip to main content
The XML data type supports manipulation of XML attributes and child elements.

Attributes

Checking for Attributes in XML

Reading Attributes from XML

The attr method returns a wrapper of the XML attribute and with value the value of the attribute can be accessed. If you want to access an attribute in another namespace, you have to use the attrNs method.
You can also get a collection of all attributes or only of a specific namespace.
Or you can directly get all attribute names instead.

Writing Attributes to XML

It is possible to set a new attribute value directly from the element wrapper or on the attribute wrapper.
You can also specify the namespace of the attribute to set.

Removing Attributes from XML

It is possible to remove an attribute from the element directly or to remove the attribute itself.
You can also specify the namespace of the attribute to remove.

Text Content

It is possible to read and write the text content of an XML element with the textContent method.

Child Elements

Reading Child Elements from XML

Besides attributes, you can also get a unique or all child elements of a specific type. Optionally, a namespace can be passed to the methods as first parameter.

Append Child Elements

The method append is used to append a single or multiple child elements to an XML element.

Remove Child Elements

To remove child elements from an XML element, the method remove is used. It accepts single or multiple child elements and removes them from the parent element.

Replace Elements

To replace an element or a child element, the methods replace and replaceChild are used.

Manipulating XML using a Script Language

XML can be manipulated from script languages in the same was as from Java. Since script languages use dynamic typing, you do not need to hint the data format but you can use autodetection. The following example demonstrates how to access an attribute and a child element from XML in Python: