如何将容器标记添加到以下xml Web服务

时间:2012-07-18 06:00:31

标签: c# xml web-services

我正在创建一个xml架构

<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://tempuri.org/">
<Inventories>
<ID>           </ID>
<Category>     </Category>
<Identity>     </Identity>
<Name>         </Name>
</Inventories>
</string>

<?xml version="1.0" encoding="UTF-8"?> <string xmlns="http://tempuri.org/"> <Inventories> <ID> </ID> <Category> </Category> <Identity> </Identity> <Name> </Name> </Inventories> </string>

使用以下代码

但我们需要将xml设为

resultList = remoteWeb.Lists.GetByTitle("Server");
context.Load(resultList);
context.ExecuteQuery();
items = resultList.GetItems(new CamlQuery());
context.Load(items);
context.ExecuteQuery();
foreach (ListItem item in items)
{
    rootNode.AppendChild(doc.CreateElement("ID")).InnerText = "pcat:401820";
    rootNode.AppendChild(doc.CreateElement("Category")).InnerText = "Infrastructure.Server";
    rootNode.AppendChild(doc.CreateElement("Identity")).InnerText = Convert.ToString(item["ID"]);
    rootNode.AppendChild(doc.CreateElement("Name")).InnerText = Convert.ToString(item["Server_Name"]) + " >> " + Convert.ToString(item["Computer_Name"]) + " >> " + Convert.ToString(item["IP"]);
}

但没有弄清楚如何在

下添加容器节点

所有帮助将不胜感激,并提前感谢

1 个答案:

答案 0 :(得分:0)

List<Inventory> items = new List<Inventory>();
items.Add(new Inventory() { ID = "id1", Category = "c1", Identity = "i1", Name = "n1" });
items.Add(new Inventory() { ID = "id2", Category = "c2", Identity = "i2", Name = "n2" });

XmlSerializer xml = new XmlSerializer(typeof(List<Inventory>),new XmlRootAttribute("Inventories"));
xml.Serialize(stream, items);

-

public class Inventory
{
    public string ID;
    public string Category;
    public string Identity;
    public string Name;
}