XML

class compas.files.XML[source]

Bases: object

Class for working with XML files.

This class simplifies reading XML files and strings across different Python implementations.

Examples

>>> from compas.files import XML
>>> xml = XML.from_string("<Main><Title>Test</Title></Main>")
>>> xml.root.tag
'Main'
Attributes:
readercompas.files.XMLReader, read-only

Reader used to process the XML file or string.

writerXMLWriter, read-only

Writer used to process the XML object to a file or string.

filepathstr

The path to the XML file.

rootxml.etree.ElementTree.Element

Root element of the XML tree.

Methods

from_file

Read XML from a file path or file-like object.

from_string

Read XML from a string.

read

Read XML from a file path or file-like object, stored in the attribute filepath.

to_file

Writes the string representation of this XML instance, including all sub-elements, to the file path in the associated XML object.

to_string

Generate a string representation of this XML instance, including all sub-elements.

write

Writes the string representation of this XML instance, including all sub-elements, to the file path in the associated XML object.