当前位置: 首页>>代码示例>>C#>>正文


C# XmlNodeType类代码示例

本文整理汇总了C#中XmlNodeType的典型用法代码示例。如果您正苦于以下问题:C# XmlNodeType类的具体用法?C# XmlNodeType怎么用?C# XmlNodeType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XmlNodeType类属于命名空间,在下文中一共展示了XmlNodeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TwoTextNodeBase

        private static void TwoTextNodeBase(XmlDocument xmlDocument, InsertType insertType, XmlNodeType nodeType)
        {
            XmlNode parent = xmlDocument.DocumentElement;
            XmlNode refChild = (insertType == InsertType.Prepend) ? parent.FirstChild : parent.LastChild;
            XmlNode newChild = TestHelper.CreateNode(xmlDocument, nodeType);

            string original = parent.InnerXml;
            string expected = (insertType == InsertType.Prepend) ? (newChild.OuterXml + parent.InnerXml)
                : ((insertType == InsertType.Append) ? (parent.InnerXml + newChild.OuterXml)
                : (refChild.PreviousSibling.OuterXml + newChild.OuterXml + refChild.OuterXml));

            // insert new child
            var insertDelegate = TestHelper.CreateInsertBeforeOrAfter(insertType);
            insertDelegate(parent, newChild, refChild);

            // verify
            Assert.Equal(3, parent.ChildNodes.Count);
            Assert.Equal(expected, parent.InnerXml);

            TestHelper.Verify(parent, refChild, newChild);
            TestHelper.VerifySiblings(refChild, newChild, insertType);

            if (insertType == InsertType.Prepend || insertType == InsertType.Append)
                TestHelper.Verify(refChild, newChild, insertType);

            // delete new child
            parent.RemoveChild(newChild);
            Assert.Equal(2, parent.ChildNodes.Count);
            TestHelper.VerifySiblings(parent.FirstChild, parent.LastChild, InsertType.Append);
            Assert.Equal(original, parent.InnerXml);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:31,代码来源:TwoTextNodeTests.cs

示例2: VerifyOwnerOfGivenType

        private static void VerifyOwnerOfGivenType(XmlNodeType nodeType)
        {
            var xmlDocument = new XmlDocument();
            var node = xmlDocument.CreateNode(nodeType, "test", string.Empty);

            Assert.Equal(xmlDocument, node.OwnerDocument);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:7,代码来源:OwnerDocumentTests.cs

示例3: AddNode

        /// <summary>
        /// Adds a new node to the curret XML document. A node is added to XDocument, and another one is added to the XmlTreeNode list that is used by the DevExpress TreeList to visually represent the XML document
        /// </summary>
        /// <param name="parrentId"></param>
        /// <param name="type"></param>
        public void AddNode(int parrentId, XmlNodeType type)
        {
            List<XmlTreeNode> treeNodes = _dataSource.GetXmlTreeNodes();

            XmlTreeNode parent = treeNodes.Where(i => i.Id == parrentId).FirstOrDefault();
            XElement parentElement = (XElement)parent.XObject;

            // The default name and value of the new node
            string name = "Name" + treeNodes.Count;
            string value = "Value";

            // Creates the XObject representing the new node in the XML document
            XObject newNodeXObject;
            if (type == XmlNodeType.Element)
            {
                newNodeXObject = new XElement(name, value);
                // When an element becomes a parent, it is no longer allowed to have a value. XDocument does not support parent elements with values
                if (parentElement.Elements().Count() == 0)
                    parentElement.SetValue("");
            }
            else
                newNodeXObject = new XAttribute(name, value);
            parentElement.Add(newNodeXObject);

            //// Creates the XmlTreeNode that is added to the list of XmlTreeNodes used by the DevExpress TreeList to visually represented the XML document
            //XmlTreeNode node = new XmlTreeNode() { Id = highestId + 1, ParentId = parrentId, IsParrent = false, Name = "Name" + treeNodes.Count, Value = "Value", Type = type, Parrent = (XElement)parent.XObject, XObject = newNodeXObject };
            //treeNodes.Add(node);
        }
开发者ID:steffan88,项目名称:XmlEditor,代码行数:33,代码来源:XmlDataProvider.cs

示例4: CXmlBase

 //
 // Constructors
 //
 public CXmlBase(string strPrefix, string strName, string strLocalName, XmlNodeType NodeType, string strNamespace)
 {
     _strPrefix = strPrefix;
     _strName = strName;
     _strLocalName = strLocalName;
     _nType = NodeType;
     _strNamespace = strNamespace;
 }
开发者ID:shmao,项目名称:corefx,代码行数:11,代码来源:CXmlCache.cs

示例5: XPathNavigatorReader

 protected XPathNavigatorReader(XPathNavigator navToRead)
 {
     // Need clone that can be moved independently of original navigator
     _navToRead = navToRead;
     _nav = XmlEmptyNavigator.Singleton;
     _state = State.Initial;
     _depth = 0;
     _nodeType = XPathNavigatorReader.ToXmlNodeType(_nav.NodeType);
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:9,代码来源:XPathNavigatorReader.cs

示例6: PositionOnNodeType2

 public void PositionOnNodeType2(XmlNodeType nodeType)
 {
     while (DataReader.Read() && DataReader.NodeType != nodeType)
     {
     }
     if (DataReader.EOF)
     {
         throw new CTestFailedException("Couldn't find XmlNodeType " + nodeType);
     }
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:LineNumber.cs

示例7: InsertTestBase

        private static void InsertTestBase(string xml, InsertType insertType, XmlNodeType nodeType)
        {
            string[] expected = new string[2];

            var xmlDocument = new XmlDocument { PreserveWhitespace = true };
            xmlDocument.LoadXml(xml);

            XmlNode parent = xmlDocument.DocumentElement;
            XmlNode firstChild = parent.FirstChild;
            XmlNode lastChild = parent.LastChild;
            XmlNode refChild = parent.FirstChild.NextSibling;
            XmlNode newChild = TestHelper.CreateNode(xmlDocument, nodeType);

            expected[0] = parent.InnerXml;
            expected[1] = (insertType == InsertType.InsertBefore)
                ? (firstChild.OuterXml + newChild.OuterXml + refChild.OuterXml + lastChild.OuterXml)
                : (firstChild.OuterXml + refChild.OuterXml + newChild.OuterXml + lastChild.OuterXml);

            // insertion
            var insertDelegate = TestHelper.CreateInsertBeforeOrAfter(insertType);
            insertDelegate(parent, newChild, refChild);

            // verify
            Assert.Equal(4, parent.ChildNodes.Count);
            Assert.Equal(expected[1], parent.InnerXml);

            TestHelper.Verify(parent, refChild, newChild);
            TestHelper.Verify(parent, firstChild, lastChild);
            TestHelper.VerifySiblings(refChild, newChild, insertType);

            if (insertType == InsertType.InsertBefore)
            {
                TestHelper.VerifySiblings(firstChild, newChild, InsertType.Append);
                TestHelper.VerifySiblings(newChild, refChild, InsertType.Append);
                TestHelper.VerifySiblings(refChild, lastChild, InsertType.Append);
            }
            else
            {
                TestHelper.VerifySiblings(firstChild, refChild, InsertType.Append);
                TestHelper.VerifySiblings(refChild, newChild, InsertType.Append);
                TestHelper.VerifySiblings(newChild, lastChild, InsertType.Append);
            }

            // delete the newChild
            parent.RemoveChild(newChild);

            // verify
            Assert.Equal(3, parent.ChildNodes.Count);
            Assert.Equal(expected[0], parent.InnerXml);

            TestHelper.Verify(parent, firstChild, lastChild);
            TestHelper.VerifySiblings(firstChild, refChild, InsertType.Append);
            TestHelper.VerifySiblings(refChild, lastChild, InsertType.Append);
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:54,代码来源:ThreeElementTests.cs

示例8: VerifyNextNode

        private void VerifyNextNode(XmlNodeType nt, string name, string value)
        {
            while (DataReader.NodeType == XmlNodeType.Whitespace ||
                    DataReader.NodeType == XmlNodeType.SignificantWhitespace)
            {
                // skip all whitespace nodes
                // if EOF is reached NodeType=None
                DataReader.Read();
            }

            CError.Compare(DataReader.VerifyNode(nt, name, value), "VerifyNextNode");
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:12,代码来源:CXmlReaderReadEtc.cs

示例9: XsltInput

        public XsltInput(XmlReader reader, Compiler compiler, KeywordsTable atoms) {
            Debug.Assert(reader != null);
            Debug.Assert(atoms != null);
            EnsureExpandEntities(reader);
            IXmlLineInfo xmlLineInfo = reader as IXmlLineInfo;

            this.atoms          = atoms;
            this.reader         = reader;
            this.reatomize      = reader.NameTable != atoms.NameTable;
            this.readerLineInfo = (xmlLineInfo != null && xmlLineInfo.HasLineInfo()) ? xmlLineInfo : null;
            this.topLevelReader = reader.ReadState == ReadState.Initial;
            this.scopeManager   = new CompilerScopeManager<VarPar>(atoms);
            this.compiler       = compiler;
            this.nodeType       = XmlNodeType.Document;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:15,代码来源:XsltInput.cs

示例10: TestOnNopNodeType

        protected void TestOnNopNodeType(XmlNodeType nt)
        {
            ReloadSource();

            PositionOnNodeType(nt);
            string name = DataReader.Name;
            string value = DataReader.Value;
            CError.WriteLine("Name=" + name);
            CError.WriteLine("Value=" + value);
            if (CheckCanReadBinaryContent()) return;

            byte[] buffer = new byte[1];
            int nBytes = DataReader.ReadContentAsBase64(buffer, 0, 1);
            CError.Compare(nBytes, 0, "nBytes");
            CError.Compare(DataReader.VerifyNode(nt, name, value), "vn");
            CError.WriteLine("Succeeded:{0}", nt);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:17,代码来源:ReadBase64.cs

示例11: OneTextNodeBase

        private static void OneTextNodeBase(string xml, InsertType insertType, XmlNodeType nodeType)
        {
            var insertDelegate = TestHelper.CreateInsertFrontOrEnd(insertType);
            var xmlDocument = new XmlDocument { PreserveWhitespace = true };
            xmlDocument.LoadXml(xml);

            var parent = xmlDocument.DocumentElement;
            var child = parent.FirstChild;
            var newChild = TestHelper.CreateNode(xmlDocument, nodeType);
            var expected = (insertType == InsertType.Prepend) ? (newChild.OuterXml + child.OuterXml) : (child.OuterXml + newChild.OuterXml);

            // insert new child
            insertDelegate(parent, newChild);

            // verify
            Assert.Equal(2, parent.ChildNodes.Count);
            Assert.Equal(expected, parent.InnerXml);

            TestHelper.Verify(parent, child, newChild);
            TestHelper.Verify(child, newChild, insertType);

            // delete new child
            parent.RemoveChild(newChild);

            // verify
            Assert.Equal(1, parent.ChildNodes.Count);

            // Verify single child
            Assert.NotNull(parent);
            Assert.NotNull(child);

            Assert.Equal(child, parent.FirstChild);
            Assert.Equal(child, parent.LastChild);
            Assert.Null(child.NextSibling);
            Assert.Null(child.PreviousSibling);

            // delete the last child
            parent.RemoveChild(child);

            // verify
            Assert.Equal(0, parent.ChildNodes.Count);
            Assert.Null(parent.FirstChild);
            Assert.Null(parent.LastChild);
            Assert.False(parent.HasChildNodes);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:45,代码来源:OneElementTests.cs

示例12: TestOnInvalidNodeType

 protected void TestOnInvalidNodeType(XmlNodeType nt)
 {
     ReloadSource();
     PositionOnNodeType(nt);
     if (CheckCanReadBinaryContent()) return;
     try
     {
         byte[] buffer = new byte[1];
         int nBytes = DataReader.ReadContentAsBase64(buffer, 0, 1);
     }
     catch (InvalidOperationException ioe)
     {
         if (ioe.ToString().IndexOf(nt.ToString()) < 0)
             CError.Compare(false, "Call threw wrong invalid operation exception on " + nt);
         else
             return;
     }
     CError.Compare(false, "Call succeeded on " + nt);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:19,代码来源:ReadBase64.cs

示例13: TestInvalidNodeType

        protected void TestInvalidNodeType(XmlNodeType nt)
        {
            ReloadSource();

            PositionOnNodeType(nt);
            string name = DataReader.Name;
            string value = DataReader.Value;

            byte[] buffer = new byte[1];
            if (CheckCanReadBinaryContent()) return;

            try
            {
                int nBytes = DataReader.ReadContentAsBinHex(buffer, 0, 1);
            }
            catch (InvalidOperationException)
            {
                return;
            }
            CError.Compare(false, "Invalid OP exception not thrown on wrong nodetype");
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:21,代码来源:ReadBinHex.cs

示例14: OneTextNode_OneNonTextNodeBase

        private static void OneTextNode_OneNonTextNodeBase(string xml, InsertType insertType, XmlNodeType nodeType, bool deleteFirst)
        {
            var xmlDocument = new XmlDocument { PreserveWhitespace = true };
            xmlDocument.LoadXml(xml);

            XmlNode parent = xmlDocument.DocumentElement;
            XmlNode refChild = (insertType == InsertType.Prepend) ? parent.FirstChild : parent.LastChild;
            XmlNode newChild = TestHelper.CreateNode(xmlDocument, nodeType);
            XmlNode nodeToRemove = (deleteFirst) ? parent.FirstChild : parent.LastChild;

            // populate the expected result, where expected[0] is the expected result after insertion, and expected[1] is the expected result after deletion
            string[] expected = new string[2];
            expected[0] = (insertType == InsertType.Prepend) ? (newChild.OuterXml + parent.InnerXml)
                : ((insertType == InsertType.Append) ? (parent.InnerXml + newChild.OuterXml)
                : (refChild.PreviousSibling.OuterXml + newChild.OuterXml + refChild.OuterXml));
            if (deleteFirst)
                expected[1] = (insertType == InsertType.Append) ? (parent.LastChild.OuterXml + newChild.OuterXml) : (newChild.OuterXml + parent.LastChild.OuterXml);
            else
                expected[1] = (insertType == InsertType.Prepend) ? (newChild.OuterXml + parent.FirstChild.OuterXml) : (parent.FirstChild.OuterXml + newChild.OuterXml);

            // insert new child
            var insertDelegate = TestHelper.CreateInsertBeforeOrAfter(insertType);
            insertDelegate(parent, newChild, refChild);

            // verify
            Assert.Equal(3, parent.ChildNodes.Count);
            Assert.Equal(expected[0], parent.InnerXml);

            TestHelper.Verify(parent, refChild, newChild);
            TestHelper.VerifySiblings(refChild, newChild, insertType);

            if (insertType == InsertType.Prepend || insertType == InsertType.Append)
                TestHelper.Verify(refChild, newChild, insertType);

            // delete new child
            parent.RemoveChild(nodeToRemove);
            Assert.Equal(2, parent.ChildNodes.Count);
            TestHelper.VerifySiblings(parent.FirstChild, parent.LastChild, InsertType.Append);
            Assert.Equal(expected[1], parent.InnerXml);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:40,代码来源:TwoElementTests.cs

示例15: CreateNode

        public static XmlNode CreateNode(XmlDocument doc, XmlNodeType nodeType)
        {
            Assert.NotNull(doc);

            switch (nodeType)
            {
                case XmlNodeType.CDATA:
                    return doc.CreateCDataSection(@"&lt; &amp; <tag> < ! > & </tag> 	 ");
                case XmlNodeType.Comment:
                    return doc.CreateComment(@"comment");
                case XmlNodeType.Element:
                    return doc.CreateElement("E");
                case XmlNodeType.Text:
                    return doc.CreateTextNode("text");
                case XmlNodeType.Whitespace:
                    return doc.CreateWhitespace(@"	  ");
                case XmlNodeType.SignificantWhitespace:
                    return doc.CreateSignificantWhitespace("	");
                default:
                    throw new ArgumentException("Wrong XmlNodeType: '" + nodeType + "'");
            }
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:22,代码来源:TestHelper.cs


注:本文中的XmlNodeType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。