MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / parseXML

Method parseXML

app/src/DataModel/Importers/ModbusMapImporter.cpp:550–585  ·  view source on GitHub ↗

* @brief Parses an XML register map (flat or nested by register type). */

Source from the content-addressed store, hash-verified

548 * @brief Parses an XML register map (flat or nested by register type).
549 */
550bool 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

Callers

nothing calls this directly

Calls 9

xmlTagToTypeFunction · 0.85
parseXmlRegisterElementFunction · 0.85
isEmptyMethod · 0.80
openMethod · 0.45
sizeMethod · 0.45
atEndMethod · 0.45
nameMethod · 0.45
appendMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected