this c# code is probably not the most efficient but gets what I want done.
How do I accomplish the same thing in F# code?
string xml = " <EmailList> " +
" <Email>[email protected]</Email> " +
" <Email>[email protected]</Email> " +
" </EmailList> ";
XmlDocument xdoc = new XmlDocument();
XmlNodeList nodeList;
String emailList = string.Empty;
xdoc.LoadXml(xml);
nodeList = xdoc.SelectNodes("//EmailList");
foreach (XmlNode item in nodeList)
{
foreach (XmlNode email in item)
{
emailList += email.InnerText.ToString() + Environment.NewLine ;
}
}
let doc = new XmlDocument() in
doc.LoadXml xml;
doc.SelectNodes "/EmailList/Email/text()"
|> Seq.cast<XmlNode>
|> Seq.map (fun node -> node.Value)
|> String.concat Environment.NewLine
If you actually want the final trailing newline you can add it in the map and String.concat with the empty string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With