* @brief Parses an XML register map (flat or nested by register type). */
| 548 | * @brief Parses an XML register map (flat or nested by register type). |
| 549 | */ |
| 550 | bool DataModel::ModbusMapImporter::parseXML(const QString& path) |
| 551 | { |
| 552 | QFile file(path); |
| 553 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) |
| 554 | return false; |
| 555 | |
| 556 | if (file.size() > kMaxImportFileBytes) |
| 557 | return false; |
| 558 | |
| 559 | QXmlStreamReader xml(&file); |
| 560 | int current_type = -1; |
| 561 | |
| 562 | while (!xml.atEnd() && !xml.hasError()) { |
| 563 | const auto token = xml.readNext(); |
| 564 | if (token != QXmlStreamReader::StartElement) |
| 565 | continue; |
| 566 | |
| 567 | const auto tag_name = xml.name().toString().toLower(); |
| 568 | |
| 569 | const int container_type = xmlTagToType(tag_name); |
| 570 | if (container_type >= 0) { |
| 571 | current_type = container_type; |
| 572 | continue; |
| 573 | } |
| 574 | |
| 575 | if (tag_name != QLatin1String("register")) |
| 576 | continue; |
| 577 | |
| 578 | RegisterEntry entry; |
| 579 | if (parseXmlRegisterElement(xml, current_type, entry)) |
| 580 | m_registers.append(entry); |
| 581 | } |
| 582 | |
| 583 | file.close(); |
| 584 | return !m_registers.isEmpty(); |
| 585 | } |
| 586 | |
| 587 | //-------------------------------------------------------------------------------------------------- |
| 588 | // JSON parser |
nothing calls this directly
no test coverage detected