BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

ReBlogger Contents

Previous posts in .NET XML, System.XML

 
 
Page 5048 of 18424

System.Xml.Linq and Office Open XML

Blogger : MSDN Blogs
All posts : All posts by MSDN Blogs
Category : .NET XML, System.XML
Blogged date : 2007 Dec 07

Starting to play with those. So just FYE, here is what I wrote yesterday:

// create the new document.xml package part

Uri documentUri = new Uri("/word/document.xml", UriKind.Relative);

PackagePart documentPart = package.CreatePart(documentUri, "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");

 

XNamespace r = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";

XNamespace wp = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";

XNamespace w = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

XNamespace dm = "http://schemas.openxmlformats.org/drawingml/2006/main";

XNamespace dp = "http://schemas.openxmlformats.org/drawingml/2006/picture";

 

var firstParagraph = new XElement(w.GetName("p"),

                                  new XElement(w.GetName("r"),

                                               new XElement(w.GetName("t"), "A paragraph")));

 

var secondParagraph = new XElement(w.GetName("p"),

                                   new XElement(w.GetName("r"),

                                                new XElement(w.GetName("t"),

                                                             new XAttribute(XNamespace.Xml + "space", "preserve"),

                                                             "A ")),

                                   new XElement(w.GetName("hyperlink"),

                                                new XAttribute(r.GetName("id"), "rId2"),

                                                new XElement(w.GetName("r"),

                                                             new XElement(w.GetName("rPr"),

                                                                          new XElement(w.GetName("color"),

                                                                                       new XAttribute(w.GetName("val"), "0000FF"),

                                                                                       new XAttribute(w.GetName("themeColor"), "hyperlink")),

                                                                          new XElement(w.GetName("u"),

                                                                                       new XAttribute(w.GetName("val"), "single"))),

                                                             new XElement(w.GetName("t"), "hyperlink"))));

 

var graphic = new XElement(dm.GetName("graphic"),

                           new XAttribute(XNamespace.Xmlns + "dm", dm.NamespaceName),

                           new XElement(dm.GetName("graphicData"),

                                        new XAttribute("uri", dp.NamespaceName),

                                        new XElement(dp.GetName("pic"),

                                        new XAttribute(XNamespace.Xmlns + "dp", dp.NamespaceName),

                                        new XElement(dp.GetName("nvPicPr"),

                                                     new XElement(dp.GetName("cNvPr"),

                                                                  new XAttribute("id", 0),

                                                                  new XAttribute("name", "openxmldeveloper.gif")),

                                                     new XElement(dp.GetName("cNvPicPr"))),

                                        new XElement(dp.GetName("blipFill"),

                                                     new XElement(dm.GetName("blip"),

                                                                  new XAttribute(r.GetName("embed"), "rId1")),

                                                     new XElement(dm.GetName("stretch"),

                                                                  new XElement(dm.GetName("fillRect")))),

                                        new XElement(dp.GetName("spPr"),

                                                     new XElement(dm.GetName("xfrm"),

                                                                  new XElement(dm.GetName("off"),