Example #1
0
        public static void NameOfAllTypes()
        {
            var xmlDocument = new XmlDocument();

            var element = xmlDocument.CreateElement("newElem");
            Assert.Equal("newElem", element.Name);

            var attribute = xmlDocument.CreateAttribute("newAttr");
            Assert.Equal("newAttr", attribute.Name);

            var text = xmlDocument.CreateTextNode("");
            Assert.Equal("#text", text.Name);

            var cdata = xmlDocument.CreateCDataSection("");
            Assert.Equal("#cdata-section", cdata.Name);

            var pi = xmlDocument.CreateProcessingInstruction("PI", "");
            Assert.Equal("PI", pi.Name);

            var comment = xmlDocument.CreateComment("some text");
            Assert.Equal("#comment", comment.Name);

            var fragment = xmlDocument.CreateDocumentFragment();
            Assert.Equal("#document-fragment", fragment.Name);
        }
Example #2
0
    // static ?!?!?!?
    public static XmlDocument Query(HttpRequest req, HttpSessionState session,Hashtable xsltParameters)
    {
        XmlDocument inputDoc = new XmlDocument();

        inputDoc.AppendChild(inputDoc.CreateProcessingInstruction("http-redirect", "/"+xsltParameters["base"].ToString()+"/static.cs?page=index"));

        return inputDoc;
    }
        public static void BasicCreate()
        {
            var xmlDocument = new XmlDocument();
            var newNode = xmlDocument.CreateProcessingInstruction("bar", "foo");

            Assert.Equal("<?bar foo?>", newNode.OuterXml);
            Assert.Equal(XmlNodeType.ProcessingInstruction, newNode.NodeType);
        }
    public static void RSSOpret(int idvalue)
    {
        DataClassesDataContext db = new DataClassesDataContext();

        List<dbCategory> ListCategory = db.dbCategories.Where(i => i.Id == idvalue).ToList();

        foreach (var itemChannel in ListCategory)
        {
            XmlDocument dom = new XmlDocument();
            XmlProcessingInstruction xpi = dom.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            dom.AppendChild(xpi);
            XmlElement rss = dom.CreateElement("rss");
            rss.SetAttribute("version", "2.0");

            XmlElement addRes = dom.CreateElement("channel");

            XmlElement navn = dom.CreateElement("title");
            navn.AppendChild(dom.CreateTextNode(itemChannel.Title));
            addRes.AppendChild(navn);

            XmlElement status = dom.CreateElement("description");
            status.AppendChild(dom.CreateTextNode(itemChannel.Description));
            addRes.AppendChild(status);

            XmlElement links = dom.CreateElement("link");
            links.AppendChild(dom.CreateTextNode(Url + "Categories.aspx?category_id='" + itemChannel.Id));
            addRes.AppendChild(links);

            List<dbNew> ListNews = db.dbNews.Where(i => i.CategoryId == idvalue).OrderByDescending(d => d.PostDate).ToList();

            foreach (var item in ListNews)
            {
                XmlElement addNew = dom.CreateElement("item");

                XmlElement titlenews = dom.CreateElement("title");
                titlenews.AppendChild(dom.CreateTextNode(item.Title));
                addNew.AppendChild(titlenews);

                XmlElement statusNew = dom.CreateElement("description");
                statusNew.AppendChild(dom.CreateTextNode(item.Content));
                addNew.AppendChild(statusNew);

                XmlElement linkNew = dom.CreateElement("link");
                linkNew.AppendChild(dom.CreateTextNode(Url + "News.aspx?category_id=" + itemChannel.Id + "&news_id=" + itemChannel.Id));
                addNew.AppendChild(linkNew);

                addRes.AppendChild(addNew);
            }

            rss.AppendChild(addRes);

            dom.AppendChild(rss);
            dom.Save(HttpContext.Current.Server.MapPath("~/feeds/") + itemChannel.Id + "_" + itemChannel.Title + ".xml");

        }
    }
Example #5
0
        public static void InsertNewNodeToElement()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a><b/></a>");
            var root = xmlDocument.DocumentElement;
            var newNode = xmlDocument.CreateProcessingInstruction("PI", "pi data");

            root.InsertBefore(newNode, root.FirstChild);

            Assert.Equal(2, root.ChildNodes.Count);
        }
Example #6
0
        public static void ImportDocumentFragment()
        {
            var tempDoc = new XmlDocument();
            var nodeToImport = tempDoc.CreateDocumentFragment();

            nodeToImport.AppendChild(tempDoc.CreateElement("A1"));
            nodeToImport.AppendChild(tempDoc.CreateComment("comment"));
            nodeToImport.AppendChild(tempDoc.CreateProcessingInstruction("PI", "donothing"));

            var xmlDocument = new XmlDocument();
            var node = xmlDocument.ImportNode(nodeToImport, true);

            Assert.Equal(xmlDocument, node.OwnerDocument);
            Assert.Equal(XmlNodeType.DocumentFragment, node.NodeType);
            Assert.Equal(nodeToImport.OuterXml, node.OuterXml);
        }
