0

I am trying to retrieve all my data from an XML file and place all data inside a newly created ArrayList which consists of int, int, string, string, and an array which has int, int, string, string, and a boolean. This is the test data:

In my new array it will hold the following:

login_group

group id, name, description, number, and "array" 

login_types

type id, group_id, title, description, enabled.

login_groups

group id="0" name="Private" description="This type of login is enabled to do   whatever." display_number="1".

login_types

type id="0" group_id="1" title="Standard" description="This login type is shortlived." enabled="false"
type id="0" group_id="2" title="Standard" description="This login type is fast paced." enabled="false"

My CS

public struct LoginGroupInfo
{
    public int id;
    public string name;
    public string description;
    public int number;
    public ArrayList types;       
}

public struct types
{
    public int id;
    public int group_id;
    public string title;
    public string description;
    public bool enabled;
}

if (!LoginTypes(id, out loginGroupList))
{
    MessageBox.Show("Error, nothing found");
}
else
{
    MessageBox.Show("Something, found");
}

public static bool LoginTypes(int Id, out ArrayList loginGroupList)
{
    bool success = false; // Return value.         

    //create a new list for my groups
    ArrayList loginList = new ArrayList();        

    try
    {
        // Get the "main" XmlNode.
        XmlNode groupNode = GetXmlDoc(myXmlFile).SelectSingleNode("login_groups");

        // Verify that node exists and get the rest.
        if (groupNode != null)
        {
            // Get the services XmlNodeList.
            XmlNodeList groupList = groupNode.SelectNodes("group");

            // Loop through the login-types.
            foreach (XmlNode typeNode in groupList)
            {
                success = true;
                LoginGroupInfo loginType = new LoginGroupInfo();

                // Save the relevant data.
                loginType.id = StrToInt(typeNode.Attributes["id"].Value);
                loginType.name = typeNode.Attributes["name"].Value;
                loginType.description = typeNode.Attributes["description"].Value;
                loginType.number = StrToInt(typeNode.Attributes["display_number"].Value);
                loginType.types= ?;
                //Not sure how to set this up, this is where i need the info 
                //from <login_types> to be placed inside the arraylist "types" inside the loginType.

                loginGroupList.Add(loginType);
            }
        }
    }
    return success;
 }
Shweta Pathak
  • 775
  • 1
  • 5
  • 21
Pedro
  • 1
  • 1
  • 3
  • 3
    The first thing I'd urge you to do is stop using public fields, and stop using mutable structs. Oh, and start following .NET naming conventions, and ditch `ArrayList` which was superseded by `List` about 10 years ago. I'd also suggest using LINQ to XML instead of the old `XmlDocument` API. Finally, you haven't actually asked a *question* which makes it hard to help you... – Jon Skeet Oct 12 '15 at 23:57
  • Thank you for the useful feedback. I am not sure how to get the data as shown into one array is the question. How can I achieve this given with the way this is being built? – Pedro Oct 13 '15 at 00:00
  • Well you already have code to add the element to the `ArrayList`... (I would strongly recommend *not* using a return type of bool for success/fail in general, btw - your method should return the list of types. Note that you never set `success` to true in your code, either.) Your question is still really unclear. It doesn't help that we can't see the XML you're trying to parse. – Jon Skeet Oct 13 '15 at 00:03
  • Why not just use standard [xml serialization](http://www.codeproject.com/Articles/483055/XML-Serialization-and-Deserialization-Part)? Much easier! – Mark Feldman Oct 13 '15 at 00:10
  • 1
    aside from seeking assistance on answering this question the feedback alone has made this worth posting, Thanks! – Pedro Oct 13 '15 at 00:36

0 Answers0