【发布时间】:2018-11-06 23:52:45
【问题描述】:
一个xml中各个级别的值的帮助。
这是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并准备试用,但我无法获取您需要的所有字段
我需要:
- 身份证,
- 小部件的标题属性,
- 每个小部件的服务,
- 服务的标题属性,
- 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; }
}
但不像进入每个小部件各自的服务(服务属性),以及在这些 xValue、xcolor 和 xalert 中
【问题讨论】:
-
您是否考虑过使用 Linq to XML 或 XPATH?还是必须使用
XmlSerializer? -
我正在使用 LINQ to XML,因为不幸的是 XPath 目前不支持,并且 linq 无法访问所有标签
标签: c# xml windows-phone-7 xml-serialization