【发布时间】:2017-11-25 23:58:13
【问题描述】:
我将以下 xml 作为主要 xml 的一部分。能够将其提取到字符串中,现在我想解析下面的 xml 并将属性名称 PersonN 、 VerifiedHuman 、 CurrAddrBlockIndex 的值放入单独的 csv 文件中 请告诉我如何解决这个问题?
我正在尝试解析的 XML:
<InterConnectResponse>
<SchemaVersion>2.0</SchemaVersion>
<ConsumerSubjects>
<ConsumerSubject subjectIdentifier="Primary">
<DataSourceResponses>
<RiskViewProducts>
<RiskViewAttribResponse>
<Attributes>
<Attribute>
<Name>PersonN</Name>
<Value>3</Value>
</Attribute>
<Attribute>
<Name>VerifiedHuman</Name>
<Value>2</Value>
</Attribute>
<Attribute>
<Name>CurrAddrBlockIndex</Name>
<Value>0.61</Value>
</Attribute>
</Attributes>
</RiskViewAttribResponse>
</RiskViewProducts>
</DataSourceResponses>
</ConsumerSubject>
</ConsumerSubjects>
</InterConnectResponse>
预期输出文件:
3, 2, 0.61
我试过了,但没有成功
StringBuilder output = new StringBuilder();
using (XmlReader reader = XmlReader.Create(new StreamReader(value)))
{
reader.ReadToFollowing("PersonN");
string LNREF72 = reader.Value;
output.AppendLine(LNREF72);
reader.ReadToFollowing("VerifiedHuman");
string VerifiedHuman = reader.Value;
output.AppendLine(", " + VerifiedHuman);
reader.ReadToFollowing("CurrAddrBlockIndex");
string CurrAddrBlockIndex = reader.Value;
output.AppendLine(", " + CurrAddrBlockIndex);
}
【问题讨论】:
标签: c# xml xml-parsing linq-to-xml