>You mention serializing in this thread - is this XML originally produced from objects using the XMLSerializer?
>If so then I think you can just add the PI during the initial serialization (although I don't know it that is an option for you). Something like:
class Program
> {
> static void Main(string[] args)
> {
>
> Thing t = new Thing();
> t.Name = "Fred";
> t.Age = 99;
>
>
> XmlSerializer s = new XmlSerializer(typeof(Thing));
> using (StreamWriter sw = new StreamWriter("test.xml"))
> {
> using (XmlTextWriter w = new XmlTextWriter(sw))
> {
> w.WriteProcessingInstruction("xml","version=\"1.0\" encoding=\"utf-8\"");
> w.WriteProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"someref.xslt\"");
> s.Serialize(w, t);
> }
> }
>
>
> }
> }
>
> [Serializable()]
> public class Thing
> {
> public string Name { get; set; }
> public int Age { get; set; }
> }
(C# I'm afraid but pretty language agnostic....)
Thanks, this is simpler but considering we negotiate with a file. In my case, I have everything constructed in memory. And, when I call this method, the XML is in the middle of its construction. I use the stream and the XmlTextWriter as mentioned in the CreateXMLInMemory() method earlier. I do not know if there would be a way to have something like that but adapted with in memory context. Otherwise, I will just wait until the XML is finished constructed, get the cXML property and simply parse it manually.