Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4233930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:17:02+00:00 2026-05-21T02:17:02+00:00

I get the following xml from a web service which I want to convert

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:17:02+00:00Added an answer on May 21, 2026 at 2:17 am

    Your approach to use active patterns to match different types of nodes looks good to me. I would probably use partial patterns (that can either return Some when they match or None) instead of complete patterns (that always return one of the cases). This allows you to write several patterns for different types of nodes you’re handling.

    let (|Result|_|) (node:#System.Xml.XmlNode) =
      if node.Name = "result" then
        Some(new Result(node))
      else
        None
    

    In the pattern matching, you can then include as many partial patterns as you like and cover all remaining cases using _ (wildcard pattern):

    match node with 
    | Result(p) ->
        Seq.singleton p
    | nd ->
        Seq.collect (fun (n) -> extract n) nd.ChildNodes
    

    Other than this, I’m not sure – the structure in your example looks quite regular, so you don’t need to handle cases as in HTML (where <a> can be nested in various other elements). It seems you can just represent the main part of XML as a list of accounts (and parse all account properties using active patterns).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the Category based total of the following <?xml version=1.0 encoding=utf-8
What I have is an XML we receive from a web service which represents
(Following up on this question: Getting raw XML response from Java web service client
How can I get data from an xml web service (say, the value of
Following on from my recent question on Large, Complex Objects as a Web Service
In a Web Service context, I have the following class which inherit from the
From windows event viewer I can get the following xml structure: <Event xmlns=http://schemas.microsoft.com/win/2004/08/events/event> <System>
I get the following text as a string from an XML-based REST API 'd':4
I am using the following code to get an XML data from a website
How can I get the connection.connection_string value from the following hibernate xml file using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.