我有一个Xml文件
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type='text/xsl' href='a.xsl'?>
现在我想在C#程序中把a.xsl 改成 b.xsl 
要怎么做啊?

解决方案 »

  1.   

    XmlDocument _dom=new XmlDocument();
    _dom.LoadXml("<?xml version='1.0' encoding='gb2312'?><?xml-stylesheet type='text/xsl' href='test.xsl'?><root/>");
    XmlNode _node=_dom.ChildNodes[1];
    XmlProcessingInstruction _newProc=_dom.CreateProcessingInstruction("xml-stylesheet"," type='text/xsl' href='xxsxx.xsl'");
    _dom.ReplaceChild(_newProc,_node);Response.Write(_dom.OuterXml);
      

  2.   

    多谢指教 
    还有个问题
    XmlNode _node=_dom.ChildNodes[1];
    万一那个节点的位置不是在  1  怎么办呢?
    如何在程序中判断这个位置是多少
    有劳了
      

  3.   

    这次是找到思归老大写的一个:try         XmlDocument xmldoc = new XmlDocument();
    xmldoc.Load("data.xml");

    XmlNode node = xmldoc.SelectSingleNode("//processing-instruction('xml-stylesheet')");
    if (node != null)
    {
    node.Value = "href='xxxdata.xsl' type='text/xsl'";
    }