什么是pcated替代非德$ P $到的XmlDataDocument和的XslTransform?pcated、XmlDataDocument、XslTransform

2023-09-07 14:29:26 作者:* 盖 世 英 雄 〆、

我改变一些旧的code,以尽量消除警告。 的XmlDataDocument 的XslTransform 都产生警告,他们是过时的。在的情况下,的XslTransform 建议更换 XslCompiledTransform ,但没有更换,建议在的XmlDataDocument

如何更改此code,以消除在.NET 4警告:

  VAR xmlDoc中=新System.Xml.XmlDataDocument(myDataSet);
VAR xslTran =新System.Xml.Xsl.XslTransform();
xslTran.Load(新的XmlTextReader(myMemoryStream),NULL,NULL);
变种SW =新System.IO.StringWriter();
xslTran.Transform(xmlDoc中,空,申银万国,NULL);
 

解决方案

 的XDocument DOC =新的XDocument();
使用(的XmlWriter XW = doc.CreateWriter())
{
  myDataSet.WriteXml(XW);
  xw.Close();
}

XslCompiledTransform PROC =新XslCompiledTransform();
使用(XmlReader的XR = XmlReader.Create(myMemoryStream))
{
  proc.Load(XR);
}

字符串结果;

使用(StringWriter的SW =新的StringWriter())
{
  proc.Transform(doc.CreateNavigator(),空,SW); //需要使用System.Xml.XPath;
  结果= sw.ToString();
}
 

应该做的,我认为。当然,我只用了的MemoryStream加载样式表和StringWriter的发送转换结果为你code代码片段中使用的那些。通常有其他输入源或输出目的地,如文件或流或TextReader的。

电脑频繁蓝屏而且出现 collecting data for crash dump 怎么办

I am modifying some legacy code to try to eliminate warnings. XmlDataDocument and XslTransform both generate warnings that they are obsolete. In the case of XslTransform the suggested replacement is XslCompiledTransform, but no replacement is suggested for XmlDataDocument.

How can I change this code to eliminate warnings in .NET 4:

var xmlDoc = new System.Xml.XmlDataDocument(myDataSet);
var xslTran = new System.Xml.Xsl.XslTransform();
xslTran.Load(new XmlTextReader(myMemoryStream), null, null);
var sw = new System.IO.StringWriter();
xslTran.Transform(xmlDoc, null, sw, null);

解决方案

XDocument doc = new XDocument();
using (XmlWriter xw = doc.CreateWriter())
{
  myDataSet.WriteXml(xw);
  xw.Close();
}

XslCompiledTransform proc = new XslCompiledTransform();
using (XmlReader xr = XmlReader.Create(myMemoryStream))
{
  proc.Load(xr);
}

string result;

using (StringWriter sw = new StringWriter())
{
  proc.Transform(doc.CreateNavigator(), null, sw);  // needs using System.Xml.XPath;
  result = sw.ToString();
}

should do I think. Of course I have only used that MemoryStream for loading the stylesheet and the StringWriter for sending the transformation result to as you code snippet used those. Usually there are other input sources or output destinations like files, or streams or Textreader.