troubleshooting Question

C# Finding Value in Parent / Multiple Child objects Returning Child values

Avatar of psdesignadmin
psdesignadminFlag for United States of America asked on
C#.NET ProgrammingXML
9 Comments1 Solution345 ViewsLast Modified:
I have filled the following Parent Class and Multiple Child classes from XML data.

Parent Class (Materials.cs):

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JobInvoicerCS
{
	[XmlRoot(ElementName="Materials")]
	public class Materials
    {
		[XmlElement(ElementName="WF")]
		public List<WF> WF { get; set; }
		[XmlElement(ElementName="M")]
		public List<M> M { get; set; }
		[XmlElement(ElementName="S")]
		public List<S> S { get; set; }
		[XmlElement(ElementName="HP")]
		public List<HP> HP { get; set; }
		[XmlElement(ElementName="WT")]
		public List<WT> WT { get; set; }
		[XmlElement(ElementName="MT")]
		public List<MT> MT { get; set; }
		[XmlElement(ElementName="ST")]
		public List<ST> ST { get; set; }
		[XmlElement(ElementName="C")]
		public List<C> C { get; set; }
		[XmlElement(ElementName="MC")]
		public List<MC> MC { get; set; }
		[XmlElement(ElementName="TS")]
		public List<TS> TS { get; set; }
		[XmlElement(ElementName="TSR")]
		public List<TSR> TSR { get; set; }
		[XmlElement(ElementName="Pipe")]
		public List<Pipe> Pipe { get; set; }
		[XmlElement(ElementName="Angle")]
		public List<Angle> Angle { get; set; }
		[XmlElement(ElementName="DoubleAngle")]
		public List<DoubleAngle> DoubleAngle { get; set; }
	}
}

Here is one child class (WF.cs):

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JobInvoicerCS
{
    [XmlRoot(ElementName = "WF")]
    public class WF
    {
        [XmlElement(ElementName = "Size")]
        public string Size { get; set; }
        [XmlElement(ElementName = "A")]
        public string A { get; set; }
        [XmlElement(ElementName = "d")]
        public string D { get; set; }
        [XmlElement(ElementName = "tw")]
        public string Tw { get; set; }
        [XmlElement(ElementName = "bf")]
        public string Bf { get; set; }
        [XmlElement(ElementName = "tf")]
        public string Tf { get; set; }
        [XmlElement(ElementName = "k_des")]
        public string K_des { get; set; }
        [XmlElement(ElementName = "k_det")]
        public string K_det { get; set; }
        [XmlElement(ElementName = "k1")]
        public string K1 { get; set; }
        [XmlElement(ElementName = "T")]
        public string T { get; set; }
        [XmlElement(ElementName = "gage")]
        public string Gage { get; set; }
        [XmlElement(ElementName = "wt__ft")]
        public string Wt__ft { get; set; }
        [XmlElement(ElementName = "bf__2_tf")]
        public string Bf__2_tf { get; set; }
        [XmlElement(ElementName = "h_tw")]
        public string H_tw { get; set; }
        [XmlElement(ElementName = "Ix")]
        public string Ix { get; set; }
        [XmlElement(ElementName = "Sx")]
        public string Sx { get; set; }
        [XmlElement(ElementName = "rx")]
        public string Rx { get; set; }
        [XmlElement(ElementName = "Zx")]
        public string Zx { get; set; }
        [XmlElement(ElementName = "Iy")]
        public string Iy { get; set; }
        [XmlElement(ElementName = "Sy")]
        public string Sy { get; set; }
        [XmlElement(ElementName = "ry")]
        public string Ry { get; set; }
        [XmlElement(ElementName = "Zy")]
        public string Zy { get; set; }
        [XmlElement(ElementName = "rts")]
        public string Rts { get; set; }
        [XmlElement(ElementName = "ho")]
        public string Ho { get; set; }
        [XmlElement(ElementName = "J")]
        public string J { get; set; }
        [XmlElement(ElementName = "Cw")]
        public string Cw { get; set; }
        [XmlElement(ElementName = "Wno")]
        public string Wno { get; set; }
        [XmlElement(ElementName = "Sw1")]
        public string Sw1 { get; set; }
        [XmlElement(ElementName = "Qf")]
        public string Qf { get; set; }
        [XmlElement(ElementName = "Qw")]
        public string Qw { get; set; }
    }
}

I am attaching the XML and the other child classes for brevity.

I am trying to find values contained in the sub-classes if they contain a certain Size.  Each sub-class contains a Size property but will not know if they are WF, WT, C, etc.

For example:

Need to return all values in the query if Size = "W12x40".  I know this would be a WF, the query should return all properties for that size.

I fill the Parent Children using this code:

            string path = @"XmlFiles\Materials.xml";
            XmlSerializer serial = new XmlSerializer(typeof(Materials));
            StreamReader reader = new StreamReader(path);
            
            StructuralMaterials = (Materials)serial.Deserialize(reader);
            reader.Close();

I will not know what subclass the size will be in on all cases. I am also not sure if I should change my structures to improve this portion of my code.

Materials.xml
Angle.cs
C.cs
DoubleAngle.cs
M.cs
HP.cs
MC.cs
MT.cs
Pipe.cs
S.cs
ST.cs
TS.cs
TSR.cs
WT.cs
ASKER CERTIFIED SOLUTION
ste5an
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros