DeviceParameterResponse.fromXML constructor

DeviceParameterResponse.fromXML(
  1. String xmlSTR
)

Implementation

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

  String messageName = document.rootElement.attributes
      .firstWhere((p0) => p0.name.toString() == "messageName")
      .value;
  String messageID = document.rootElement.attributes
      .firstWhere((p0) => p0.name.toString() == "messageID")
      .value;
  String result = document.rootElement.childElements.first.attributes
      .firstWhere((p0) => p0.name.toString() == "result")
      .value;
  XmlElement? deviceElement =
      document.rootElement.findAllElements("device").isEmpty
          ? null
          : document.rootElement.findAllElements("device").first;
  Device? device = deviceElement == null
      ? null
      : Device.fromXML(deviceElement.toXmlString());

  return DeviceParameterResponse(
      messageName: messageName,
      messageID: int.parse(messageID),
      result: result,
      device: device);
}