<?xml version=“1.0” encoding="GB2312" ?>
<Output>
<DataArea id="Info" text="返回信息">
  <Field id="Code" text="代码"> 134 </Field>
  <Field id="ErrMsg" text="错误信息"> 0110 </Field>
</DataArea>
</Output>
谢谢大家

解决方案 »

  1.   

    自己在server里拼个xml字符串,然后返回字符串呗。
    是否理解错误?
      

  2.   

    我知道了,你需要把“<”和“>”进行编码,不然部允许传。
      

  3.   

    返回字串肯定不行的,
    因为哪会在这段代码2边加上<string>内容</string>
    这个我会,但不是我想要的
      

  4.   

    没看懂.是不是要定义一个类,让其序列化XML时生成这种格式的XML?
      

  5.   

    你可以返回内容,然后生成一个那样格式的XML文件
      

  6.   

    一种是使用xmlDocument处理,
    另外使用字符串处理肯定是可以的。
    也许是你写的方法不对吧。
      /// <summary>
        /// 将传入的参数以xml格式返回
        /// </summary>
        /// <param name="StrValue"></param>
        /// <returns></returns>
        public static XmlDataDocument ReturnResultXml(string StrValue)
        {
            XmlDataDocument xmlDataResult = new XmlDataDocument();
            System.IO.Stream DataStream = new System.IO.MemoryStream();
            System.Xml.XmlTextWriter xmltextwriterData = new XmlTextWriter(DataStream, System.Text.Encoding.UTF8);
            xmltextwriterData.WriteStartDocument();
            xmltextwriterData.WriteStartElement("NewDataset");
            xmltextwriterData.WriteStartElement("ReturnResult");
            xmltextwriterData.WriteElementString("ReturnValue", StrValue);
            xmltextwriterData.WriteEndElement();
            xmltextwriterData.WriteEndElement();
            xmltextwriterData.Flush();
            DataStream.Position = 0;
            xmlDataResult.Load(DataStream);
            xmltextwriterData.Close();
            DataStream.Close();
            DataStream.Dispose();        return xmlDataResult;
        }
    }你可以以这为基础改动,UTF8换成gb2312就行。
      

  7.   


    public class Output
    {
    public Output(){ }
        [XmlElement(ElementName = "DataArea")]
        public DataArea dataArea;
    }
    public class DataArea
    {
        public DataArea() 
        {    }
        [XmlAttribute(AttributeName = "id")]
        public string id;
        [XmlAttribute(AttributeName = "text")]
        public string text;
        [XmlElement(ElementName = "Field")]
        public Field[] field;
    }
    public class Field
    {
        public Field() { }
        public Field(string id, string text, string html)
        {
            this.id = id;
            this.text = text;
            this.html = html;
        }
        [XmlAttribute(AttributeName="id")]
        public string id;
        [XmlAttribute(AttributeName = "text")]
        public string text;
        [XmlText]
        public string html;
    }
    //序列化后该类后返回
        [WebMethod]
        public string StreamXml() {
            DataArea da = new DataArea();
            da.id = "Info";
            da.text = "返回信息";
            da.field = new Field[] { new Field("Code", "代码", "134"), new Field("ErrMg", "错误信息", "0110") };
            Output op = new Output();
            op.dataArea = da;
            MemoryStream ms = new MemoryStream();
            XmlSerializer xml = new XmlSerializer(typeof(Output));
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            ns.Add("", "");
            xml.Serialize(ms, op, ns);
            return Encoding.UTF8.GetString(ms.ToArray());
        }
      

  8.   

    7楼的还是不对,返回来的,是这样<?xml version="1.0" encoding="utf-8" ?> 
      <string xmlns="http://57.1.57.1/"><?xml version="1.0"?> <Output> <DataArea id="Info" text="返回信息"> <Field id="Code" text="代码">134</Field> <Field id="ErrMg" text="错误信息">0110</Field> </DataArea> </Output></string> 
      

  9.   

    写个ToXML方法算了,这么麻烦呢
      

  10.   


    返回字串我会,可返回的2边会加上节点string我不想要这个懂不?
      

  11.   

    刚又测试了下,返回的是这个,没有你说的那个string,测试代码就是7楼提供的。<?xml version="1.0"?>
    <Output>
      <DataArea id="Info" text="返回信息">
        <Field id="Code" text="代码">134</Field>
        <Field id="ErrMg" text="错误信息">0110</Field>
      </DataArea>
    </Output>
      

  12.   

    你调用得WebService是用HTTP Get方式调用吧?
    WebService是会拼上SOAP头的
    如果你是要支持HTTP GET,直接写个aspx简单些