I get the following xml from a web service which I want to convert into .net objects:
let xmlString = "<?xml version=\"1.0\"?>
<logInResponse>
<result>OK</result>
<xmlLogIn>
<session>11C0ED6F8F7288855FC73C99979A9732.TOGKE6VP9aE8abcdLXaVXg</session>
<user>WallStreetScumbag1</user>
<authorizations>
<insiderTrading>true</insiderTrading>
</authorizations>
</xmlLogIn>
</logInResponse>"
This is what I have so far:
type Result(value:XmlNode) =
member this.Value = value.InnerText
let (|Node|Result|) (node : #System.Xml.XmlNode) =
if node.Name = "result" then
Result (new Result(node))
else
Node (seq {for x in node.ChildNodes -> x})
let extract node =
let rec extract node =
match node with
| Result(p) ->
Seq.singleton p
| Node(nodes) ->
Seq.collect (fun (n) -> extract n) nodes
extract node
let xmlDoc = new XmlDocument()
xmlDoc.LoadXml(xmlString)
//type LogIn() =
//This is where I would create a .net object that mirrors the xml.
As you can see some elements are repeated within different elements and sometimes elements don't include all the elements that can show up as you can see in my sample xml. This same web service will also reuse many of these same elements in other types of responses. Is it possible to use active patterns to create a general way to deserialize the xml I get back into objects? It appears that this web service never uses attributes to send information, it all seems to be elements inside elements which might make this problem easier. If I am going about this the wrong way please feel free to suggest something better.
Thanks in advance,
Bob