string process ="type='text/xsl'"+" href="+"'moban001.xsl'";
xw.WriteProcessingInstruction("xml-stylesheet",process);

解决方案 »

  1.   

    string xml = "<?xml version=\"1.0\" encoding=\"gb2312\"?><Text><Textxml> <Name> 知道天高地厚</Name></Textxml></Text> ";
    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
    doc.LoadXml(xml);
    Response.Clear();
    Response.Write (Server.HtmlEncode(doc.OuterXml));
    Response.Write ("<hr>");
    System.Xml.XmlProcessingInstruction newPI;
    String PItext = "type='text/xsl' href='Text.xsl'";
    newPI = doc.CreateProcessingInstruction("xml-stylesheet", PItext);
    doc.InsertBefore(newPI,doc.DocumentElement);
    System.Xml.XmlNode nod = doc.SelectSingleNode("//Textxml");
    System.Xml.XmlNode newNode = doc.CreateNode(System.Xml.XmlNodeType.Element,"Content","");
    System.Xml.XmlCDataSection CData;
    CData = doc.CreateCDataSection(" 真是不知高地厚 的东西我的心情好 ");
    newNode.AppendChild(CData);
    nod.AppendChild(newNode);
    Response.Write (Server.HtmlEncode(doc.OuterXml));
      

  2.   

    上面的xw是XmlTextWriter的一个实例
    XmlTextWriter xw=new XmlTextWriter(dir,null);
      

  3.   

    XmlTextWriter xw=new XmlTextWriter(dir,null);
    xw.WriteStartDocument();
    // 写入处理指令
    string process ="type='text/xsl'"+" href="+"'moban001.xsl'";
    xw.WriteProcessingInstruction("xml-stylesheet",process);明白了吧