F# XML parsing

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>test@email.com</Email> " +
               "      <Email>test2@email.com</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 ;
        }               
    }

Answers


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.


Need Your Help

Haskell lazy Bytestring words not lazy?

haskell bytestring long-lines lazy-io

I have the following Haskell program for computing a maximum sum substring of a string of integers:

Jenkins build 'cannot find current revision' at GitHub

git github jenkins git-submodules

I have a (private) project at GitHub which has a submodule. When I invoke the ant build at the command line in Terminal (OSX), the build is fine. But when the same build.xml is invoked via Jenkin...