原先字符串
<TireSize>195/55R15 花纹CPC2</TireSize>
<AveragePrice>680</AveragePrice>
<MonthlyTireVolume>4</MonthlyTireVolume>
<TireSize>265/65R17 花纹LX</TireSize>
<AveragePrice>1380</AveragePrice>
<MonthlyTireVolume>2</MonthlyTireVolume>
需要效果
<TireSize>
<TireSize>195/55R15 花纹CPC2</TireSize>
<AveragePrice>680</AveragePrice>
<MonthlyTireVolume>4</MonthlyTireVolume>
</TireSize>
<TireSize>
<TireSize>265/65R17 花纹LX</TireSize>
<AveragePrice>1380</AveragePrice>
<MonthlyTireVolume>2</MonthlyTireVolume>
</TireSize>
看起来就是<TireSize>节点没有结束,是吧?
可以采用直接替换的方式实现:
sourceString.Replace("</MonthlyTireVolume>","</MonthlyTireColume></TireSize>")
类似于这样的代码。
这样有规则的可以当做节点去操作