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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:05:55+00:00 2026-05-27T13:05:55+00:00

Hi Guys I am having following type of XML to parse. <?xml version=1.0 encoding=utf-8

  • 0

Hi Guys I am having following type of XML to parse.

<?xml version="1.0" encoding="utf-8" ?>
<Functions>

<Function>
<Name>local:FunctionName</Name>
<Library>UserDefined</Library>
<Signature type="xs:decimal+">local:FunctionName(#?VALUE#,arg1,arg2,arg3) as xs:decimal+</Signature>
<Description>Some comments</Description>
<Code><![CDATA[some code]]></Code>
</Function>

<Function>
<Name>local:NewFunction</Name>
<Library>UserDefined</Library>
<Signature type="xs:decimal+">local:NewFunction(num1 as xs:string+,num2 as xs:string+,num3 as xs:string+) as xs:decimal+</Signature>
<Parameters>
     <Parameter type="xs:string" occurence="+" name="num1">num1 as xs:string+</Parameter>
     <Parameter type="xs:string" occurence="+" name="num2">num2 as xs:string+</Parameter>
     <Parameter type="xs:string" occurence="+" name="num3">num3 as xs:string+</Parameter>
</Parameters>
<Description>Some comments</Description>
<Code><![CDATA[some code]]></Code>
</Function>


</Functions>

and after Parsing I have to populate following Models

 List<Function> objFunctionsList = new List<Function>();

where Function class is as follows

 public class Function
    {
        public String Name { get;set;}

        public Parameter ReturnType { get; set;}

        public List<Parameter> Parameters { get; set;}

        public String Library{get;set;}    

        public String Signature{get; set;}

        public String Description{get;set;}

        public String Code{get;set;}
    }

   and the Parameter class is as follows

public class Parameter
{
    [DefaultValue("")] 
    public String Name{get;set;}

    [DefaultValue("")]
    public String DataType{get;set;}

    [DefaultValue("")]
    public String OccurenceType {get; set;}
}

The Code that i am trying is below. I am calling function written below to get list populated.

public static List<Function> GetAllFunctions(String pXMLPath)
        {
            List<Function> objFunctionsList = new List<Function>(); 

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(pXMLPath);


                XElement fList = XElement.Parse(xmlDoc.InnerXml);

                // In following 10 lines I am getting Null-reference exception
                var Functions = fList
                    .Element("Functions")
                    .Elements("Function")
                    .Select(Function => new
                        {
                            Name = (string)Function.Element("Name"),
                            Library = (string)Function.Element("Library"),
                            Signature = (string)Function.Element("Signature"),
                            ReturnType = (string)Function.Attribute("type"),
                            Description = (string)Function.Element("Description"),
                            Code = (string)Function.Element("Code"),
                            Parameters =  GetParamsList(Function)
                        });

                foreach (var f in Functions)
                {
                    Function objFunction = new Function();
                    objFunction.Name = f.Name;
                    objFunction.Library = f.Library;
                    objFunction.Description = f.Description;
                    objFunction.Code = f.Code;
                    objFunction.Signature = f.Signature;
                    objFunction.State = 0;//Unmodified (Save not required)

                    #region Populating Return Type

                    string returnType = f.ReturnType;
                    string signature = f.Signature;

                    Parameter objReturnType = new Parameter();
                    if (String.IsNullOrEmpty(returnType) || returnType == Constants.XSNOPARAM)
                    {
                        objReturnType.Name = string.Empty;
                        objReturnType.OccurenceType = string.Empty;
                        objReturnType.DataType = Constants.XSNOPARAM;
                    }
                    else
                    {

                        if (returnType.EndsWith(Constants.ASTERIK))
                        {
                            objReturnType.DataType = returnType.Substring(0, returnType.Length - 1);
                            objReturnType.OccurenceType = Constants.OCCURENCES_ASTERISK;
                        }
                        else if (returnType.EndsWith(Constants.PLUS))
                        {
                            objReturnType.DataType = returnType.Substring(0, returnType.Length - 1);
                            objReturnType.OccurenceType = Constants.OCCURENCES_PLUS;
                        }
                        else if (returnType.EndsWith(Constants.QUESTION_MARK))
                        {
                            objReturnType.DataType = returnType.Substring(0, returnType.Length - 1);
                            objReturnType.OccurenceType = Constants.OCCURENCES_QUESTION;
                        }
                        else if (returnType.Length > 0)
                        {
                            objReturnType.DataType = returnType;
                        }

                    } 
                    #endregion

                    objFunction.ReturnType = objReturnType;

                    objFunction.Parameters = new List<Parameter>();
                    foreach (var param in f.Parameters.ToList())
                    {
                        Parameter objParam = new Parameter();

                        objParam.Name = param.Name;
                        objParam.DataType = param.DataType;
                        objParam.OccurenceType = param.OccurenceType;

                        objFunction.Parameters.Add(objParam);
                    }

                    objFunctionsList.Add(objFunction);

                }

            }
            catch (Exception ex)
            {

            }
            return objFunctionsList;
        }

private static List<Parameter> GetParamsList(XElement pParametersElement)
        {
            if (pParametersElement != null)
            {
                   var Parameters = pParametersElement
                    .Elements("Parameter")
                   .Select(Parameter => new
                   {
                       Name = (string)Parameter.Attribute("name"),
                       Occurence = (string)Parameter.Attribute("occurence"),
                       Type = (string)Parameter.Attribute("type")
                   });

                List<Parameter> objParamsList = new List<Parameter>();

                foreach (var param in Parameters)
                {
                    Parameter objParam = new Parameter();
                    objParam.Name = param.Name;
                    objParam.OccurenceType = param.Occurence;
                    objParam.DataType = param.Type;

                    objParamsList.Add(objParam);
                }
                return objParamsList;
            }
            else
                return null;
        }

Mainly in following code i m getting Exception

 var Functions = fList
                    .Element("Functions")
                    .Elements("Function")
                    .Select(Function => new
                        {
                            Name = (string)Function.Element("Name"),
                            Library = (string)Function.Element("Library"),
                            Signature = (string)Function.Element("Signature"),
                            ReturnType = (string)Function.Attribute("type"),
                            Description = (string)Function.Element("Description"),
                            Code = (string)Function.Element("Code"),
                            Parameters =  GetParamsList(Function)
                        });

enter image description here

Stack Trace

Type : System.NullReferenceException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Object reference not set to an instance of an object.
Source : MyApp.XEG.Utility
Help link : 
Data : System.Collections.ListDictionaryInternal
TargetSite : System.Collections.Generic.List`1[MyApp.XEG.Model.Function] GetAllFunctions(System.String)
Stack Trace :    at MyApp.XEG.Utility.CFLFile.GetAllFunctions(String pXMLPath) in C:\MyApp\XEG.Utility\CFLFile.cs:line 189

here the line 189 is the highlighted line in yellow

  • 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-27T13:05:56+00:00Added an answer on May 27, 2026 at 1:05 pm

    Errors:

    • swalling the exception!
    • you need var Functions = fList.Elements("Function"). etc – no “Functions” first (at the top)
    • you need Parameters = GetParamsList(Function.Element("Parameters")) (just below that)
    • you need to null-check the parameters: if (f.Parameters != null) foreach(var param in f.Parameters) {...} (near the bottom of GetAllFunctions)

    with those changes, it works. There is also no need for XmlDocument in here; XElement.Load() would be preferable. Personally I’d use XmlSerializer instead, but … meh.

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

Sidebar

Related Questions

Hey Guys, having an issue with Linq-to-SQL, I am basically doing the following but
Hey guys, I'm having a problem handling my callback data in JQuery. The following
Hi guys I'm having problems with the following virtual hosts: <VirtualHost *:80> ServerAdmin webmaster@localhost
Hey guys I'm having such a hard time of it today. I have a
Guys I know this question is silly but just to make sure: Having in
Hey guys i want to execute my SQL statement but im having synatx trouble,
Hey guys, I'm having a problem with IE7, my menu always drops down behind
Hi guys i've never written a comparator b4 and im having a real problem.
HI Guys, Here I am having problem that How can I post an image
H guys. I'm developing a custom component for SSIS. I'm having a problem when

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.