[C] 在XMLDocument中添加XSL引用
我正在用我的C代码创建一个XML文档。我需要在XML文档中添加XSL引用。我的代码是:[C] 在XMLDocument中添加XSL引用,xml,xslt,c#-2.0,Xml,Xslt,C# 2.0,我正在用我的C代码创建一个XML文档。我需要在XML文档中添加XSL引用。我的代码是: XmlDocument xDoc = new XmlDocument(); if (!File.Exists(fileName)) { XmlDeclaration dec = xDoc.CreateXmlDeclaration("1.0", "UTF-8", null); xDoc.AppendChild(dec); **[Need to add code to add the XS
XmlDocument xDoc = new XmlDocument();
if (!File.Exists(fileName))
{
XmlDeclaration dec = xDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
xDoc.AppendChild(dec);
**[Need to add code to add the XSL reference e.g. - <?xml-stylesheet type="text/xsl" href="style.xsl"?> ] **
XmlElement root = xDoc.CreateElement("Errors");
xDoc.AppendChild(root);
}
else
{
xDoc.Load(fileName);
}
XmlElement errorLogStart = xDoc.CreateElement("ErrorLog");
XmlElement errorText = xDoc.CreateElement("Message");
errorText.InnerText = message;
errorLogStart.AppendChild(errorText);
xDoc.DocumentElement.InsertBefore(errorLogStart, xDoc.DocumentElement.FirstChild);
FileStream fileXml = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
xDoc.Save(fileXml);
我需要在XML文档中添加以下行。我怎么做?通过谷歌找不到太多信息。试试这个:
var xDoc = new XmlDocument();
var pi = xDoc.CreateProcessingInstruction(
"xml-stylesheet",
"type=\"text/xsl\" href=\"cdcatalog.xsl\"");
xDoc.AppendChild(pi);
试试这个:
var xDoc = new XmlDocument();
var pi = xDoc.CreateProcessingInstruction(
"xml-stylesheet",
"type=\"text/xsl\" href=\"cdcatalog.xsl\"");
xDoc.AppendChild(pi);