{"id":314673,"date":"2020-12-11T03:00:20","date_gmt":"2020-12-11T03:00:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=314673"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=314673","title":{"rendered":"\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 XML \u0432 Qt"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u044d\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u043a\u0438\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c, \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043b\u0438 \u0436\u0435 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u043e\u0435 \u0442\u043e \u0432\u0440\u0435\u043c\u044f. \u0422\u0443\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 XML.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0415\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 xml-\u043a\u043e\u043d\u0444\u0438\u0433:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt; &lt;etaps&gt; \t&lt;etap id=&quot;1&quot;&gt; \t\t&lt;name&gt;\u041f\u0435\u0440\u0432\u044b\u0439&lt;\/name&gt; \t\t&lt;firststage&gt;1&lt;\/firststage&gt; \t\t&lt;laststage&gt;9&lt;\/laststage&gt; \t\t&lt;pausestage&gt;10&lt;\/pausestage&gt;         &lt;etappause&gt;5&lt;\/etappause&gt; \t&lt;\/etap&gt; \t&lt;etap id=&quot;2&quot;&gt; \t\t&lt;name&gt;\u0412\u0442\u043e\u0440\u043e\u0439&lt;\/name&gt; \t\t&lt;firststage&gt;10&lt;\/firststage&gt; \t\t&lt;laststage&gt;20&lt;\/laststage&gt; \t\t&lt;pausestage&gt;15&lt;\/pausestage&gt;         &lt;etappause&gt;2&lt;\/etappause&gt; \t&lt;\/etap&gt; \t&lt;etap id=&quot;3&quot;&gt; \t\t&lt;name&gt;\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439&lt;\/name&gt; \t\t&lt;firststage&gt;21&lt;\/firststage&gt; \t\t&lt;laststage&gt;50&lt;\/laststage&gt; \t\t&lt;pausestage&gt;15&lt;\/pausestage&gt;         &lt;etappause&gt;3&lt;\/etappause&gt; \t&lt;\/etap&gt; &lt;\/etaps&gt; <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0417\u0430\u0434\u0430\u0447\u0430: \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0444\u0430\u0439\u043b \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 Qt, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e QXmlStreamReader.<\/p>\n<p>  \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433:<\/p>\n<pre><code class=\"cpp\">    QFile* file = new QFile(&quot;config.xml&quot;);      if (!file-&gt;open(QIODevice::ReadOnly | QIODevice::Text))     {         emit Log(tr(&quot;\u041d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c XML-\u043a\u043e\u043d\u0444\u0438\u0433&quot;), LOG_LEVEL_ERROR);         return false;     }     QXmlStreamReader xml(file); <\/code><\/pre>\n<p>  \u0418\u0449\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0442\u0435\u0433 (etaps) \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0442\u0435\u0433 etap:<\/p>\n<pre><code class=\"cpp\">    while (!xml.atEnd() &amp;&amp; !xml.hasError())     {         QXmlStreamReader::TokenType token = xml.readNext();         if (token == QXmlStreamReader::StartDocument)             continue;         if (token == QXmlStreamReader::StartElement)         {             if (xml.name() == &quot;etaps&quot;)                 continue;             if (xml.name() == &quot;etap&quot;)                 XMLConf.append(parseEtap(xml));         }     } <\/code><\/pre>\n<p>  \u043f\u0430\u0440\u0441\u0438\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0433\u0430 etap \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0432 QMap&lt;QString, QString&gt;:<\/p>\n<p>  \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0442\u0430\u043c \u043b\u0438 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f:<\/p>\n<pre><code class=\"cpp\">    QMap&lt;QString, QString&gt; etap;     if (xml.tokenType() != QXmlStreamReader::StartElement &amp;&amp; xml.name() == &quot;etap&quot;)         return etap; <\/code><\/pre>\n<p>  \u043f\u0430\u0440\u0441\u0438\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0432 etap \u0442\u0435\u0433 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 QMap:<\/p>\n<pre><code class=\"cpp\">    QXmlStreamAttributes attributes = xml.attributes();     if (attributes.hasAttribute(&quot;id&quot;))         etap[&quot;id&quot;] = attributes.value(&quot;id&quot;).toString();     xml.readNext();     while (!(xml.tokenType() == QXmlStreamReader::EndElement &amp;&amp; xml.name() == &quot;etap&quot;))     {         if (xml.tokenType() == QXmlStreamReader::StartElement)         {             if (xml.name() == &quot;name&quot;)                 addElementDataToMap(xml, etap);             if (xml.name() == &quot;firststage&quot;)                 addElementDataToMap(xml, etap);             if (xml.name() == &quot;laststage&quot;)                 addElementDataToMap(xml, etap);             if (xml.name() == &quot;pausestage&quot;)                 addElementDataToMap(xml, etap);             if (xml.name() == &quot;etappause&quot;)                 addElementDataToMap(xml, etap);         }         xml.readNext();     } <\/code><\/pre>\n<p>  \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 QMap<\/p>\n<pre><code class=\"cpp\">void addElementDataToMap(QXmlStreamReader&amp; xml, QMap&lt;QString, QString&gt;&amp; map) const {     if (xml.tokenType() != QXmlStreamReader::StartElement)         return;     QString elementName = xml.name().toString();     xml.readNext();     map.insert(elementName, xml.text().toString()); }  <\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c QMap&lt;QString, QString&gt; \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438: \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u0433\u0430 \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/532436\/\"> https:\/\/habr.com\/ru\/post\/532436\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u044d\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u043a\u0438\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c, \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043b\u0438 \u0436\u0435 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u043e\u0435 \u0442\u043e \u0432\u0440\u0435\u043c\u044f. \u0422\u0443\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 XML.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-314673","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/314673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=314673"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/314673\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=314673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=314673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=314673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}