protected void ThisDocument_BeforeSave(Word.Document document, ref bool b, ref bool q) { DialogResult result = MessageBox.Show("Do you want to save as XML also?", "Tech Head Brothers - Article", MessageBoxButtons.YesNo); THBDocument thbdocument = new THBDocument(ThisDocument); if ( result == DialogResult.Yes) { thbdocument.Save(); result = MessageBox.Show("Do you want to preview the article?", "Tech Head Brothers - Article", MessageBoxButtons.YesNo); if ( result == DialogResult.Yes) { thbdocument.Preview(); } }
<?xml version="1.0" encoding="iso-8859-1" ?> <?xml-stylesheet type='text/xsl' href='Preview_Content20.xsl' ?>
public void Preview() { Save(XmlPreviewPath, new LocalTransformer());
public interface ITransformer { string Transform(string input, string path); } public class BaseTransformer : ITransformer { public virtual string Transform(string input, string path) { StringBuilder sb = new StringBuilder(input); //TODO: Add all these settings to the application config file sb = sb.Replace("'","'"); sb = sb.Replace("","'"); sb = sb.Replace("","'"); sb = sb.Replace("","..."); sb = sb.Replace("","oe"); return sb.ToString(); } }
/// <summary> /// Transform the xml generated by Word 2003 to the format /// </summary> public class LocalTransformer : BaseTransformer { public override string Transform(string input, string path) { input = base.Transform(input, path); // Setup Chain of Responsibility Handler h1 = new CodeHandler(); Handler h2 = new ImgLocalHandler(); Handler h3 = new XmlHandler(); Handler h4 = new ArticleHandler(); Handler h5 = new LinkHandler(); h1.Path = h2.Path = h3.Path = h4.Path = h5.Path = path; h1.SetSuccessor(h2); h2.SetSuccessor(h3); h3.SetSuccessor(h4); h4.SetSuccessor(h5); return h1.HandleRequest(input); } }
class XmlHandler : Handler { override public string HandleRequest(string input) { Regex regex = new Regex(@"<?xml(?<attribut>.*?)\?>", options); MatchEvaluator evaluator = new MatchEvaluator(Replace); string output = regex.Replace(input, evaluator); if( successor != null ) output = successor.HandleRequest(output); return output; } override protected string Replace(Match m) { return "xml version=\"1.0\" encoding=\"iso-8859-1\" ?><?xml-stylesheet type='text/xsl' href='Preview_Content20.xsl' ?>"; } }
<?xml version="1.0" encoding="ISO-8859-1" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes" /> <xsl:template match="article"> <HTML> <HEAD> <title> Tech Head Brothers </title> </HEAD> <body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="0" marginheight="0" marginwidth="0"> <table cellspacing="0" cellpadding="0" border="0" width="1024" align="center"> <tr valign="top"> <td align="left"> <table cellspacing="1" cellpadding="1" border="0" width="100%" class="articleDescription"> <tr valign="top"> <td align="center" valign="center"> </td> <td align="left"> <b> <xsl:value-of select='title' /> </b> par <xsl:choose> <xsl:when test="string-length(author/email)=0"> <xsl:value-of select='author/name' /> </xsl:when> <xsl:otherwise> <a target="_self" href='mailto:{author/email}'> <xsl:value-of select='author/name' /> </a> </xsl:otherwise> </xsl:choose> <br /> <br /> <xsl:value-of select='description' />. </td> </tr> </table> <xsl:apply-templates select="content" /> </td> </tr> </table> </body> </HTML> </xsl:template> ... </xsl:stylesheet>
public void Preview() { Save(XmlPreviewPath, new LocalTransformer()); //Preview Process proc = new Process(); //On spcifie les valeurs utiliser pour dmarrer le processus ProcessStartInfo processStarInf = new ProcessStartInfo(); //on dsire lancer Internet Explorer processStarInf.FileName = "iexplore.exe"; //on lui passe en argument une url processStarInf.Arguments = "file://" + XmlPreviewPath; //spcifie la taille de la nouvelle fenetre au dmarrage du processus processStarInf.WindowStyle = ProcessWindowStyle.Maximized; // Dmarre le processus proc = Process.Start(processStarInf); }