XmlDocument是WebService方法的一种常用的返回类型。
public static XmlDocument CreateXmlDocument(string function,bool b) {
XmlDocument xmlDoc = new XmlDocument();
//建立Xml的定义声明
//XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "GB2312", null);
//xmlDoc.AppendChild(dec);
//创建根节点
XmlElement root = xmlDoc.CreateElement("Description");
xmlDoc.AppendChild(root);
XmlElement name = xmlDoc.CreateElement("Name");
name.InnerText = "";
XmlElement value = xmlDoc.CreateElement("Value");
value.InnerText = "";
switch (function) {
case "select"://查询操作
if (b)
{
name.InnerText = "0";
value.InnerText = "查询操作成功!";
}
else
{
name.InnerText = "1";
value.InnerText = "查询操作失败,请稍后再试!";
}
break;
}
root.AppendChild(name);
root.AppendChild(value);
return xmlDoc;
}
对应的XML样式如下:
<?xml version="1.0" encoding="utf-8" ?>
<Description>
<Name>1</Name>
<Value>查询操作失败,请稍后再试!</Value>
</Description>