EDIT: A bit more detailed HTML document... In short- how do I actually do the lookup and where precisely should the element.setvalue or element.value appear in the query...
Edit 2: The list of monkey id does not appear clear so I will add proper id's and add additional properties to my Lookup data object, sorry for the confusion! The reason I have used a list is bacause my datasource could be from anywhere also I have used a List object because I do not really know the proper usage of Dictionary (I am a newbie to coding hence why my question is all over the place, please bear with me)
I have an XElement which is a properly formatted HTML document, I am trying to replace only the value of a html element with a value contained in a List Object for example
<div id="pageContainer">
<p> some guy wants to <b>buy</b> a <h4><label id="monkey23">monkeyfield</label></h4> for some price that I do not have a clue about, maybe we should <i>suggest</i> a list of other monkeys he may like:
</p>
<h3>list of special monekeys you may want chappy...</h3>
<br />
<ul>
<li><label id="monkey13">monkeyfield</label></li>
<li><label id="monkey3">monkeyfield</label></li>
<li><label id="animal4">animalfield</label></li>
<li><label id="seacreature5">seacreaturefield</label></li>
<li><label id="mamal1">mamal field</label></li>
</ul>
</div>
Note: the value "monkeyfield" is a temporary value inserted onscreen for the purpose of identifying this is a field, once the values from the data source is binded the new values should appear.
public class LookupData
{
public string id{get;set;}
public string value{get;set;}
public string Type{get;set;}
public string Url{get;set;}
}
...
public void DataTransformerMethod()
{
var data = new List<LookupData>();
data.add(new LookupData{id="monkey3", value="special monkey from africa" });
data.add(new LookupData{id="monkey13", value="old monkey from china" });
data.add(new LookupData{id="seacreature5", value="sea monkey" });
data.add(new LookupData{id="animal4", value="rhino" });
data.add(new LookupData{id="mamal1", value="some mamal creature" });
//what linq query will iterate over the document and set the values from the values
//found in the list?
var answer = from x in HtmlDocAsAXelement
where x.Attributes()
.Any(a=> data.AsEnumerable().Where(f=> f.Name == a.Name) );
//somehow I should use .SetValue(a.value)???
SaveTheNewXElement(answer ); //all other original data must stay in tact...
}
- I will update, could you provide any code?