Read method

Future<void> Read({
  1. XmlNodeType? nodeType,
})
Reads the next node.

Implementation

Future<void> Read({XmlNodeType? nodeType}) async {
  if (nodeType != XmlNodeType.XmlDeclaration) {
    _prevNodeType = _xmlReader.NodeType;
  }

  // XmlReader.Read returns true if the next node was read successfully; false if there
  // are no more nodes to read. The caller to EwsXmlReader.Read expects that there's another node to
  // read. Throw an exception if not true.
  bool nodeRead = await _xmlReader.Read();
  // A hanging (streaming notifications) response is a sequence of SOAP
  // documents read without a preamble. Exchange sends no XML declarations
  // there, but other servers such as grommunio start every document with
  // one, so skip a declaration unless the caller asked for it.
  while (nodeRead &&
      nodeType != XmlNodeType.XmlDeclaration &&
      NodeType == XmlNodeType.XmlDeclaration) {
    nodeRead = await _xmlReader.Read();
  }
  if (!nodeRead) {
    throw ServiceXmlDeserializationException(
      "Strings.UnexpectedEndOfXmlDocument",
    );
  }
  if (nodeType != null && NodeType != nodeType) {
    throw ServiceXmlDeserializationException("""string.Format(
                      Strings.UnexpectedElementType,
                      $nodeType,
                      $NodeType)""");
  }
}