Note that there are some explanatory texts on larger screens.

plurals
  1. POSort Nodes in XmlDocument by Attribute in C++, XPath, Windows Forms
    primarykey
    data
    text
    <p>I want to sort a XML-Document by attributes of an Child-Node. I am working with Windows Forms in Visual C++. I tried to use the solution proposed <a href="https://stackoverflow.com/questions/344737/sorting-xml-nodes-based-on-datetime-attribute-c-xpath">here on Stackoverflow</a>. But somehow it won't work.</p> <p>My <strong>unsorted</strong> XML-Doc looks like the following:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Message-List&gt; &lt;Message sendTime="0"&gt;&lt;/Message&gt; &lt;Message sendTime="20"&gt;&lt;/Message&gt; &lt;Message sendTime="5"&gt;&lt;/Message&gt; &lt;/Message-List&gt; </code></pre> <p>My <strong>sorted</strong> XML-Doc should look like this:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Message-List&gt; &lt;Message sendTime="0"&gt;&lt;/Message&gt; &lt;Message sendTime="5"&gt;&lt;/Message&gt; &lt;Message sendTime="20"&gt;&lt;/Message&gt; &lt;/Message-List&gt; </code></pre> <p>I tried following Code, but the <strong>checkme</strong>-String returned is <strong>0205</strong>. So the sorting doesn't even work.</p> <pre class="lang-cpp prettyprint-override"><code>System::Xml::XmlDocument^ sourceXmlDoc = gcnew XmlDocument; sourceXmlDoc-&gt;LoadXml("&lt;Message-List&gt;&lt;Message sendTime=\"0\"&gt;&lt;/Message&gt;&lt;Message sendTime=\"20\"&gt;&lt;/Message&gt;&lt;Message sendTime=\"5\"&gt;&lt;/Message&gt;&lt;/Message-List&gt;"); System::Xml::XPath::XPathNavigator^ navigator = sourceXmlDoc-&gt;CreateNavigator(); System::Xml::XPath::XPathExpression^ selectExpression = navigator-&gt;Compile("Message-List/Message"); System::Xml::XPath::XPathExpression^ sortExpr = navigator-&gt;Compile("@sendTime"); selectExpression-&gt;AddSort(sortExpr, XmlSortOrder::Ascending, XmlCaseOrder::None, "", XmlDataType::Text); System::Xml::XPath::XPathNodeIterator^ nodeIterator = navigator-&gt;Select(selectExpression); String^ checkMe; while (nodeIterator-&gt;MoveNext()) { if (nodeIterator-&gt;Current-&gt;MoveToFirstAttribute()) { checkMe = checkMe + nodeIterator-&gt;Current-&gt;Value; } } </code></pre> <p>Furthermore, I am stuck on how to proceed in the while-loop. How can I save the resorted xmlDoc as XmlDocument?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload