我正在創建一個項目,其中我從c#創建了一個power point文檔。 由於某種原因,我的一個方法,我得到這個錯誤,它的所有非常好埠:狀態EndRootElement中的令牌啓動元素會導致無效的XML文檔
「狀態EndRootElement中的令牌StartElement將導致無效的XML文檔。
這裏是我的方法:
private static void slideLayout6XML()
{
FileStream slideLayout6Stream = new FileStream(slideLayout6, FileMode.Create, FileAccess.Write);
XmlWriter slideLayout6Writer = null;
try
{
XmlWriterSettings contentTypesSettings = new XmlWriterSettings();
contentTypesSettings.Indent = true;
slideLayout6Writer = XmlWriter.Create(slideLayout6Stream, contentTypesSettings);
slideLayout6Writer.WriteStartDocument(true);
slideLayout6Writer.WriteStartElement("p", "sldLayout");
slideLayout6Writer.WriteAttributeString("preserve", "1");
slideLayout6Writer.WriteAttributeString("type", "titleOnly");
slideLayout6Writer.WriteStartElement("p", "http://schemas.openxmlformats.org/drawingml/2006/main");
slideLayout6Writer.WriteStartElement("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
slideLayout6Writer.WriteStartElement("a", "http://schemas.openxmlformats.org/presentationml/2006/main");
slideLayout6Writer.WriteStartElement("p", "cSld");
slideLayout6Writer.WriteAttributeString("name", "Title Only");
slideLayout6Writer.WriteStartElement("p", "spTree");
slideLayout6Writer.WriteStartElement("p", "nvGrpSpPr");
slideLayout6Writer.WriteStartElement("p", "cNvpr");
slideLayout6Writer.WriteAttributeString("name", "");
slideLayout6Writer.WriteAttributeString("id", "1");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "cNvGrpSpPr");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "nvPr");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "grpSpPr");
slideLayout6Writer.WriteStartElement("a", "xfrm");
slideLayout6Writer.WriteStartElement("a", "off");
slideLayout6Writer.WriteAttributeString("y", "0");
slideLayout6Writer.WriteAttributeString("x", "0");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "ext");
slideLayout6Writer.WriteAttributeString("y", "0");
slideLayout6Writer.WriteAttributeString("x", "0");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "chOff");
slideLayout6Writer.WriteAttributeString("y", "0");
slideLayout6Writer.WriteAttributeString("x", "0");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "chExt");
slideLayout6Writer.WriteAttributeString("y", "0");
slideLayout6Writer.WriteAttributeString("x", "0");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "sp");
slideLayout6Writer.WriteStartElement("p", "nvSpPr");
slideLayout6Writer.WriteStartElement("p", "cNvPr");
slideLayout6Writer.WriteAttributeString("name", "Title 1");
slideLayout6Writer.WriteAttributeString("id", "2");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "cNvSpPr");
slideLayout6Writer.WriteStartElement("a", "spLocks");
slideLayout6Writer.WriteAttributeString("noGrp", "1");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "nvPr");
slideLayout6Writer.WriteStartElement("p", "ph");
slideLayout6Writer.WriteAttributeString("type", "title");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "txBody");
slideLayout6Writer.WriteStartElement("a", "bodyPr");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "lstStyle");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "p");
slideLayout6Writer.WriteStartElement("a", "r");
slideLayout6Writer.WriteStartElement("a", "rPr");
slideLayout6Writer.WriteAttributeString("lang", "en-US");
slideLayout6Writer.WriteAttributeString("smtClean", "0");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "t");
slideLayout6Writer.WriteRaw("Click to edit Master title style");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "endParaRPr");
slideLayout6Writer.WriteAttributeString("lang", "en-US");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "sp");
slideLayout6Writer.WriteStartElement("p", "nvSpPr");
slideLayout6Writer.WriteStartElement("p", "cNvPr");
slideLayout6Writer.WriteAttributeString("name", "Date Placeholder 2");
slideLayout6Writer.WriteAttributeString("id", "3");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "cNvSpPr");
slideLayout6Writer.WriteStartElement("a", "spLocks");
slideLayout6Writer.WriteAttributeString("noGrp", "1");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "nvPr");
slideLayout6Writer.WriteStartElement("p", "ph");
slideLayout6Writer.WriteAttributeString("type", "dt");
slideLayout6Writer.WriteAttributeString("idx", "10");
slideLayout6Writer.WriteAttributeString("sz", "half");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "txBody");
slideLayout6Writer.WriteStartElement("a", "bodyPr");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "lstStyle");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "p");
slideLayout6Writer.WriteStartElement("a", "fld");
slideLayout6Writer.WriteAttributeString("type", "datetime1");
slideLayout6Writer.WriteAttributeString("id", "{32E0D616-E0F4-45FD-A59D-58900C81D413}");
slideLayout6Writer.WriteStartElement("a", "rPr");
slideLayout6Writer.WriteAttributeString("lang", "en-US");
slideLayout6Writer.WriteAttributeString("smtClean", "0");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "t");
slideLayout6Writer.WriteRaw("5/17/2012");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "endParaRpR");
slideLayout6Writer.WriteAttributeString("lang", "en-US");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "sp");
slideLayout6Writer.WriteStartElement("p", "nvSpPr");
slideLayout6Writer.WriteStartElement("p", "cNvPr");
slideLayout6Writer.WriteAttributeString("name", "Footer Placeholder 3");
slideLayout6Writer.WriteAttributeString("id", "4");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "cNvSpPr");
slideLayout6Writer.WriteStartElement("a", "spLocks");
slideLayout6Writer.WriteAttributeString("noGrp", "1");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "nvPr");
slideLayout6Writer.WriteStartElement("p", "ph");
slideLayout6Writer.WriteAttributeString("type", "ftr");
slideLayout6Writer.WriteAttributeString("idx", "11");
slideLayout6Writer.WriteAttributeString("sz", "quarter");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "txBody");
slideLayout6Writer.WriteStartElement("a", "bodyPr");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "lstStyle");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "p");
slideLayout6Writer.WriteStartElement("a", "r");
slideLayout6Writer.WriteStartElement("a", "rPr");
slideLayout6Writer.WriteAttributeString("lang", "en-US");
slideLayout6Writer.WriteAttributeString("smtClean", "0");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "t");
slideLayout6Writer.WriteRaw("Crowded Igloo Business System");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "endParaRPr");
slideLayout6Writer.WriteAttributeString("lang", "en-US");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "sp");
slideLayout6Writer.WriteStartElement("p", "nvSpPr");
slideLayout6Writer.WriteStartElement("p", "cNvPr");
slideLayout6Writer.WriteAttributeString("name", "Slide Number Placeholder 4");
slideLayout6Writer.WriteAttributeString("id", "5");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "cNvSpPr");
slideLayout6Writer.WriteStartElement("a", "spLocks");
slideLayout6Writer.WriteAttributeString("noGrp", "1");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "nvPr");
slideLayout6Writer.WriteStartElement("p", "ph");
slideLayout6Writer.WriteAttributeString("type", "sldNum");
slideLayout6Writer.WriteAttributeString("idx", "12");
slideLayout6Writer.WriteAttributeString("sz", "quarter");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "txBody");
slideLayout6Writer.WriteStartElement("a", "bodyPr");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "lstStyle");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "p");
slideLayout6Writer.WriteStartElement("a", "fld");
slideLayout6Writer.WriteAttributeString("type", "slidenum");
slideLayout6Writer.WriteAttributeString("id", "{8B131516-2DB0-4AAA-89BA-2724DE07B6A2}");
slideLayout6Writer.WriteStartElement("a", "rPr");
slideLayout6Writer.WriteAttributeString("lang", "en-US");
slideLayout6Writer.WriteAttributeString("smtClean", "0");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "t");
slideLayout6Writer.WriteRaw("<#>");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("a", "endParaRPr");
slideLayout6Writer.WriteAttributeString("lang", "en-US");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "extLst");
slideLayout6Writer.WriteStartElement("p", "ext");
slideLayout6Writer.WriteAttributeString("uri", "{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}");
slideLayout6Writer.WriteStartElement("p14", "creationId", "http://schemas.microsoft.com/office/powerpoint/2010/main");
slideLayout6Writer.WriteAttributeString("val", "3805825225");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteStartElement("p", "clrMapOvr");
slideLayout6Writer.WriteStartElement("a", "masterClrMapping");
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndElement();
slideLayout6Writer.WriteEndDocument();
}
finally
{
if (slideLayout6Writer != null)
slideLayout6Writer.Flush();
slideLayout6Writer.Close();
}
}
對不起,大規模的方法,但這種方法,引發錯誤。 任何幫助將不勝感激謝謝。
謝謝你是對的。我關閉了一個需要啓動元素的元素。沒有屬性字符串的元素會變得非常混亂。 –
在我的情況下,在創建它時,意外地關閉了主父節點,從而防止嘗試寫入子節點。 – SushiGuy