I have an xml file like the following:
<Links>
<Link>
<Text>Google</Text>
<Uri>http://ift.tt/1tgogIY;
</Link>
<Link>
<Text>Yahoo</Text>
<Uri>http://ift.tt/1tLFWBt;
</Link>
</Links>
From it, I'd like to build a bunch of Hyperlink elements containing
- Display text
- A URI
- A method to navigate to the URI
Obviously, there's a number of ways of going about this, and historically, I'd probably do something like this:
List<ACMEXmlNode> nodes = ACMEXmlParser.GetNodes("Link", targetDoc);
List<Hyperlink>;
foreach (var node in nodes) {
var currentLink = new Hyperlink();
currentLink.Uri = node.ChildNode("Uri").Value;
// Can't work out how to do the below line in a linq statement
currentLink.ContentStart.InsertTextInRun(node.ChildNode("Text").Value);
currentLink.RequestNavigate += this.DoBrowserNavigate;
}
However, I'm also trying to learn Linq, and this seems like it should be a typical use-case for it. Can anyone help me with how to accomplish the same kind of thing with it? Thus far, I have:
_Links = new List<Hyperlink>(
from linkElement in oLinksConfig.Descendants("Links")
select new Hyperlink
{
NavigateUri = new System.Uri(linkElement.Element("Uri").Value ),
// Fails...
ContentStart.InsertTextInRun(linkElement.Element("Text").Value)
}
).ToList();
Which doesn't work. If anyone can tell me how to fix it so it does, I'd be grateful.
No comments:
Post a Comment