BpDeviceParameter.fromXML constructor

BpDeviceParameter.fromXML(
  1. String xmlSTR
)

Implementation

factory BpDeviceParameter.fromXML(String xmlSTR) {
  final document = XmlDocument.parse(xmlSTR);
  XmlElement? vendorModelInfoElement =
      document.firstChild!.getElement("vendorModelInfo");
  XmlElement? ipAndPortElement = document.firstChild!.getElement("ipAndPort");
  XmlElement? statusElement = document.firstChild!.getElement("bpStatus");
  VendorModelInfo vendorModelInfo =
      VendorModelInfo.fromXML(vendorModelInfoElement!.toXmlString());
  IpAndPort ipAndPort = IpAndPort.fromXML(ipAndPortElement!.toXmlString());
  BpStatus status = BpStatus.fromXML(statusElement!.toXmlString());
  String supportsColor = document.firstChild!.attributes
      .firstWhere((element) => element.name.toString() == "supportsColor")
      .value;
  XmlElement? supportedStocksElement =
      document.firstChild!.getElement("supportedStocks");
  List<XmlElement> supporters = supportedStocksElement == null
      ? []
      : supportedStocksElement.findElements("supportedStock").toList();
  List<SupportedStock> supportedStocks =
      supporters.map((e) => SupportedStock.fromXML(e.toXmlString())).toList();

  return BpDeviceParameter(
    vendorModelInfo: vendorModelInfo,
    ipAndPort: ipAndPort,
    status: status,
    supportsColor: supportsColor,
    supportedStocks: supportedStocks,
  );
}