Example #7
0
        public static void OwnerDocumentOnImportedTree()
        {
            var tempDoc = new XmlDocument();
            var nodeToImport = tempDoc.CreateDocumentFragment();

            nodeToImport.AppendChild(tempDoc.CreateElement("A1"));
            nodeToImport.AppendChild(tempDoc.CreateComment("comment"));
            nodeToImport.AppendChild(tempDoc.CreateProcessingInstruction("PI", "donothing"));

            var xmlDocument = new XmlDocument();
            var node = xmlDocument.ImportNode(nodeToImport, true);

            Assert.Equal(xmlDocument, node.OwnerDocument);

            foreach (XmlNode child in node.ChildNodes)
                Assert.Equal(xmlDocument, child.OwnerDocument);
        }
    public static void RSSOpretKategori(int idvalue = 0)
    {
        DataLinqDB db = new DataLinqDB();

        string k = "kategori";

        XmlDocument dom = new XmlDocument();
        XmlProcessingInstruction xpi = dom.CreateProcessingInstruction(
            "xml", "version=\"1.0\" encoding=\"utf‐8\"");
        dom.AppendChild(xpi);
        XmlElement rod = dom.CreateElement("rod");
        rod.SetAttribute("attribut", k);

        List<category> ListCategory;

        if (idvalue > 0)
        {
            ListCategory = db.categories.Where(i => i.category_id == idvalue).ToList();
        }
        else
        {
            ListCategory = db.categories.ToList();
        }

        foreach (var item in ListCategory)
        {
            XmlElement addRes = dom.CreateElement("channel");

            XmlElement navn = dom.CreateElement("title");
            navn.AppendChild(dom.CreateTextNode(item.category_title));
            addRes.AppendChild(navn);

            XmlElement status = dom.CreateElement("description");
            status.AppendChild(dom.CreateTextNode(item.category_description));
            addRes.AppendChild(status);

            XmlElement links = dom.CreateElement("link");
            links.AppendChild(dom.CreateTextNode(Url + "Categories.aspx?category_id='" + item.category_id));
            addRes.AppendChild(links);

            if (idvalue > 0)
            {
                ListCategory = db.news.Where(i => i.fk_categories_id == idvalue).ToList();
            }
            else
            {
                ListCategory = db.news.ToList();
            }

            foreach (var item1 in collection)
            {

            }

            rod.AppendChild(addRes);

            dom.AppendChild(rod);
            dom.Save(HttpContext.Current.Server.MapPath("~/feeds/") + k + ".xml");

        }
    }
Example #9
0
        public static void ProcessingInstructionNode()
        {
            var xmlDocument = new XmlDocument();
            var node = xmlDocument.CreateProcessingInstruction("PI", "data");

            Assert.Equal("data", node.Value);
            node.Value = "new pi data";
            Assert.Equal("new pi data", node.Value);
        }
Example #10
0
        public static void ReplaceAttributeChildWithProcessingInstruction()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<root attr='test'/>");

            var attribute = xmlDocument.DocumentElement.Attributes[0];
            var attributeChild = attribute.FirstChild;
            var newText = xmlDocument.CreateProcessingInstruction("PI", "instructions");

            Assert.Throws<InvalidOperationException>(() => attribute.ReplaceChild(newText, attributeChild));
        }
Example #11
0
        public static void FirstChildOfNewProcessingInstruction()
        {
            var xmlDocument = new XmlDocument();

            Assert.Null(xmlDocument.CreateProcessingInstruction("PI", "pi_info").FirstChild);
        }
Example #12
0
 public static void CheckNoChildrenOnPI()
 {
     var xmlDocument = new XmlDocument();
     Assert.False(xmlDocument.CreateProcessingInstruction("PI", "info").HasChildNodes);
 }
Example #13
0
        public static void NewlyCreatedProcessingInstruction()
        {
            var xmlDocument = new XmlDocument();
            var node = xmlDocument.CreateProcessingInstruction("PI", "data");

            Assert.Null(node.NextSibling);
        }
Example #14
0
        public static void ProcessingInstructionChildNodeCount()
        {
            var xmlDocument = new XmlDocument();
            var item = xmlDocument.CreateProcessingInstruction("PI", "pi_info");
            var clonedTrue = item.CloneNode(true);
            var clonedFalse = item.CloneNode(false);

            Assert.Equal(0, item.ChildNodes.Count);
            Assert.Equal(0, clonedTrue.ChildNodes.Count);
            Assert.Equal(0, clonedFalse.ChildNodes.Count);
        }