在XML文档中插入“xml-stylesheet” [英] Inserting 'xml-stylesheet' in XML document
问题描述
我从存储过程生成XMl文档。在创建之后我想插入以下元素以指向xsl文件。我如何在c#和/或存储过程中执行此操作
< xml-stylesheet type ='text / xsl'href ='x .xsl'?>
插入时看起来应该是这样的
Im generating an XMl document from a stored procedure. After its created i want to insert the below element to point to a xsl file. How do i do this in c# and/or stored procedure
<xml-stylesheet type ='text/xsl' href= 'x.xsl'?>
should look something like this when inserted
<br />
<?xml-stylesheet type ='text/xsl' href= 'x.xsl'?><br />
<catalog><br />
<cd><br />
<title>Empire Burlesque</title><br />
<artist>Bob Dylan</artist><br />
......<br />
推荐答案
// Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item><name>wrench</name></item>");
doc.PrependChild(doc.CreateProcessingInstruction(
"xml-stylesheet",
"type='text/xsl' href='book.xsl'"));
// Save the document to a file and auto-indent the output.
XmlTextWriter writer = new XmlTextWriter("data.xml",null);
writer.Formatting = Formatting.Indented;
doc.Save(writer);
请参阅: http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.createprocessinginstruction.asp [ ^ ]
刚刚清理过它有点... :-D
See:http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.createprocessinginstruction.asp[^]
Just cleaned it up a bit... :-D
Declare @Stylesheet as XML
Declare @xOutput as XML
DECLARE @XmlTable TABLE (
Element0 int,
Element1 nvarchar(100),
Element2 nvarchar(200))
INSERT INTO @XmlTable ([Element0] ,[Element1],[Element2])
VALUES (1,'bobo','Monkey')
-- Convert Table data into XML
SET @xOutput = (Select *From @XmlTable
FOR XML PATH( 'DataItem' ), ROOT('Root'))
select @xOutput
select @xOutput.query('
<?xml-stylesheet type="text/xsl" href="my-style-sheet.xsl" ?>,/.')
参见: http://blogs.msdn.com/b/mrorke/archive/2005/05/10/416033.asp [ ^ ]
createXML.WriteProcessingInstruction(xml-stylesheet,type ='text / xsl'href ='gss.xsl');
createXML.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='gss.xsl'");
这篇关于在XML文档中插入“xml-stylesheet”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!