using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
namespace WebServiceStringtoXML
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
XmlDocument xmldoc;
XmlNode xmlnode;
XmlElement xmlelemRoot;
XmlElement xmlelemUNIT;
XmlElement xmlelemLANGUAGE;
XmlElement xmlelemFORMAT;
XmlElement xmlelemTEXT;
XmlElement xmlelemBREAK;
XmlElement xmlelemDIGITS;
XmlElement xmlelenNEXT;
XmlElement xmlelenPROMPT;
XmlElement xmlelenWRONGPROMPT;
XmlElement xmlelenWRONGNEXT;
XmlElement xmlelenREPEAT;
XmlElement xmlelenSILENCE;
XmlElement xmlelenSILENCENEXT;
XmlElement xmlelenCASES;
XmlElement xmlelenCASE;
XmlText xmltext;
[WebMethod]
public Boolean Toxml(string strContent,string Number,int count)
{
if (strContent.Trim () =="")
{
return false ;
}
xmldoc = new XmlDocument();
//string str = "I lOVE YOU ";
//加入XML的声明段落
xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
//string strXml = "<?xml version='1.0' encoding='gb2312'?>";
//xmldoc.LoadXml(strXml);
xmldoc.AppendChild(xmlnode);
//加入一个根元素
xmlelemRoot = xmldoc.CreateElement("IVR");
xmlelemRoot.SetAttribute ("ver","1.0");
xmldoc.AppendChild(xmlelemRoot);
//入口节点
xmlelemUNIT = xmldoc.CreateElement("", "UNIT", "");
xmlelemUNIT.SetAttribute("name", "Start");
xmlelemUNIT.SetAttribute("type", "ENTRANCE");
xmlelenNEXT = xmldoc.CreateElement("NEXT");
xmlelenNEXT.InnerText = "TransferExt";
xmlelemUNIT.AppendChild(xmlelenNEXT);
xmlelemRoot.AppendChild(xmlelemUNIT);
//TTS节点
xmlelemUNIT = xmldoc.CreateElement("", "UNIT", "");
//xmltext = xmldoc.CreateTextNode ( "Root Text" ) ;
xmlelemUNIT.SetAttribute("name", "TransferExt");
xmlelemUNIT.SetAttribute("type", "TTS2");
//xmlelem.AppendChild ( xmltext ) ;
xmlelemRoot.AppendChild(xmlelemUNIT);
//加入另外一个元素LANGUAGE
// xmlelem2 = xmldoc.CreateElement("LANGUAGE");
xmlelemLANGUAGE = xmldoc.CreateElement("", "LANGUAGE", "");
xmlelemLANGUAGE.InnerText ="0";
//xmlelemLANGUAGE.AppendChild(xmltext);
xmlelemUNIT.AppendChild(xmlelemLANGUAGE);
//加入另外一个元素FORMAT
xmlelemFORMAT = xmldoc.CreateElement("", "FORMAT", "");
xmlelemFORMAT.InnerText = "0";
xmlelemUNIT.AppendChild(xmlelemFORMAT);
//加入另外一个元素TEXT
xmlelemTEXT = xmldoc.CreateElement("TEXT");
xmlelemTEXT.InnerText = strContent.ToString();
xmlelemUNIT.AppendChild(xmlelemTEXT);
//加入另外一个元素BREAK
xmlelemBREAK = xmldoc.CreateElement("BREAK");
xmlelemBREAK.InnerText = "false";
xmlelemUNIT.AppendChild(xmlelemBREAK);
//加入另外一个元素DIGITS
xmlelemDIGITS = xmldoc.CreateElement("DIGITS");
xmlelemDIGITS.InnerText = "1234567890*#";
xmlelemUNIT.AppendChild(xmlelemDIGITS);
//加入另外一个元素NEXT
xmlelenNEXT = xmldoc.CreateElement("NEXT");
xmlelenNEXT.InnerText = "playquestion";
xmlelemUNIT.AppendChild(xmlelenNEXT);
xmlelemUNIT = xmldoc.CreateElement("", "UNIT", "");
xmlelemUNIT.SetAttribute("name", "playquestion");
xmlelemUNIT.SetAttribute("type", "MENU");
xmlelenPROMPT = xmldoc.CreateElement("PROMPT");
xmlelenPROMPT.InnerText = @"wave\re.wav";
xmlelemUNIT.AppendChild(xmlelenPROMPT);
xmlelenWRONGPROMPT = xmldoc.CreateElement("WRONGPROMPT");
xmlelemUNIT.AppendChild(xmlelenWRONGPROMPT);
xmlelenWRONGNEXT = xmldoc.CreateElement("WRONGNEXT");
xmlelemUNIT.AppendChild(xmlelenWRONGNEXT);
xmlelenREPEAT = xmldoc.CreateElement("REPEAT");
xmlelenREPEAT.InnerText = "3";
xmlelemUNIT.AppendChild(xmlelenREPEAT);
xmlelenSILENCE = xmldoc.CreateElement("SILENCE");
xmlelenSILENCE.InnerText = "50";
xmlelemUNIT.AppendChild(xmlelenSILENCE);
xmlelenSILENCENEXT = xmldoc.CreateElement("SILENCENEXT");
xmlelenSILENCENEXT.InnerText = "playquestion";
xmlelemUNIT.AppendChild(xmlelenSILENCENEXT);
xmlelenCASES = xmldoc.CreateElement("CASES");
xmlelenCASE = xmldoc.CreateElement("CASE");
xmlelenCASE.SetAttribute("DTMF", "0");
xmlelenCASE.InnerText = "TransferExt";
xmlelenCASES.AppendChild(xmlelenCASE);
xmlelemUNIT.AppendChild(xmlelenCASES);
xmlelemRoot.AppendChild(xmlelemUNIT);
//保存创建好的XML文档
try
{
xmldoc.Save(@"d:\data\"+Number+"-"+count +".xml");
return true;
}
catch (Exception e)
{
//显示错误信息
return false;
}
}
}
}