I have an XML and I want to group multiple elements that have the same value.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE repub SYSTEM "C:\repub\Repub_V1.dtd">
<?xml-stylesheet href="C:\repub\repub.xsl" type="text/xsl"?>
<repub>
<head>
<title>xxx</title>
</head>
<body>
<sec>
<title>First Title</title>
<break name="1-1">
<heading><page num="1"/>First Heading</heading>
<bl>This is another text</bl>
<p>This is a paragraph</p>
</break>
</sec>
<sec>
<title>Second Title</title>
<break name="2-1">
<heading><page num="1"/>Second Heading</heading>
<bl>This is another text</bl>
<p>This is a paragraph</p>
</break>
</sec>
<sec>
<title>First Title</title>
<break name="3-1">
<heading><page num="1"/>Third Heading</heading>
<bl>This is another text</bl>
<p>This is a paragraph</p>
</break>
</sec>
<sec>
<title>Third Title</title>
<break name="4-1">
<heading><page num="1"/>Fourth Heading</heading>
<bl>This is another text</bl>
<p>This is a paragraph</p>
</break>
<break name="5-1">
<heading><page num="1"/>Fifth Heading</heading>
<bl>This is another text</bl>
<p>This is a paragraph</p>
</break>
</sec>
</body>
</repub>
I have already grouped the values but it is in List<IGrouping<string, XElement>>
format and that is not the issue.
The issue is that I want to check for the values in the list and see if a particular value exists, say for example, in this scenario, "Third Title". So, whenever, in any XML, if there is Third Title, it will always be at the top, that is [0] and the rest will come as they occur.
I want to know how to custom order my list.
Regards Aman
Use a Dictionary with Xml Linq :
Moving element without dictionary
Not sure about the syntax in your case, but here is a solution for a list of strings that you should be able to easily adapt.