コード例 #1
0
ファイル: XmlNodeListTests.cs プロジェクト: nobled/mono
		public void AppendChildAffectOnEnumeration ()
		{
			document.LoadXml ("<foo><child1/></foo>");
			element = document.DocumentElement;
			enumerator = element.GetEnumerator();
			Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
			Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
			enumerator.Reset();
			Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
			element.AppendChild(document.CreateElement("child2"));
			Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
			Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
		}
コード例 #2
0
ファイル: XmlNodeListTests.cs プロジェクト: nobled/mono
		public void Reset ()
		{
			document.LoadXml ("<foo><child1/><child2/></foo>");
			element = document.DocumentElement;
			enumerator = element.GetEnumerator();
			enumerator.MoveNext();
			enumerator.MoveNext();
			Assert.AreEqual (((XmlElement)enumerator.Current).LocalName, "child2", "Expected child2.");
			enumerator.Reset();
			enumerator.MoveNext();
			Assert.AreEqual (((XmlElement)enumerator.Current).LocalName, "child1", "Expected child1.");
		}
コード例 #3
0
ファイル: XmlNodeListTests.cs プロジェクト: nobled/mono
		public void ZeroChildren ()
		{
			document.LoadXml ("<foo/>");
			documentElement = document.DocumentElement;
			Assert.AreEqual (documentElement.GetEnumerator().MoveNext(), false, "Should be empty node list.");
		}
コード例 #4
0
ファイル: XmlNodeListTests.cs プロジェクト: nobled/mono
		public void CurrentAfterLastNode ()
		{
			document.LoadXml ("<foo><child1/></foo>");
			element = document.DocumentElement;
			enumerator = element.GetEnumerator();
			enumerator.MoveNext();
			enumerator.MoveNext();
			try 
			{
				obj = enumerator.Current;
				Assert.Fail ("Calling Current property after last node in list should have thrown InvalidOperationException.");
			} 
			catch (InvalidOperationException) { }
		}
コード例 #5
0
ファイル: XmlNodeListTests.cs プロジェクト: nobled/mono
		public void CurrentDoesntMove ()
		{
			document.LoadXml ("<foo><child1/></foo>");
			element = document.DocumentElement;
			enumerator = element.GetEnumerator();
			enumerator.MoveNext();
			Assert.AreEqual (Object.ReferenceEquals(enumerator.Current, enumerator.Current), true, "Consecutive calls to Current property should yield same reference.");
		}
コード例 #6
0
ファイル: XmlNodeListTests.cs プロジェクト: nobled/mono
		public void RemoveOnlyChildAffectOnEnumeration ()
		{
			document.LoadXml ("<foo><child1/></foo>");
			element = document.DocumentElement;
			enumerator = element.GetEnumerator();
			element.RemoveChild(element.FirstChild);
			Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
		}
コード例 #7
0
ファイル: XmlNodeListTests.cs プロジェクト: nobled/mono
		// TODO:  Take the word save off front of this method when XmlNode.RemoveAll() is fully implemented.

		public void saveTestRemoveAllAffectOnEnumeration ()
		{
			document.LoadXml ("<foo><child1/><child2/><child3/></foo>");
			element = document.DocumentElement;
			enumerator = element.GetEnumerator();
			Assert.AreEqual (element.ChildNodes.Count, 3, "Expected 3 children.");
			Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
			element.RemoveAll();
			Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
		}
コード例 #8
0
ファイル: XmlNodeListTests.cs プロジェクト: nobled/mono
		// TODO:  Take the word save off front of this method when XmlNode.ReplaceChild() is implemented.

		public void saveTestReplaceChildAffectOnEnumeration ()
		{
			document.LoadXml ("<foo><child1/><child2/></foo>");
			element = document.DocumentElement;
			node = document.CreateElement("child3");
			enumerator = element.GetEnumerator();
			Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
			element.ReplaceChild(node, element.LastChild);
			enumerator.MoveNext();
			Assert.AreEqual (((XmlElement)enumerator.Current).LocalName, "child3", "Expected child3 element.");
			Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
		}
コード例 #9
0
ファイル: XmlNodeListTests.cs プロジェクト: nobled/mono
		public void RemoveChildAffectOnEnumerationWhenEnumeratorIsOnRemovedChild ()
		{
			document.LoadXml ("<foo><child1/><child2/><child3/></foo>");
			element = document.DocumentElement;
			enumerator = element.GetEnumerator ();
			enumerator.MoveNext ();
			enumerator.MoveNext ();
			Assert.AreEqual ("child2", ((XmlElement)enumerator.Current).LocalName, "Expected child2 element.");
			Assert.AreEqual ("child2", element.FirstChild.NextSibling.LocalName, "Expected child2 element.");
			element.RemoveChild (element.FirstChild.NextSibling);
			enumerator.MoveNext ();
			
			try {
				element = (XmlElement) enumerator.Current;
				Assert.Fail ("Expected an InvalidOperationException.");
			} catch (InvalidOperationException) { }
		}
