我有一个奇怪的问题。我无法以任何方式修改我需要使用的 XML(这导致了我的问题)。我正在处理的 XML 采用以下形式:
<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>
我想做的是提取此信息,并使用它来实例化一个自定义类 CustomClassName,然后将其添加到 aList<CustomClassName>
中,其中 XML 文档中的每个不同 <ClassName>
元素(不是值)用于创建一个新的 CustomClassName以下表格:
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
}
我希望我已经清楚地解释了我的愿望,如果没有,请戳我以获取更多信息。
是否有可能做到这一点 ?
编辑 :
对于每个“不同的”ClassName 元素,我的意思是元素 ClassName 将在 XML 文档中出现多次,尽管如此,我希望只用其相关属性(ClassAttribute 元素的值)实例化一个 ClassName 类,并且不同的 ClassName 元素的值被“附加”到实例化类中属性的末尾。