我曾经的代码在C#以下位到一个XML文件转换为另一种使用XSLT/XSLT总是给我UTF-16用斜杠
string xmlInput = @"<?xml version='1.0' encoding='UTF-8'?><catalog><cd><title> Empire Burlesque </title ><artist> Bob Dylan </artist><country> USA </country><company> Columbia </company><price> 10.90 </price><year> 1985 </year></cd></catalog>";
///////////////////////////////////////////////////////////////
string xmlOutput = String.Empty;
using (StringReader sri = new StringReader(xmlInput))
{
using (XmlReader xri = XmlReader.Create(sri))
{
XslCompiledTransform xslt = new XslCompiledTransform();
//xslt.Load(xrt);
xslt.Load(@"XSLT/slide2.xslt");
using (StringWriter sw = new StringWriter())
using (XmlWriter xwo = XmlWriter.Create(sw, new XmlWriterSettings { Encoding = Encoding.UTF8 }))
{
xslt.Transform(xri, xwo);
xmlOutput = sw.ToString();
}
}
}
xmlOutput给我"<?xml version=\"1.0\" encoding=\"utf-16\"?><root> Empire Burlesque </root>"
我怎样才能获得UTF-8并没有斜杠?
实际文件中没有斜杠。你只是看着Visual Studio显示结果的方式。 – jdweng
.NET字符串是UTF-16,因此如果输出XML声明,您将获得该编码。为什么你需要一个字符串作为XSLT结果,但希望它声明UTF-8?你以后是否将该字符串写入文件?至于斜杠,这是Visual Studio在调试器中为字符串值显示的内容,不是? –
我的XSLT: <?xml version ='1.0'encoding ='UTF-8'?> 的 的 XSL:模板> XSL :样式表> –
iconiconoclast