【发布时间】:2019-02-28 12:52:59
【问题描述】:
我有一个 XML,我想对具有相同值的多个元素进行分组。
<?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>
我已经对这些值进行了分组,但它是List<IGrouping<string, XElement>> 格式,这不是问题。
问题是我想检查列表中的值并查看是否存在特定值,例如,在这种情况下,“第三个标题”。因此,无论何时,在任何 XML 中,如果有第三个标题,它将始终位于顶部,即 [0],其余的将在它们出现时出现。
我想知道如何自定义我的列表。
问候 阿曼
【问题讨论】:
标签: c# .net xml visual-studio linq