有人能把我引向正确的方向吗?
我想要做的是从 WebMethod 获取输出:
我从数据库中获取值;
1694.152344;1694.092285;1693.972168;1693.852051
2013-07-10 20:00:00;2013-07-10 19:00:00;2013-07-10 18:00:00;2013-07-10 17:00:00
我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<FieldsRoot xmlns="http://appserver.weevio.se/schema/SDKr1/Fields.xsd">
<Fields ok="true" nodeId="TEST_1.HW">
<Numeric value="1694.152344" datum="2013-07-10 20:00:00" status="16" />
<Numeric value="1694.092285" datum="2013-07-10 19:00:00" status="16" />
<Numeric value="1693.972168" datum="2013-07-10 18:00:00" status="16" />
<Numeric value="1693.852051" datum="2013-07-10 17:00:00" status="16" />
</Fields>
</FieldsRoot>
我的代码看起来像:
[WebMethod]
public XElement Sum2()
{
XNamespace defaultNamespace = XNamespace.Get("http://appserver.weevio.se/schema/SDKr1/Fields.xsd");
XElement test = new XElement(new XElement(defaultNamespace + "FieldsRoot"));
string value = "1694.152344;1694.092285;1693.972168;1693.852051";
string datum = "2013-07-10 20:00:00;2013-07-10 19:00:00;2013-07-10 18:00:00;2013-07-10 17:00:00";
string[] valueA = value.Split(';');
string[] datumA = datum.Split(';');
int d = 0;
foreach (var customer in valueA)
{
XElement xElement = new XElement(defaultNamespace + "Numeric",
new XAttribute("value", valueA[d]),
new XAttribute("datum", datumA[d]),
new XAttribute("status", 16)
);
test.Add(new XElement(defaultNamespace + "Fields", new XAttribute("ok", "true"), new XAttribute("nodeId", "TEST.HW"), xElement));
d = d + 1;
}
return test;
}
我得到的是:
<?xml version="1.0" encoding="utf-8"?>
<FieldsRoot xmlns="http://appserver.weevio.se/schema/SDKr1/Fields.xsd">
<Fields ok="true" nodeId="TEST.HW">
<Numeric value="1694.152344" datum="2013-07-10 20:00:00" status="16" />
</Fields>
<Fields ok="true" nodeId="TEST.HW">
<Numeric value="1694.092285" datum="2013-07-10 19:00:00" status="16" />
</Fields>
<Fields ok="true" nodeId="TEST.HW">
<Numeric value="1693.972168" datum="2013-07-10 18:00:00" status="16" />
</Fields>
<Fields ok="true" nodeId="TEST.HW">
<Numeric value="1693.852051" datum="2013-07-10 17:00:00" status="16" />
</Fields>
</FieldsRoot>