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 1024787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:49:49+00:00 2026-05-16T11:49:49+00:00

Deat alls, I try to work this few rows of code, but I really

  • 0

Deat alls,

I try to work this few rows of code, but I really do not know why the ‘myTreeNodes‘ List of TreeNodes reset during the call of the ‘extractData‘ routine.

It seem that I have respected all the necessary constraints and good practice, but something … I have missed!

Many thanks in advance for any of your suggestion

ANN

Code

    let GetFactors =        
        let errorHeader = "Gasket Factor - List Retrieve"
        let doc = new XmlDocument()
        let myTreeNodes = List<TreeNode>.Empty 

        let readData (xmlNode:XmlNode) (treeNodes:List<TreeNode>) =
            match xmlNode.Name with
            |   "GasketFactors" -> 
                    let attribs = xmlNode.Attributes
                    if (attribs.Count > 0) then
                        let name = GetStringData "Version" attribs
                        printfn "GASKET FACTORS VERSION: '%s'" name
            |   "Gasket" -> 
                    let attribs = xmlNode.Attributes                         
                    if (attribs.Count > 0) then
                        let name = GetStringData "Type" attribs
                        let mainNode = new TreeNode(name)
                        let treeNodes = mainNode :: treeNodes
                        printfn " - Type: %s " name
            |   "Data" -> 
                    let attribs = xmlNode.Attributes 
                    if (attribs.Count > 0) then
                        let parent = List.head treeNodes
                        let gskType = parent.Name 
                        let gskSource = GetStringData "Source" attribs
                        let gskSubType = GetStringData "SubType" attribs
                        let gskMaterialGroup = GetStringData "Group" attribs
                        let gskMaterial = GetStringData "Material" attribs
                        let gskMaterialFiller = GetStringData "Filler" attribs
                        let gskMaterialLayers = GetStringData "Layers" attribs
                        let gsk_m = 
                            let value = GetStringData "m" attribs
                            0.0
                        let gsk_y = 
                            let value = GetStringData "y" attribs
                            0.0
                        let gskFactors = new Factors(gsk_m, gsk_y)
                        let gskService = GetStringData "Service" attribs
                        let gskUserNote = GetStringData "Note" attribs
                        let gskShow = GetBoolData "Show" attribs
                        let newGasket = new Gasket(gskSource, gskType, gskSubType,
                                                   gskMaterial, gskMaterialGroup, gskMaterialFiller, gskMaterialLayers,
                                                   gskFactors, new Geometry(),
                                                   gskService, gskUserNote, gskShow) 
                        let childNode = new TreeNode(gskSubType)
                        childNode.Tag <- newGasket
                        parent.Nodes.Add(childNode) |> ignore
                        printfn "     - Sub Type: %s " (newGasket.ToString())
            |   _ -> 
                    printfn "%A" xmlNode

        let rec extractData (xmlNode:XmlNode) (treeNodes:List<TreeNode>) =
            if (xmlNode <> null) then
                match xmlNode.NodeType with
                |   XmlNodeType.Element -> 
                        readData xmlNode treeNodes
                        printfn "{TEXT: %s}" xmlNode.Value
                        if (xmlNode.HasChildNodes) then
                            extractData xmlNode.FirstChild treeNodes
                        else
                            let next = xmlNode.NextSibling
                            let parent = xmlNode.ParentNode 
                            if (next <> null) then
                                extractData next treeNodes    
                            else
                                extractData parent treeNodes  
                |   XmlNodeType.Text | XmlNodeType.CDATA ->
                        printfn "{TEXT: %s}" xmlNode.Value
                        extractData xmlNode.NextSibling treeNodes
                |   XmlNodeType.Comment ->
                        printfn "{COMMENT: %s}" xmlNode.Value
                        extractData xmlNode.NextSibling treeNodes
                |   XmlNodeType.ProcessingInstruction | XmlNodeType.XmlDeclaration ->
                        printfn "{DECLARATION: %s = %s}" xmlNode.Name xmlNode.Value
                        extractData xmlNode.NextSibling treeNodes
                |   _ -> 
                        printfn "{OTHER: %s = %s}" xmlNode.Name xmlNode.Value 
                        extractData xmlNode.NextSibling treeNodes
            else
                ()

        try
            doc.Load( Resources.GasketXMLFactorsPath )
        with
        | ex -> failwith (errorHeader + ": Not Possible to Load!" + ex.ToString())            
        extractData doc.FirstChild myTreeNodes
        myTreeNodes

XML Source

{GasketFactors Version="1.0.0.0"}

{Gasket Type="Self-Energizing"}

{Data Source="ASME" SubType="Welded" m="0.00" y="0.0 psi" /}

{Data Source="ASME" SubType="Any" m="0.00" y="0.0 psi" /}

{/Gasket}

{Gasket Type="Vegetable Fibers"}

{Data Source="ASME" SubType="Any" Material="Any" m="1.75" y="1100.0 psi" /}

{/Gasket}

{/GasketFactors}
  • 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-16T11:49:49+00:00Added an answer on May 16, 2026 at 11:49 am

    I haven’t dived deeply, but if

    let myTreeNodes = List<TreeNode>.Empty 
    

    is F# list<‘T>, then it is immutable and when you append element to list – you construct new list instead of mutating source one. You can either on every step take source list and return modified version or use mutable collection like System.Collections.Generic.List<‘T> or System.Collections.Generic.LinkedList<‘T> to accumulate changes.

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

Sidebar

Related Questions

No related questions found

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.