Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Serializing XML with stylesheet
Message
De
21/08/2012 08:09:34
 
 
À
21/08/2012 04:02:31
Information générale
Forum:
ASP.NET
Catégorie:
XML
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01550792
Message ID:
01550877
Vues:
32
>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.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform