У меня есть два XML-файла, как показано нижеПолучить XML-узел по значению атрибута и десериализации этот узел
Формат 1:
<Template Type="Print">
<PrintWidth>7</PrintWidth>
<PrintHeight>5</PrintHeight>
</Template>
Формат 2:
<Templates>
<Template Type="Print">
<PrintWidth>7</PrintWidth>
<PrintHeight>5</PrintHeight>
</Template>
<Template Type="Print">
<PrintWidth>7</PrintWidth>
<PrintHeight>5</PrintHeight>
</Template>
</Templates>
Я создал Класс сопоставления для формата 1, как указано ниже:
public class Template
{
private double _printWidth;
private double _printHeight;
/// <summary>
/// Print width in inches
/// </summary>
[System.Xml.Serialization.XmlAttributeAttribute()]
public double PrintWidth {
get {
return this._printWidth;
}
set {
this._printWidth = value;
this.RaisePropertyChanged("PrintWidth");
}
}
[System.Xml.Serialization.XmlAttributeAttribute()]
public double PrintHeight {
get {
return this._printHeight;
}
set {
this._printHeight = value;
this.RaisePropertyChanged("PrintHeight");
}
}
}
Я хотел запросить только один узел XML в формате 2, который имеет Type="Print"
в класс Template
. Есть ли общий способ, с помощью которого я могу десериализовать оба файла XML (Foarmat 1 и один узел формата 2) до класса Template
?