Example #1
0
 public void RemoveReference(Reference reference)
 {
     if (reference is BookReference)
     {
         BookReference bookReference  = (BookReference)reference;
         XmlNode       referencesNode = xml.SelectSingleNode("/documentation/references");
         foreach (XmlNode node in referencesNode.ChildNodes)
         {
             if (node.Name.Equals("bookReference") && node["name"].InnerText.Equals(bookReference.Name))
             {
                 referencesNode.RemoveChild(node);
             }
         }
     }
     else if (reference is LinkReference)
     {
         LinkReference linkReference  = (LinkReference)reference;
         XmlNode       referencesNode = xml.SelectSingleNode("/documentation/references");
         foreach (XmlNode node in referencesNode.ChildNodes)
         {
             if (node.Name.Equals("linkReference") && node["caption"].InnerText.Equals(linkReference.Caption))
             {
                 referencesNode.RemoveChild(node);
             }
         }
     }
 }
Example #2
0
        public void AddReferences(List <Reference> references)
        {
            XmlNode referencesNode = xml.SelectSingleNode("/documentation/references");

            if (referencesNode == null)
            {
                referencesNode = xml.CreateNode(XmlNodeType.Element, "references", null);
                XmlNode documentationNode = xml.SelectSingleNode("/documentation");
                documentationNode.AppendChild(referencesNode);
            }
            else
            {
                referencesNode.RemoveAll();
            }

            foreach (Reference reference in references)
            {
                if (reference is LinkReference)
                {
                    LinkReference linkReference        = (LinkReference)reference;
                    XmlNode       linkReferenceNode    = xml.CreateNode(XmlNodeType.Element, "linkReference", null);
                    XmlNode       linkNode             = xml.CreateNode(XmlNodeType.Element, "link", null);
                    XmlAttribute  urlAttribute         = xml.CreateAttribute("url", null);
                    XmlAttribute  linkNodeAttribute    = xml.CreateAttribute("lang");
                    XmlNode       captionNode          = xml.CreateNode(XmlNodeType.Element, "caption", null);
                    XmlAttribute  captionNodeAttribute = xml.CreateAttribute("lang");
                    urlAttribute.Value = ((LinkReference)reference).Link;
                    linkNode.Attributes.Append(urlAttribute);
                    linkNodeAttribute.Value = "en";
                    linkNode.Attributes.Append(linkNodeAttribute);
                    captionNode.InnerText      = linkReference.Caption;
                    captionNodeAttribute.Value = "en";
                    captionNode.Attributes.Append(captionNodeAttribute);
                    linkReferenceNode.AppendChild(linkNode);
                    linkReferenceNode.AppendChild(captionNode);
                    referencesNode.AppendChild(linkReferenceNode);
                }
                else if (reference is BookReference)
                {
                    BookReference bookReference          = (BookReference)reference;
                    XmlNode       bookReferenceNode      = xml.CreateNode(XmlNodeType.Element, "bookReference", null);
                    XmlNode       authorNode             = xml.CreateNode(XmlNodeType.Element, "author", null);
                    XmlAttribute  authorNodeAttribute    = xml.CreateAttribute("lang");
                    XmlNode       publisherNode          = xml.CreateNode(XmlNodeType.Element, "publisher", null);
                    XmlAttribute  publisherNodeAttribute = xml.CreateAttribute("lang");
                    XmlNode       nameNode          = xml.CreateNode(XmlNodeType.Element, "name", null);
                    XmlAttribute  nameNodeAttribute = xml.CreateAttribute("lang");
                    authorNode.InnerText      = bookReference.Author;
                    authorNodeAttribute.Value = "en";
                    authorNode.Attributes.Append(authorNodeAttribute);
                    publisherNode.InnerText      = bookReference.Publisher;
                    publisherNodeAttribute.Value = "en";
                    publisherNode.Attributes.Append(publisherNodeAttribute);
                    nameNode.InnerText      = bookReference.Name;
                    nameNodeAttribute.Value = "en";
                    nameNode.Attributes.Append(nameNodeAttribute);
                    bookReferenceNode.AppendChild(authorNode);
                    bookReferenceNode.AppendChild(publisherNode);
                    bookReferenceNode.AppendChild(nameNode);
                    referencesNode.AppendChild(bookReferenceNode);
                }
            }
        }