How to add processing instruction exactly after xml declaration?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri Im trying to add <?xml-stylesheet type="text/xsl My test file.xsl"?> declaration exactly after the xml declaration
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri <?xml version="1.0" encoding="utf-8"?>
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri the following is the code im using but its adding processing instruction at the end of the file instead of after xml declaration. I want it exactly after the xml declaration,
<span style="font-size:small <span style="font-family:Calibri so the xml file should start like this<span style="font-family:Calibri; font-size:small
<span style="font-family:Calibri; font-size:small
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <?<span style="color:#A31515; xml-stylesheet<span style="color:Gray; type="text/xsl My test file.xsl"<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; Person<span style="color:Blue; >
.
. The actual xml data goes here
.
<span style="color:Blue; </<span style="color:#A31515; Person<span style="color:Blue; >




[/code]
<p style="margin:0in 0in 0pt
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private <span style="color:Blue; void AddXslRefernce(Stream stream)
{
XmlDocument xDoc = <span style="color:Blue; new XmlDocument();
xDoc.Load(stream);
XmlProcessingInstruction pi =
xDoc.CreateProcessingInstruction(<span style="color:#A31515; "xml-stylesheet", <span style="color:#A31515; "type="text/xsl My test file.xsl"");
xDoc.AppendChild(pi);

}


[/code]


<p style="margin:0in 0in 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0in 0in 0pt <span style="font-size:small <span style="font-family:Calibri the other question i have, after adding new ProcessingInstruction will the underneath Stream object have the updated XML???

View the full article
 
Back
Top