コード例 #10
0
ファイル: XmlNodeListTests.cs プロジェクト: nobled/mono
		public void RemoveChildAffectOnEnumeration ()
		{
			document.LoadXml ("<foo><child1/><child2/></foo>");
			element = document.DocumentElement;
			enumerator = element.GetEnumerator();
			element.RemoveChild(element.FirstChild);
			enumerator.MoveNext();
			Assert.AreEqual (((XmlElement)enumerator.Current).LocalName, "child2", "Expected child2 element.");
		}
コード例 #11
0
        /* OPC Compliance methods */

        /**
         * Check the element for the following OPC compliance rules:
         * <p>
         * Rule M4.2: A format consumer shall consider the use of the Markup
         * Compatibility namespace to be an error.
         * </p><p>
         * Rule M4.3: Producers shall not create a document element that contains
         * refinements to the Dublin Core elements, except for the two specified in
         * the schema: <dcterms:created> and <dcterms:modified> Consumers shall
         * consider a document element that violates this constraint to be an error.
         * </p><p>
         * Rule M4.4: Producers shall not create a document element that contains
         * the xml:lang attribute. Consumers shall consider a document element that
         * violates this constraint to be an error.
         *  </p><p>
         * Rule M4.5: Producers shall not create a document element that contains
         * the xsi:type attribute, except for a <dcterms:created> or
         * <dcterms:modified> element where the xsi:type attribute shall be present
         * and shall hold the value dcterms:W3CDTF, where dcterms is the namespace
         * prefix of the Dublin Core namespace. Consumers shall consider a document
         * element that violates this constraint to be an error.
         * </p>
         */
        public void CheckElementForOPCCompliance(XmlElement el)
        {
            foreach (XmlAttribute attr in el.Attributes)
            {
                if (attr.Name.StartsWith("xmlns:"))
                {
                    string namespacePrefix = attr.Name.Substring(6);
                    if (nsmgr.LookupNamespace(namespacePrefix).Equals(PackageNamespaces.MARKUP_COMPATIBILITY))
                    {
                        // Rule M4.2
                        throw new InvalidFormatException(
                                    "OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.");
                    }
                }
            }
            // Check the current element


            // Rule M4.3
            if (el.NamespaceURI.Equals(
                    namespaceDcTerms)
                    && !(el.LocalName.Equals(KEYWORD_CREATED) || el.LocalName
                            .Equals(KEYWORD_MODIFIED)))
                throw new InvalidFormatException(
                        "OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.");

            // Rule M4.4
            if (el.Attributes["lang", namespaceXML] != null)
                throw new InvalidFormatException(
                        "OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.");

            // Rule M4.5
            if (el.NamespaceURI.Equals(
                    namespaceDcTerms))
            {
                // DCTerms namespace only use with 'created' and 'modified' elements
                String elName = el.LocalName;
                if (!(elName.Equals(KEYWORD_CREATED) || elName
                        .Equals(KEYWORD_MODIFIED)))
                    throw new InvalidFormatException("Namespace error : " + elName
                            + " shouldn't have the following naemspace -> "
                            + namespaceDcTerms);

                // Check for the 'xsi:type' attribute
                XmlAttribute typeAtt = el.Attributes["xsi:type"];
                if (typeAtt == null)
                    throw new InvalidFormatException("The element '" + elName
                            + "' must have the '" + nsmgr.LookupPrefix(namespaceXSI)
                            + ":type' attribute present !");

                // Check for the attribute value => 'dcterms:W3CDTF'
                if (!typeAtt.Value.Equals("dcterms:W3CDTF"))
                    throw new InvalidFormatException("The element '" + elName
                            + "' must have the '" + nsmgr.LookupPrefix(namespaceXSI)
                            + ":type' attribute with the value 'dcterms:W3CDTF' !");
            }

            // Check its children
            IEnumerator itChildren = el.GetEnumerator();
            while (itChildren.MoveNext())
            {
                if (itChildren.Current is XmlElement)
                    CheckElementForOPCCompliance((XmlElement)itChildren.Current);
            }
        }
コード例 #12
0
		public void CurrentBeforeFirstNode ()
		{
			document.LoadXml ("<foo><child1/></foo>");
			element = document.DocumentElement;
			enumerator = element.GetEnumerator();
			try 
			{
				obj = enumerator.Current;
				Fail ("Calling Current property before first node in list should have thrown InvalidOperationException.");
			} catch (InvalidOperationException) { }
		}