示例#1
0
        /// <summary>
        /// Appends the new snippet.
        /// </summary>
        /// <returns>Index position of added snippet</returns>
        public int AppendNewSnippet()
        {
            XmlElement newSnippet = SnippetXmlDoc.CreateElement("CodeSnippet", nsMgr.LookupNamespace("ns1"));

            newSnippet.SetAttribute("Format", "1.0.0");
            newSnippet.AppendChild(SnippetXmlDoc.CreateElement("Header", nsMgr.LookupNamespace("ns1")));
            newSnippet.AppendChild(SnippetXmlDoc.CreateElement("Snippet", nsMgr.LookupNamespace("ns1")));

            XmlNode codeSnippetsNode = SnippetXmlDoc.SelectSingleNode("//ns1:CodeSnippets", nsMgr);
            XmlNode newNode          = codeSnippetsNode.AppendChild(newSnippet);

            Snippets.Add(new Snippet(newNode, nsMgr));
            return(Snippets.Count - 1);
        }
示例#2
0
        private void LoadFromDoc()
        {
            nsMgr = new XmlNamespaceManager(SnippetXmlDoc.NameTable);
            nsMgr.AddNamespace("ns1", "http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet");


            // If the document doesn't already have a declaration, add it
            if (SnippetXmlDoc.FirstChild.NodeType != XmlNodeType.XmlDeclaration)
            {
                XmlDeclaration decl = SnippetXmlDoc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
                SnippetXmlDoc.InsertBefore(decl, SnippetXmlDoc.DocumentElement);
            }

            // Handle the current ambiguity as to whether
            // the root node "CodeSnippets" is optional or not
            if (SnippetXmlDoc.DocumentElement.Name == "CodeSnippet")
            {
                // Since the root element was CodeSnippet, we should
                // proceed with the assumption that this file only
                // defines one snippet.
                Snippets.Add(new Snippet(SnippetXmlDoc.DocumentElement, nsMgr));
                return;
            }
            else
            {
                foreach (XmlNode node in SnippetXmlDoc.DocumentElement.SelectNodes("//ns1:CodeSnippet", nsMgr))
                {
                    Snippets.Add(new Snippet(node, nsMgr));
                }
            }
            if (schemas.Count > 0)
            {
                SnippetXmlDoc.Schemas = schemas;
                ValidationEventHandler schemaValidator = SchemaValidationEventHandler;
                SnippetXmlDoc.Validate(schemaValidator);
            }
        }
示例#3
0
 public void SaveAs(string fileName)
 {
     SnippetXmlDoc.Save(fileName);
     FileName = fileName;
 }
示例#4
0
 public void Save()
 {
     SnippetXmlDoc.Save(FileName);
 }