rootElement property

XmlElement rootElement

Return the root XmlElement of the document, or throw a StateError if the document has no such element.

For example, the following code prints <books />:

var xml = '<?xml version="1.0"?>'
          '<books />';
print(XmlDocument.parse(xml).rootElement);

Implementation

XmlElement get rootElement {
  for (final node in children) {
    if (node is XmlElement) {
      return node;
    }
  }
  throw StateError('Empty XML document');
}