Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to read below xml data.

<MetaDataVersion OID="CDASH_MetaDataVersion_2011-10-24" Name="CDASH MDV">
<FormDef OID="F.AE_2011-10-24" Name="Adverse Event" Repeating="No">
<ItemGroupRef Mandatory="Yes" ItemGroupOID="IG.AEYN_2011-10-24"/>
<ItemGroupRef Mandatory="Yes" ItemGroupOID="IG.AE_DETAILS_2011-10-24"/>


IF you see I want data from "FORMDef" Element and want to check if it has "ItemGroupRef" then i want to read. When I am reading using XMLTextreader, I am able to read "FormDef" but I want to read "ItemGroupRef" in same loop. If it is present then read and move reader to next element.

Now when I am reading my program goes to "FORMDef" and in next cycle it is going to "ItemGroupRef" but since "ItemGroupRef" is sub element of "FormDef" i want to read it at one go and move reader to next.

Kidly Help

What I have tried:

public ArrayList Form_data = new ArrayList();
        public struct Form_attr
        {
            public string OID;
            public string Name;
            public string repeating;
        };
        public frmMain()
        {
           
            InitializeComponent();
            load_XML();
        }

        public void load_XML()
        {
         
            Form_attr fa;
            try
            {
                XmlTextReader reader = new XmlTextReader("updated.xml");
                while (reader.Read())
                {
                    if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "FormDef"))
                    {
                        if (reader.HasAttributes)
                        {
                            fa.OID = reader.GetAttribute("OID");
                            fa.Name = reader.GetAttribute("Name");
                            fa.repeating = reader.GetAttribute("Repeating");
                            Form_data.Add(fa);
                            
                            
                        }
                                           
                        
                        
                    }
                 /*   else if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "FormDef"))*/



                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
               
            }


            for (int i = 0; i < Form_data.Count; i++)
            {
                Form_attr test = (Form_attr)Form_data[i];
              Console.WriteLine("Form OID--> "+test.OID+" Name==>"+test.Name+"   Repeating-->"+test.repeating );
            }
            
        }
    }
}
Posted
Updated 26-Nov-18 1:00am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900