XML
- class compas.files.XML(filepath=None)[source]
Bases:
object
Class for working with XML files.
This class simplifies reading XML files and strings across different Python implementations.
- Attributes
reader (
XMLReader
, read-only) – Reader used to process the XML file or string.writer (
XMLWriter
, read-only) – Writer used to process the XML object to a file or string.filepath (str) – The path to the XML file.
root (
xml.etree.ElementTree.Element
) – Root element of the XML tree.
Examples
>>> from compas.files import XML >>> xml = XML.from_string("<Main><Title>Test</Title></Main>") >>> xml.root.tag 'Main'
Methods
Read XML from a file path or file-like object.
Read XML from a string.
Read XML from a file path or file-like object, stored in the attribute
filepath
.Writes the string representation of this XML instance, including all sub-elements, to the file path in the associated XML object.
Generate a string representation of this XML instance, including all sub-elements.
Writes the string representation of this XML instance, including all sub-elements, to the file path in the associated XML object.