【发布时间】:2019-09-12 05:29:38
【问题描述】:
我有以下 XML 文件,我怎样才能获得存储在给定类型的标签中的值(在这种情况下说类型为“FileModel”) ..我怎样才能编写一些代码来获取值 Rep1 和 Rep2 。我需要这些值在方法中运行某个验证
我怎样才能做到这一点?
<?xml version="1.0"?>
<MainClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Items>
<Settings xsi:type="FileModel">
<Name>Rep1</Name>
<IsActive>true</IsActive>
<IsHidden>false</IsHidden>
</Settings>
<Settings xsi:type="FileModel">
<Name>Rep2</Name>
<IsActive>true</IsActive>
<IsHidden>false</IsHidden>
</Settings>
<Settings xsi:type="ServerModel">
<Name>DelRep</Name>
<IsActive>false</IsActive>
<IsHidden>false</IsHidden>
</Settings>
</Items>
</MainClass>
【问题讨论】:
-
您目前如何处理 XML?通过
XmlSerializer反序列化?用 LINQ to XML 解析?用XmlDocument解析? -
现在我的整个 XML 文件存储为类似 string WholeContent = File.ReadAllText(this.FilePath); 的字符串,并且 WholeContent 在其他地方使用,但我认为 linq在这种情况下,将 XML 转换为更好的方法
-
查看其他答案here,看看有什么可以帮助你的
标签: c# xml serialization