.NET需要将XML转换为另一种格式

时间:2016-11-04 11:00:17

标签: c# asp.net xml xml-serialization

我正在创建一个MVC应用程序,我正在从Dataset创建XML。现在,我需要将该XML转换为另一种格式,以便重复ID节点,如下所示。

原始XML:

<Requirements>
  <Requirement>
    <ID>Req97</ID>
    <VagueWord>or</VagueWord>
    <Suggestion>Keep each requirement in a single sentence.</Suggestion>
    <Explanation>Suggests that you are combining requirements. Requirements that contain conjunctions/disjunctions (AND/OR) are dangerous and can lead to downstream problems in defining scope of the requirement.</Explanation>
    <VaguePhrase>Marketing or Servicing</VaguePhrase>
    <ContentText>If a user is identified as Marketing or Servicing, then the Campaign Management (CM) hyperlink should be displayed.</ContentText>
    <VagueTypeText>Not Standard</VagueTypeText>
  </Requirement>
  <Requirement>
    <ID>Req97</ID>
    <VagueWord>should</VagueWord>
    <Suggestion>Use 'shall/must/will' for requirements,</Suggestion>
    <Explanation>Is often ambiguous, or inappropriate. Some readers will interpret these as optional or advisory, others as required.</Explanation>
    <ContentText>If a user is identified as Marketing or Servicing, then the Campaign Management (CM) hyperlink should be displayed.</ContentText>
    <VagueTypeText>Not Standard</VagueTypeText>
  </Requirement>
  <Requirement>
    <ID>Req98</ID>
    <VagueWord>Unless</VagueWord>
    <Suggestion>Specify each conditions explicitly. One condition per requirement.</Suggestion>
    <Explanation>Is an escape clause. Requirements with escape clauses are not testable. The word implies additional condition to the requirement.</Explanation>
    <ContentText>Unless Sleep, Latency, Noise, or apply conditions are present, the data transmissions will contain the code for Normal Operation.</ContentText>
    <VagueTypeText>Not Standard</VagueTypeText>
  </Requirement>
</Requirements>

预期的XML:

<Requirements>
  <Requirement>
    <ID>Req97</ID>
     <VagueWords>
    <VagueWord id="1">or</VagueWord>
    <VagueWord id="2">should</VagueWord>
    </VagueWords>
    <Suggestions>
    <Suggestion id="1">Keep each requirement in a single sentence.</Suggestion>
    <Suggestion id="2">Use 'shall/must/will' for requirements,</Suggestion>
    </Suggestions>
    <Explanations>
    <Explanation id="1">Suggests that you are combining requirements. Requirements that contain conjunctions/disjunctions (AND/OR) are dangerous and can lead to downstream problems in defining scope of the requirement.</Explanation>
    <Explanation id="2">Is often ambiguous, or inappropriate. Some readers will interpret these as optional or advisory, others as required.</Explanation>
    </Explanations>
    <VaguePhrases>
    <VaguePhrase id="1">Marketing or Servicing</VaguePhrase>
    <ContentText id="1">If a user is identified as Marketing or Servicing, then the Campaign Management (CM) hyperlink should be displayed.</ContentText>
    </VaguePhrases>
    <ContentTexts>
    <ContentText id="2">If a user is identified as Marketing or Servicing, then the Campaign Management (CM) hyperlink should be displayed.</ContentText>
    </ContentTexts>
    <VagueTypeTexts>
    <VagueTypeText id="1">Not Standard</VagueTypeText>
    <VagueTypeText id="2">Not Standard</VagueTypeText>
    </VagueTypeTexts>
  </Requirement>
 <Requirement>
    <ID>Req98</ID>
     <VagueWords>
    <VagueWord>Unless</VagueWord>
     </VagueWords>
     <Suggestions>
    <Suggestion>Specify each conditions explicitly. One condition per requirement.</Suggestion>
    </Suggestions>
    <Explanations>
    <Explanation>Is an escape clause. Requirements with escape clauses are not testable. The word implies additional condition to the requirement.</Explanation>
    </Explanations>
    <ContentTexts>
    <ContentText>Unless Sleep, Latency, Noise, or apply conditions are present, the data transmissions will contain the code for Normal Operation.</ContentText>
    </ContentTexts>
    <VagueTypeTexts>
    <VagueTypeText>Not Standard</VagueTypeText>
    </VagueTypeTexts>
  </Requirement>
</Requirements>

我需要添加属性为&#34; id&#34;仅用于重复节点ID。如果这个预期的XML不是有效的XML格式,请告诉我

0 个答案:

没有答案