rootElement property

  1. @override
XmlElement get rootElement
inherited

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

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