帮助获取各种级别xml中的值。从xml中获取值(4个级别)
这是XML:
<widgets>
<id>95</id>
<widget type="1" name="accventas" caption="Ofertas ventas" flags="4">
<service name="pm_venofer_total00001" caption="Pendientes de aceptar" desc="" type="3" detail="1">
<xvalue>20</xvalue>
<xcolor>1</xcolor>
</service>
</widget>
<widget type="3" name="today_state" caption="Estado de ventas" flags="4">
<service name="pd_today_orders00001" caption="Pedidos" desc="Nº pedidos del día" type="3" detail="1">
<xvalue>0</xvalue>
<xcolor>2</xcolor>
<xalert>No se está vendiendo nada</xalert>
</service>
<service name="pd_today_sales00001" caption="Importe" desc="Importe ventas del día" type="3" detail="1">
<xvalue>0,00</xvalue>
<xcolor>2</xcolor>
<xalert>No estamos recaudando nada</xalert>
</service>
</widget>
</widgets>
加载的XML,并准备尝试过,但我不能得到你所需要
的各个领域,我需要:
- ID ,
- 控件的标题属性,
- 每个控件的服务,
- 服务的caption属性,
- x值,
- xcolor和xalert,
- 每个服务
我可以得到所有的部件,像这样的:(我认为两种:Employees
和Employee
)
[XmlRoot("widgets")]
public class Employees
{
[XmlElement("widget")]
public ObservableCollection <Employee> Coleccion { get; set; }
}
public class Employee
{
[XmlAttribute("caption")]
public string nombreWidget { get; set; }
}
但不喜欢把自己内部的每个插件各自的服务(服务属性),和这些x值,xcolor和xalert内
您是否考虑过使用Linq转XML或XPATH?还是你必须使用'XmlSerializer'? – mipe34
我正在使用LINQ to XML,因为不幸的是XPath目前不支持,并且LINQ没有访问所有标签 – user1909412