DeviceStatusNotification.fromXML constructor

DeviceStatusNotification.fromXML(
  1. String xmlSTR
)

Implementation

factory DeviceStatusNotification.fromXML(String xmlSTR) {
  final document = XmlDocument.parse(xmlSTR);

  String messageName = document.rootElement.attributes
      .firstWhere((p0) => p0.name.toString() == "messageName")
      .value;
  // String xmlns = document.rootElement.attributes.firstWhere((p0) => p0.name.toString() == "xmlns").value;
  String messageID = document.rootElement.attributes
      .firstWhere((p0) => p0.name.toString() == "messageID")
      .value;
  // String xsi = document.rootElement.attributes.firstWhere((p0) => p0.name.toString() == "xmlns:xsi").value;
  // String result = document.rootElement.childElements.first.attributes.firstWhere((p0) => p0.name.toString() == "result",orElse: orElseEmpty).value;

  XmlElement resElement =
      document.rootElement.findAllElements("deviceStatusNotification").first;
  XmlElement statusElement = resElement.childElements
      .where((element) => element.name.toString().endsWith("Status"))
      .first;

  Status status = Status.fromXML(statusElement.toXmlString());
  return DeviceStatusNotification(
      messageName: messageName,
      messageID: int.parse(messageID),
      status: status);
}