当前位置: 首页>>代码示例>>C++>>正文


C++ DeviceInfo::ParseXml方法代码示例

本文整理汇总了C++中DeviceInfo::ParseXml方法的典型用法代码示例。如果您正苦于以下问题:C++ DeviceInfo::ParseXml方法的具体用法?C++ DeviceInfo::ParseXml怎么用?C++ DeviceInfo::ParseXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DeviceInfo的用法示例。


在下文中一共展示了DeviceInfo::ParseXml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ParseXml

bool FirmwareInfo::ParseXml(QXmlStreamReader& xml)
{
	Clear();

	bool foundName = false;
	bool foundVersion = false;
	bool foundPlatform = false;
	bool foundDevelopers = false;
	bool foundUrl = false;
	bool foundDonateUrl = false;
	bool foundDevices = false;
	bool foundPit = false;
	bool foundRepartition = false;
	bool foundNoReboot = false;
	bool foundFiles = false;

	if (!xml.readNextStartElement())
	{
		Alerts::DisplayError("Failed to find <firmware> element.");
		return (false);
	}

	if (xml.name() != "firmware")
	{
		Alerts::DisplayError(QString("Expected <firmware> element but found <%1>.").arg(xml.name().toString()));
		return (false);
	}

	QString formatVersionString;
	formatVersionString += xml.attributes().value("version");

	if (formatVersionString.isEmpty())
	{
		Alerts::DisplayError("<firmware> is missing the version attribute.");
		return (false);
	}

	bool parsedVersion = false;
	int formatVersion = formatVersionString.toInt(&parsedVersion);

	if (!parsedVersion)
	{
		Alerts::DisplayError("<firmware> contains a malformed version.");
		return (false);
	}

	if (formatVersion > kVersion)
	{
		Alerts::DisplayError("Package is for a newer version of Heimdall Frontend.\nPlease download the latest version of Heimdall Frontend.");
		return (false);
	}

	while (!xml.atEnd())
	{
		QXmlStreamReader::TokenType nextToken = xml.readNext();

		if (nextToken == QXmlStreamReader::StartElement)
		{
			if (xml.name() == "name")
			{
				if (foundName)
				{
					Alerts::DisplayError("Found multiple <name> elements in <firmware>.");
					return (false);
				}

				foundName = true;
				name = xml.readElementText();
			}
			else if (xml.name() == "version")
			{
				if (foundVersion)
				{
					Alerts::DisplayError("Found multiple <version> elements in <firmware>.");
					return (false);
				}

				foundVersion = true;
				version = xml.readElementText();
			}
			else if (xml.name() == "platform")
			{
				if (foundPlatform)
				{
					Alerts::DisplayError("Found multiple <platform> elements in <firmware>.");
					return (false);
				}

				foundPlatform = true;

				if (!platformInfo.ParseXml(xml))
					return (false);
			}
			else if (xml.name() == "developers")
			{
				if (foundDevelopers)
				{
					Alerts::DisplayError("Found multiple <developers> elements in <firmware>.");
					return (false);
				}
//.........这里部分代码省略.........
开发者ID:0x2b,项目名称:Heimdall,代码行数:101,代码来源:FirmwareInfo.cpp


注:本文中的DeviceInfo::ParseXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。