EDN Admin
Well-known member
I have an XML file with a format that will be like:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; Properties<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MMI_PRE<span style="color:Black; "<span style="color:Blue; >NO<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MMI_POST<span style="color:Black; "<span style="color:Blue; >YES<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ReportOnlyFlag_PRE<span style="color:Black; "<span style="color:Blue; >0<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ReportOnlyFlag_POST<span style="color:Black; "<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SettlementStatus_PRE<span style="color:Black; "<span style="color:Blue; >CSI<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SettlementStatus_POST<span style="color:Black; "<span style="color:Blue; >NIS<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Properties<span style="color:Blue; >
[/code]
I would like to find an effecient LINQ to XML script that will return the Property ID value + the Property value, but not sure how to do this.
I am able to at least get the ID values (but not property value) by doing the following:
<div style="color:Black;background-color:White; <pre>
XDocument xDoc = XDocument.Parse(rdr[<span style="color:#A31515; "Data"].ToString().Trim());
<span style="color:Blue; var properties = (<span style="color:Blue; from p <span style="color:Blue; in xDoc.Descendants(<span style="color:#A31515; "Property")
<span style="color:Blue; select p.Attribute(<span style="color:#A31515; "ID").Value).ToList();
<span style="color:Blue; foreach (<span style="color:Blue; var property <span style="color:Blue; in properties)
{
<span style="color:Blue; string id = property;
}
[/code]
So I think I am close, but could use some help on how to get a list of, say, {"MMI_PRE". "NO"}, {"MMI_POST", "YES"}, etc. from the above sample XML.
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; Properties<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MMI_PRE<span style="color:Black; "<span style="color:Blue; >NO<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; MMI_POST<span style="color:Black; "<span style="color:Blue; >YES<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ReportOnlyFlag_PRE<span style="color:Black; "<span style="color:Blue; >0<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ReportOnlyFlag_POST<span style="color:Black; "<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SettlementStatus_PRE<span style="color:Black; "<span style="color:Blue; >CSI<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Property <span style="color:Red; ID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SettlementStatus_POST<span style="color:Black; "<span style="color:Blue; >NIS<span style="color:Blue; </<span style="color:#A31515; Property<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Properties<span style="color:Blue; >
[/code]
I would like to find an effecient LINQ to XML script that will return the Property ID value + the Property value, but not sure how to do this.
I am able to at least get the ID values (but not property value) by doing the following:
<div style="color:Black;background-color:White; <pre>
XDocument xDoc = XDocument.Parse(rdr[<span style="color:#A31515; "Data"].ToString().Trim());
<span style="color:Blue; var properties = (<span style="color:Blue; from p <span style="color:Blue; in xDoc.Descendants(<span style="color:#A31515; "Property")
<span style="color:Blue; select p.Attribute(<span style="color:#A31515; "ID").Value).ToList();
<span style="color:Blue; foreach (<span style="color:Blue; var property <span style="color:Blue; in properties)
{
<span style="color:Blue; string id = property;
}
[/code]
So I think I am close, but could use some help on how to get a list of, say, {"MMI_PRE". "NO"}, {"MMI_POST", "YES"}, etc. from the above sample XML.
View the full article