【发布时间】:2014-04-02 18:22:55
【问题描述】:
我收到此代码的根元素缺失异常。该代码正在尝试再次读取相同的 xml 文件。这个位置大约有 150 个 xml 文件。有人可以帮忙吗?
foreach (string file in Directory.EnumerateFiles("C:\\Path\\", "*.xml"))
{
string FileName = Path.GetFileNameWithoutExtension(file);
XPathDocument myXPathDoc = new XPathDocument(file);
XslCompiledTransform myXslTrans = new XslCompiledTransform();
/* loading XSLT */
myXslTrans.Load("ABCXSLT.xsl");
/* creating Output Stream */
XmlTextWriter myWriter = new XmlTextWriter(FileName + "_cleaned.xml", null);
/* XML transformation */
myXslTrans.Transform(myXPathDoc, null, myWriter);
myWriter.Close();
}
【问题讨论】:
-
您真的需要为每个 xml 文件重新加载 .xsl 文件吗?也许问题出在 xsl 文件中,因为它在循环的每次迭代中都会重新加载。
-
你能发布 XML 吗?
-
哪个statemenr给出了这个错误?
-
感谢你们的 cmets 伙计们!我从@deanosaur 那里得到了答案!