I have a weird problem. I cannot modify the XML I need to work with in any way (which is causing me the problem). The XML I am dealing with takes the following form :
<DocumentRoot>
<Parent>
<ClassAttribute> Value </ClassAttribute>
<ClassName> More Attributes </ClassName> <!--Can occur a varying number of times.-->
</Parent>
<Parent>
<ClassAttribute> Value </ClassAttribute>
<ClassName> More Attributes </ClassName>
<ClassName> More Attributes </ClassName>
</Parent>
</DocumentRoot>
What I wish to do is extract this information, and use it to instantiate a custom class, CustomClassName, which will then be added to a List<CustomClassName>, where each distinct <ClassName> element (not value) from the XML document is used to create a new CustomClassName of the following form :
public class CustomClassName {
public string ClassName; //gotten from the ClassName element (NOT the value)
public List<string> classAttributes //gotten from the value inside the ClassAttribute element
public List<string> moreAttributes //gotten from the value inside the ClassName element
}
I hope I have explained my wishes clearly, if not please poke me for further information.
Is it possible to do this ?
Edit :
By each “distinct” ClassName element, I mean that the element ClassName will be present several times in the XML document, despite this I would like only one ClassName class to be instantiated with its relevant attributes (the value of the ClassAttribute element) and the value of the distinct ClassName element being “appended” to the end of the properties in instantiated class.
try this