I have a xml from which I want to parse only specific attributes not all. I have 100s of attributes and the xml I provided is a sample with few attributes
. I want explicitly specify the attributes names and parse their values.
Eg : I want to parse get the values of the Attribute names PersonN , VerifiedHuman
In my logic I want to parse the values by specifying attribute names like <Name>PersonN</Name> and parse its value
The result should be a csv.
<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>
------ Many More Attributes ---------
</Attributes>
</RiskViewAttribResponse>
</RiskViewProducts>
</DataSourceResponses>
</ConsumerSubject>
</ConsumerSubjects>
</InterConnectResponse>
Logic I am using : (I dont know how to specify the attribute names and get their values)In this code str3 is the above xml.
using (XmlReader read = XmlReader.Create(new StringReader(str3)))
{
bool isValue = false;
while (read.Read())
{
if (read.NodeType == XmlNodeType.Element && read.Name == "Value")
{
isValue = true;
}
if (read.NodeType == XmlNodeType.Text && isValue)
{
output.Append((output.Length == 0 ? "" : ", ") + read.Value);
isValue = false;
}
}
}
Expected output :
3, 2
ConsumerSubjectelements? - Jon Skeet