SupportedStock.fromXML constructor

SupportedStock.fromXML(
  1. String xmlSTR
)

Implementation

factory SupportedStock.fromXML(String xmlSTR) {
  final document = XmlDocument.parse(xmlSTR);
  String stockName = document.firstChild!.attributes
      .firstWhere((element) => element.name.toString() == "stockName", orElse: orElseEmpty)
      .value;
  String supportsColor = document.firstChild!.attributes
      .firstWhere((element) => element.name.toString() == "supportsColor", orElse: orElseEmpty)
      .value;
  String stockWidth = document.firstChild!.attributes.firstWhere((element) => element.name.toString() == "stockWidth").value;
  String stockHeight = document.firstChild!.attributes.firstWhere((element) => element.name.toString() == "stockHeight").value;
  String leftMargin = document.firstChild!.attributes.firstWhere((element) => element.name.toString() == "leftMargin").value;
  String rightMargin = document.firstChild!.attributes.firstWhere((element) => element.name.toString() == "rightMargin").value;
  String topMargin = document.firstChild!.attributes.firstWhere((element) => element.name.toString() == "topMargin").value;
  String bottomMargin =
      document.firstChild!.attributes.firstWhere((element) => element.name.toString() == "bottomMargin").value;
  String perforationLeft =
      document.firstChild!.attributes.firstWhere((element) => element.name.toString() == "perforationLeft").value;
  return SupportedStock(
    stockName: stockName,
    supportsColor: supportsColor,
    stockWidth: stockWidth,
    stockHeight: stockHeight,
    leftMargin: leftMargin,
    rightMargin: rightMargin,
    topMargin: topMargin,
    bottomMargin: bottomMargin,
    perforationLeft: perforationLeft,
  );
}