Inheritance: XmlCharacterData
		public void SetUp()
		{
			XmlCompletionDataProvider completionDataProvider = new XmlCompletionDataProvider(new XmlSchemaCompletionDataCollection(), null, String.Empty);
			treeViewContainerControl = new XmlTreeViewContainerControl();
			treeView = treeViewContainerControl.TreeView;
			treeViewContainerControl.LoadXml(GetXml(), completionDataProvider);
			doc = treeViewContainerControl.Document;
			
			clipboardHandler = treeViewContainerControl as IClipboardHandler;
			
			htmlElement = doc.DocumentElement;
			bodyElement = htmlElement.FirstChild as XmlElement;
			paragraphElement = bodyElement.SelectSingleNode("p") as XmlElement;
			paragraphText = paragraphElement.SelectSingleNode("text()") as XmlText;
			bodyComment = bodyElement.SelectSingleNode("comment()") as XmlComment;
			
			htmlTreeNode = treeView.Nodes[0] as XmlElementTreeNode;
			htmlTreeNode.PerformInitialization();
			bodyTreeNode = htmlTreeNode.FirstNode as XmlElementTreeNode;
			bodyTreeNode.PerformInitialization();
			bodyCommentTreeNode = bodyTreeNode.FirstNode as XmlCommentTreeNode;
			paragraphTreeNode = bodyTreeNode.LastNode as XmlElementTreeNode;
			paragraphTreeNode.PerformInitialization();
			paragraphTextTreeNode = paragraphTreeNode.FirstNode as XmlTextTreeNode;
		}
		public void SetUpFixture()
		{
			doc = new XmlDocument();
			doc.LoadXml("<root><firstChild><secondChild/></firstChild><textChild>some text</textChild></root>");
			using (XmlTreeViewControl treeView = new XmlTreeViewControl()) {
				treeView.Document = doc;
				treeView.SelectedNode = treeView.Nodes[0];
				rootNodeElement = treeView.SelectedElement;
				isRootElementSelected = treeView.IsElementSelected;
				rootNode = (ExtTreeNode)treeView.SelectedNode;
				rootNodeHadChildrenBeforeExpansion = rootNode.Nodes.Count > 0;
				rootNode.Expanding();
				firstChildNode = (ExtTreeNode)rootNode.Nodes[0];
				firstChildNodeHadChildrenBeforeExpansion = firstChildNode.Nodes.Count > 0;
				firstChildNode.Expanding();
				secondChildNode = (ExtTreeNode)firstChildNode.Nodes[0];
				textChildNode = (ExtTreeNode)rootNode.Nodes[1];
				textChildNode.Expanding();
				textNode = (ExtTreeNode)textChildNode.Nodes[0];
				isTextContentSelectedBeforeTextNodeSelected = treeView.IsTextNodeSelected;
				textContentBefore = treeView.SelectedTextNode;
				treeView.SelectedNode = textNode;
				isTextContentSelectedAfterTextNodeSelected = treeView.IsTextNodeSelected;
				textContentAfter = treeView.SelectedTextNode;
				textNodeElement = treeView.SelectedElement;
			}
		}
Beispiel #3
0
 protected override void ExecuteCore(XmlText text)
 {
     Validate();
     var element = text.OwnerDocument.CreateElement(Name);
     element.InnerText = text.Value;
     text.ParentNode.ReplaceChild(element, text);
 }
		public XmlTextTreeNode(XmlText xmlText)
			: base(xmlText)
		{
			this.xmlText = xmlText;
			ImageKey = XmlTextTreeNodeImageKey;
			SelectedImageKey = ImageKey;
			Update();
		}
 void AppendTextToDocumentation(XmlText textNode)
 {
     if (textNode != null) {
         if (textNode.Data != null) {
             documentation.Append(textNode.Data);
         }
     }
 }
Beispiel #6
0
        public Channel(XmlDocument doc, XmlNode node)
        {
            this.channel = node;
            this.doc = doc;

            title = MakeTextElement ("title");
            link = MakeTextElement ("link");
            description = MakeTextElement ("description");
        }
        public void Init()
        {
            base.InitFixture();
            paragraphElement = (XmlElement)editor.Document.SelectSingleNode("/html/body/p");
            textNode = (XmlText)paragraphElement.SelectSingleNode("text()");
            mockXmlTreeView.SelectedTextNode = textNode;

            editor.InsertTextNodeBefore();
        }
		public void Init()
		{
			base.InitFixture();
			rootElement = editor.Document.DocumentElement;
			bodyElement = (XmlElement)rootElement.FirstChild;
			paragraphElement = (XmlElement)bodyElement.SelectSingleNode("p");
			bodyComment = (XmlComment)bodyElement.SelectSingleNode("comment()");
			paragraphText = (XmlText)paragraphElement.SelectSingleNode("text()");
		}
Beispiel #9
0
    static int ConnectSample()
    {
        PmsXchangeService service = new PmsXchangeService();

        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        //The security header is untyped due to the lax processing instruction
        System.Xml.XmlElement token    = doc.CreateElement("UsernameToken");
        System.Xml.XmlElement password = doc.CreateElement("Password");
        System.Xml.XmlElement username = doc.CreateElement("Username");

        System.Xml.XmlText usernameText = doc.CreateTextNode("SPIOrangeTest");
        System.Xml.XmlText passwordText = doc.CreateTextNode("YOURPASSWORD");
        username.AppendChild(usernameText);
        password.AppendChild(passwordText);
        token.AppendChild(username);
        token.AppendChild(password);

        System.Xml.XmlElement[] elements = new System.Xml.XmlElement[] { token };

        SecurityHeaderType type = new SecurityHeaderType();

        service.Security     = type;
        service.Security.Any = elements;

        OTA_ReadRQ otaReadRQ = new OTA_ReadRQ();

        otaReadRQ.Version = 1.0M;
        OTA_ReadRQReadRequests rr = new OTA_ReadRQReadRequests();
        OTA_ReadRQReadRequestsHotelReadRequest hotelR = new OTA_ReadRQReadRequestsHotelReadRequest();

        hotelR.HotelCode = "123";

        object[] ob = new object[] { hotelR };
        rr.Items = ob;

        OTA_ReadRQReadRequestsHotelReadRequestSelectionCriteria crit = new OTA_ReadRQReadRequestsHotelReadRequestSelectionCriteria();
        OTA_ReadRQReadRequestsHotelReadRequestSelectionCriteriaSelectionType selType = OTA_ReadRQReadRequestsHotelReadRequestSelectionCriteriaSelectionType.Undelivered;

        crit.SelectionType          = selType;
        crit.SelectionTypeSpecified = true;

        hotelR.SelectionCriteria = crit;
        otaReadRQ.ReadRequests   = rr;
        // Retrieve the response
        Console.WriteLine("About to make request :::");
        OTA_ResRetrieveRS resRetrieveRS = service.ReadRQ(otaReadRQ);

        Console.WriteLine("Received response :::");

        //Do further work ....
        // ....
        return(0);
    }
Beispiel #10
0
        private static string GetElementText(Xml.XmlElement element)
        {
            foreach (Xml.XmlNode n in element.ChildNodes)
            {
                if (n is Xml.XmlText)
                {
                    Xml.XmlText textNode = (Xml.XmlText)n;
                    return(textNode.Value);
                }
            }

            return(string.Empty);
        }
Beispiel #11
0
Datei: Show.cs Projekt: rh/mix
        public void Print(XmlText text, bool enter)
        {
            if (SkipText)
            {
                return;
            }

            Context.Output.Write(text.Value.Trim());

            if (enter)
            {
                Context.Output.WriteLine();
            }
        }
Beispiel #12
0
        protected override void ExecuteCore(XmlText text)
        {
            Validate();

            var element = text.ParentNode as XmlElement;

            if (element != null && element.Attributes[Name] == null)
            {
                var attribute = text.OwnerDocument.CreateAttribute(Name);
                attribute.Value = text.Value;
                element.Attributes.Append(attribute);
                element.RemoveChild(text);
            }
        }
Beispiel #13
0
        public void core0007T()
        {
            string computedValue = "";

            System.Xml.XmlText oldTextNode   = null;
            System.Xml.XmlText newTextNode   = null;
            System.Xml.XmlNode testNode      = null;
            string             expectedValue = "System.ArgumentOutOfRangeException";//util.INDEX_SIZE_ERR;

            testResults results = new testResults("Core0007T");

            try
            {
                results.description = "The \"splitText(offset)\" method raises an " +
                                      "INDEX_SIZE_ERR Exception if the specified " +
                                      "offset is negative.";

                //
                // Retrieve the targeted data
                //
                testNode    = util.nodeObject(util.THIRD, util.SECOND);
                oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
                //
                // Call the "spitText(offset)" method with "offset" equal to a negative
                // number should raise an exception.
                //
                try
                {
                    oldTextNode.SplitText(-69);
                }
                catch (System.Exception ex)
                {
                    computedValue = ex.GetType().FullName;
                }
            }
            catch (System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            results.expected = expectedValue;
            results.actual   = computedValue;

            util.resetData();

            Assert.AreEqual(results.expected, results.actual);
        }
Beispiel #14
0
        public TextDocumentFacade(XmlDocument document)
        {
            this.document = document;

            root = document.CreateElement("html");
            document.AppendChild(root);

            body = document.CreateElement("body");
            head = document.CreateElement("head");

            root.AppendChild(head);
            root.AppendChild(body);

            title = document.CreateElement("title");
            titleText = document.CreateTextNode("");
            head.AppendChild(title);
        }
Beispiel #15
0
        public void core0008T()
        {
            string computedValue = "";

            System.Xml.XmlText oldTextNode   = null;
            System.Xml.XmlNode testNode      = null;
            string             expectedValue = "System.ArgumentOutOfRangeException";

            testResults results = new testResults("Core0008T");

            try
            {
                results.description = "The \"splitText(offset)\" method raises an " +
                                      "ArgumentOutOfRangeException if the specified " +
                                      "offset is greater than the number of 16-bit units " +
                                      "in the Text node.";
                //
                // Retrieve the targeted data.
                //
                testNode    = util.nodeObject(util.THIRD, util.SECOND);
                oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
                //
                // Call the "spitText(offset)" method with "offset" greater than the numbers
                // of characters in the Text node, it should raise an exception.

                try
                {
                    oldTextNode.SplitText(300);
                }
                catch (System.Exception ex)
                {
                    computedValue = ex.GetType().ToString();
                }
            }
            catch (System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            results.expected = expectedValue;
            results.actual   = computedValue;

            util.resetData();

            Assert.AreEqual(results.expected, results.actual);
        }
		public void SetUpFixture()
		{
			base.InitFixture();
			
			// User selects text node and alters its text.
			textNode = (XmlText)mockXmlTreeView.Document.DocumentElement.FirstChild;
			mockXmlTreeView.SelectedTextNode = textNode;
			editor.SelectedNodeChanged();
			mockXmlTreeView.TextContent = "new value";
			editor.TextContentChanged();
			
			// The user then selects another element and then switches
			// back to the text node.
			mockXmlTreeView.SelectedElement = mockXmlTreeView.Document.DocumentElement;
			editor.SelectedNodeChanged();
			mockXmlTreeView.TextContent = String.Empty;
			mockXmlTreeView.SelectedTextNode = textNode;
			editor.SelectedNodeChanged();
		}
Beispiel #17
0
        [Ignore(".NET DOM implementation does not match W3C DOM specification.")] // MS DOM is buggy
        public void core0009T()
        {
            string computedValue = "";

            System.Xml.XmlNode testNode      = null;
            System.Xml.XmlText readOnlyText  = null;
            string             expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;

            testResults results = new testResults("Core0009T");

            try
            {
                results.description = "The \"splitText(offset)\" method raises a " +
                                      "NO_MODIFICATION_ALLOWED_ERR Exception if the " +
                                      "node is readonly.";
                //
                // Attempt to modify descendants of an EntityReference node should raise
                // an exception.
                //
                testNode     = util.nodeObject(util.SECOND, util.SIXTH);
                readOnlyText = (System.Xml.XmlText)testNode.ChildNodes.Item(util.FIRST).FirstChild;

                try
                {
                    readOnlyText.SplitText(5);
                }
                catch (ArgumentException ex)
                {
                    computedValue = ex.GetType().FullName;
                }
            }
            catch (System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            results.expected = expectedValue;
            results.actual   = computedValue;

            util.resetData();

            Assert.AreEqual(results.expected, results.actual);
        }
Beispiel #18
0
        public void core0005T()
        {
            string computedValue = "";
            string expectedValue = " Jones";

            System.Xml.XmlText oldTextNode = null;
            System.Xml.XmlText newTextNode = null;
            System.Xml.XmlNode testNode    = null;

            testResults results = new testResults("Core0005T");

            try
            {
                results.description = "After the \"splitText(offset)\" method is invoked, the " +
                                      "new Text node contains all of the content from the offset " +
                                      "point to the end of the text.";
                //
                // Retrieve the targeted data.
                //
                testNode    = util.nodeObject(util.THIRD, util.SECOND);
                oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
                //
                // Split the two lines of text into two different Text nodes.
                //
                newTextNode   = oldTextNode.SplitText(util.SEVENTH);
                computedValue = newTextNode.Value;
            }
            catch (System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual   = computedValue;

            util.resetData();

            Assert.AreEqual(results.expected, results.actual);
        }
Beispiel #19
0
        public void core0003T()
        {
            string computedValue = "";
            string expectedValue = "Jones";

            System.Xml.XmlText oldTextNode = null;
            System.Xml.XmlNode testNode    = null;

            testResults results = new testResults("Core0003T");

            try
            {
                results.description = "The \"splitText(offset)\" method breaks the Text node " +
                                      "into two Text nodes at the specified offset, keeping each " +
                                      "node in the tree as siblings.";
                //
                // Retrieve the targeted data.
                //
                testNode    = util.nodeObject(util.THIRD, util.SECOND);
                oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
                //
                // Split the two lines of text into two different Text nodes.
                //
                oldTextNode.SplitText(util.EIGHT);
                computedValue = oldTextNode.NextSibling.Value;
            }
            catch (System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            //  Write out results
            //
            results.expected = expectedValue;
            results.actual   = computedValue;

            util.resetData();

            Assert.AreEqual(results.expected, results.actual);
        }
Beispiel #20
0
        public void core0006T()
        {
            string computedValue = "";
            string expectedValue = "98551";

            System.Xml.XmlText oldTextNode = null;
            System.Xml.XmlText newTextNode = null;
            System.Xml.XmlNode testNode    = null;

            testResults results = new testResults("Core0006T");

            try
            {
                results.description = "The \"splitText(offset)\" method returns the " +
                                      "new Text node.";
                //
                // Retrieve the targeted data.
                //
                testNode    = util.nodeObject(util.FIRST, util.SIXTH);
                oldTextNode = (System.Xml.XmlText)testNode.FirstChild;
                //
                // Split the two lines of text into two different Text nodes.
                //
                newTextNode   = oldTextNode.SplitText(30);
                computedValue = newTextNode.Value;
            }
            catch (System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }
            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual   = computedValue;

            util.resetData();

            Assert.AreEqual(results.expected, results.actual);
        }
Beispiel #21
0
        /// <summary> Encodes a Primitive in XML by adding it's value as a child of the given Element.
        /// Returns true if the given Primitive contains a value.
        /// </summary>
        private bool encodePrimitive(Primitive datatypeObject, System.Xml.XmlElement datatypeElement)
        {
            bool hasValue = false;

            if (datatypeObject.Value != null && !datatypeObject.Value.Equals(""))
            {
                hasValue = true;
            }

            System.Xml.XmlText t = datatypeElement.OwnerDocument.CreateTextNode(datatypeObject.Value);
            if (hasValue)
            {
                try
                {
                    datatypeElement.AppendChild(t);
                }
                catch (System.Exception e)
                {
                    throw new DataTypeException("DOMException encoding Primitive: ", e);
                }
            }
            return(hasValue);
        }
		public void SetUp()
		{
			treeViewContainerControl = new DerivedXmlTreeViewContainerControl();
			treeView = treeViewContainerControl.TreeView;
			treeViewContainerControl.LoadXml(GetXml());
			doc = treeViewContainerControl.Document;
			
			clipboardHandler = treeViewContainerControl as IClipboardHandler;
			
			htmlElement = doc.DocumentElement;
			bodyElement = htmlElement.FirstChild as XmlElement;
			paragraphElement = bodyElement.SelectSingleNode("p") as XmlElement;
			paragraphText = paragraphElement.SelectSingleNode("text()") as XmlText;
			bodyComment = bodyElement.SelectSingleNode("comment()") as XmlComment;
			
			htmlTreeNode = treeView.Nodes[0] as XmlElementTreeNode;
			htmlTreeNode.PerformInitialization();
			bodyTreeNode = htmlTreeNode.FirstNode as XmlElementTreeNode;
			bodyTreeNode.PerformInitialization();
			bodyCommentTreeNode = bodyTreeNode.FirstNode as XmlCommentTreeNode;
			paragraphTreeNode = bodyTreeNode.LastNode as XmlElementTreeNode;
			paragraphTreeNode.PerformInitialization();
			paragraphTextTreeNode = paragraphTreeNode.FirstNode as XmlTextTreeNode;
		}
		/// <summary>
		/// Removes the specified text node from the tree.
		/// </summary>
		public void RemoveTextNode(XmlText textNode)
		{
			XmlTextTreeNode node = FindTextNode(textNode);
			if (node != null) {
				node.Remove();
			}
		}
		/// <summary>
		/// Appends a new child text node to the currently selected element.
		/// </summary>
		public void AppendChildTextNode(XmlText textNode)
		{
			XmlElementTreeNode selectedNode = SelectedElementNode;
			if (selectedNode != null) {
				XmlTextTreeNode newNode = new XmlTextTreeNode(textNode);
				newNode.AddTo(selectedNode);
				selectedNode.Expand();
			}
		}
Beispiel #25
0
 private void AddXmlText(StringBuilder sb, int indentationLevel, XmlText xmlText)
 {
     Indent(sb, indentationLevel);
     sb.Append(string.Format(@"\cf{0}{1}\par", (int)ColorKinds.Value, XmlEncode(xmlText.Value)));
 }
Beispiel #26
0
        private XmlNode LoadNodeDirect()
        {
            XmlNode   node2;
            XmlReader reader     = this.reader;
            XmlNode   parentNode = null;

Label_0009:
            node2 = null;
            switch (reader.NodeType)
            {
            case XmlNodeType.Element:
            {
                bool       isEmptyElement = this.reader.IsEmptyElement;
                XmlElement newChild       = new XmlElement(this.reader.Prefix, this.reader.LocalName, this.reader.NamespaceURI, this.doc)
                {
                    IsEmpty = isEmptyElement
                };
                if (this.reader.MoveToFirstAttribute())
                {
                    XmlAttributeCollection attributes = newChild.Attributes;
                    do
                    {
                        XmlAttribute attribute = this.LoadAttributeNodeDirect();
                        attributes.Append(attribute);
                    }while (reader.MoveToNextAttribute());
                }
                if (!isEmptyElement)
                {
                    parentNode.AppendChildForLoad(newChild, this.doc);
                    parentNode = newChild;
                    goto Label_01FC;
                }
                node2 = newChild;
                break;
            }

            case XmlNodeType.Attribute:
                node2 = this.LoadAttributeNodeDirect();
                break;

            case XmlNodeType.Text:
                node2 = new XmlText(this.reader.Value, this.doc);
                break;

            case XmlNodeType.CDATA:
                node2 = new XmlCDataSection(this.reader.Value, this.doc);
                break;

            case XmlNodeType.EntityReference:
                node2 = this.LoadEntityReferenceNode(true);
                break;

            case XmlNodeType.ProcessingInstruction:
                node2 = new XmlProcessingInstruction(this.reader.Name, this.reader.Value, this.doc);
                break;

            case XmlNodeType.Comment:
                node2 = new XmlComment(this.reader.Value, this.doc);
                break;

            case XmlNodeType.Whitespace:
                if (!this.preserveWhitespace)
                {
                    goto Label_01FC;
                }
                node2 = new XmlWhitespace(this.reader.Value, this.doc);
                break;

            case XmlNodeType.SignificantWhitespace:
                node2 = new XmlSignificantWhitespace(this.reader.Value, this.doc);
                break;

            case XmlNodeType.EndElement:
                if (parentNode.ParentNode != null)
                {
                    parentNode = parentNode.ParentNode;
                    goto Label_01FC;
                }
                return(parentNode);

            case XmlNodeType.EndEntity:
                goto Label_01FC;

            default:
                throw UnexpectedNodeType(this.reader.NodeType);
            }
            if (parentNode != null)
            {
                parentNode.AppendChildForLoad(node2, this.doc);
            }
            else
            {
                return(node2);
            }
Label_01FC:
            if (reader.Read())
            {
                goto Label_0009;
            }
            return(null);
        }
		/// <summary>
		/// Shows the corresponding tree node with the ghosted image 
		/// that indicates it is being cut.
		/// </summary>
		void ShowCutTextNode(XmlText textNode, bool showGhostImage)
		{
			XmlTextTreeNode node = FindTextNode(textNode);
			node.ShowGhostImage = showGhostImage;
		}
		/// <summary>
		/// Looks at all the nodes in the tree view and returns the
		/// tree node that represents the specified text node.
		/// </summary>
		XmlTextTreeNode FindTextNode(XmlText textNode, TreeNodeCollection nodes)
		{
			foreach (ExtTreeNode node in nodes) {
				XmlTextTreeNode textTreeNode = node as XmlTextTreeNode;
				if (textTreeNode != null) {
					if (textTreeNode.XmlText == textNode) {
						return textTreeNode;
					}
				} else {
					// Look for a match in the node's child nodes.
					XmlTextTreeNode childTextTreeNode = FindTextNode(textNode, node.Nodes);
					if (childTextTreeNode != null) {
						return childTextTreeNode;
					}
				}
			}
			return null;
		}
		/// <summary>
		/// Updates the corresponding tree node's text based on 
		/// the textNode's value.
		/// </summary>
		public void UpdateTextNode(XmlText textNode)
		{
			XmlTextTreeNode node = FindTextNode(textNode);
			if (node != null) {
				node.Update();
			}
		}
		/// <summary>
		/// Appends a new text node to the currently selected
		/// element.
		/// </summary>
		public void AppendChildTextNode(XmlText textNode)
		{
			xmlElementTreeView.AppendChildTextNode(textNode);			
		}
Beispiel #31
0
        // Used by the ReadNode method for recursively building a DOM subtree.
        internal XmlNode ReadNodeInternal(XmlReader r)
        {
            switch (r.NodeType)
            {
            case XmlNodeType.Attribute:
            {
                // create the attribute
                XmlAttribute att = CreateAttribute
                                       (r.Prefix, r.LocalName, r.NamespaceURI);

                // read and append the children
                ReadChildren(r, att);

                // return the attribute
                return(att);
            }
            // Not reached.

            case XmlNodeType.CDATA:
            {
                // create the character data section
                XmlCDataSection cdata = CreateCDataSection(r.Value);

                // advance the reader to the next node
                r.Read();

                // return the character data section
                return(cdata);
            }
            // Not reached.

            case XmlNodeType.Comment:
            {
                // create the comment
                XmlComment comment = CreateComment(r.Value);

                // advance the reader to the next node
                r.Read();

                // return the comment
                return(comment);
            }
            // Not reached.

            case XmlNodeType.DocumentType:
            {
                // create the document type
                XmlDocumentType doctype = CreateDocumentType
                                              (r.Name, r["PUBLIC"], r["SYSTEM"], r.Value);

                // advance the reader to the next node
                r.Read();

                // return the document type
                return(doctype);
            }
            // Not reached.

            case XmlNodeType.Element:
            {
                // create the element
                XmlElement elem = CreateElement
                                      (r.Prefix, r.LocalName, r.NamespaceURI);
                bool isEmptyElement = r.IsEmptyElement;

                // read the attributes
                while (r.MoveToNextAttribute())
                {
                    XmlAttribute att = (XmlAttribute)ReadNodeInternal(r);
                    elem.SetAttributeNode(att);
                }
                r.MoveToElement();

                // return now if there are no children
                if (isEmptyElement)
                {
                    // advance the reader to the next node
                    r.Read();

                    // return the empty element
                    return(elem);
                }

                elem.IsEmpty = isEmptyElement;

                // read and append the children
                ReadChildren(r, elem);

                // return the element
                return(elem);
            }
            // Not reached.

            case XmlNodeType.DocumentFragment:
            case XmlNodeType.EndElement:
            case XmlNodeType.EndEntity:
            case XmlNodeType.Entity:
            case XmlNodeType.Notation:
            {
                // TODO

                // advance the reader to the next node
                r.Read();

                // nothing to return
                return(null);
            }
            // Not reached.

            case XmlNodeType.EntityReference:
            {
                // create the entity reference
                XmlEntityReference er = CreateEntityReference(r.Name);

                // advance the reader to the next node
                r.Read();

                // return the entity reference
                return(er);
            }
            // Not reached.

            case XmlNodeType.ProcessingInstruction:
            {
                // create the processing instruction
                XmlProcessingInstruction pi = CreateProcessingInstruction
                                                  (r.Name, r.Value);

                // advance the reader to the next node
                r.Read();

                // return the processing instruction
                return(pi);
            }
            // Not reached.

            case XmlNodeType.SignificantWhitespace:
            {
                // create the significant whitespace
                XmlSignificantWhitespace sws = CreateSignificantWhitespace
                                                   (r.Value);

                // advance the reader to the next node
                r.Read();

                // return the significant whitespace
                return(sws);
            }
            // Not reached.

            case XmlNodeType.Text:
            {
                // create the text
                XmlText text = CreateTextNode(r.Value);

                // advance the reader to the next node
                r.Read();

                // return the text
                return(text);
            }
            // Not reached.

            case XmlNodeType.Whitespace:
            {
                // if whitespace preservation is off, skip whitespace
                if (!preserveWhitespace)
                {
                    while (r.Read())
                    {
                        if (r.NodeType != XmlNodeType.Whitespace)
                        {
                            return(null);
                        }
                    }
                    return(null);
                }

                // create the whitespace
                XmlWhitespace ws = CreateWhitespace(r.Value);

                // advance the reader to the next node
                r.Read();

                // return the whitespace
                return(ws);
            }
            // Not reached.

            case XmlNodeType.XmlDeclaration:
            {
                // set up the defaults
                String e = String.Empty;
                String s = String.Empty;

                // read the version
                r.MoveToNextAttribute();

                // read the optional attributes
                if (r.MoveToNextAttribute())
                {
                    if (r.Name == "encoding")
                    {
                        e = r.Value;
                        if (r.MoveToNextAttribute())
                        {
                            s = r.Value;
                        }
                    }
                    else
                    {
                        s = r.Value;
                    }
                }

                // create the xml declaration
                XmlDeclaration xml = CreateXmlDeclaration("1.0", e, s);

                // advance the reader to the next node
                r.Read();

                // return the xml declaration
                return(xml);
            }
            // Not reached.

            default:
            {
                throw new InvalidOperationException(/* TODO */);
            }
                // Not reached.
            }
        }
Beispiel #32
0
Datei: Remove.cs Projekt: rh/mix
 protected override void ExecuteCore(XmlText text)
 {
     text.ParentNode.RemoveChild(text);
 }
 public void UpdateTextNode(XmlText textNode)
 {
     textNodesUpdated.Add(textNode);
 }
Beispiel #34
0
        private XmlNode LoadEntityChildren()
        {
            XmlNode node = null;

            // We do not use creator functions on XmlDocument, b/c we do not want to let users extend the nodes that are children of entity nodes (also, if we do
            // this, XmlDataDocument will have a problem, b/c they do not know that those nodes should not be mapped).
            switch (reader.NodeType)
            {
            case XmlNodeType.EndElement:
            case XmlNodeType.EndEntity:
                break;

            case XmlNodeType.Element: {
                bool fEmptyElement = reader.IsEmptyElement;

                XmlElement element = new XmlElement(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
                element.IsEmpty = fEmptyElement;

                while (reader.MoveToNextAttribute())
                {
                    XmlAttribute attr = (XmlAttribute)LoadEntityChildren();
                    element.Attributes.Append(attr);
                }

                // recursively load all children.
                if (!fEmptyElement)
                {
                    LoadEntityChildren(element);
                }

                node = element;
                break;
            }

            case XmlNodeType.Attribute:
                if (reader.IsDefault)
                {
                    XmlUnspecifiedAttribute attr = new XmlUnspecifiedAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
                    LoadEntityAttributeChildren(attr);
                    attr.SetSpecified(false);
                    node = attr;
                }
                else
                {
                    XmlAttribute attr = new XmlAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
                    LoadEntityAttributeChildren(attr);
                    node = attr;
                }
                break;

            case XmlNodeType.SignificantWhitespace:
                node = new XmlSignificantWhitespace(reader.Value, this.doc);
                break;

            case XmlNodeType.Whitespace:
                if (preserveWhitespace)
                {
                    node = new XmlWhitespace(reader.Value, this.doc);
                }
                else
                {
                    // if preserveWhitespace is false skip all subsequent WS nodes and position on the first non-WS node
                    do
                    {
                        if (!reader.Read())
                        {
                            return(null);
                        }
                    } while (reader.NodeType == XmlNodeType.Whitespace);
                    node = LoadEntityChildren();       // Skip WS node if preserveWhitespace is false
                }
                break;

            case XmlNodeType.Text:
                node = new XmlText(reader.Value, this.doc);
                break;

            case XmlNodeType.CDATA:
                node = new XmlCDataSection(reader.Value, this.doc);
                break;

            case XmlNodeType.EntityReference: {
                XmlEntityReference eref = new XmlEntityReference(reader.Name, this.doc);
                if (reader.CanResolveEntity)
                {
                    reader.ResolveEntity();
                    LoadEntityChildren(eref);
                    //what if eref doesn't have children at all? should we just put a Empty String text here?
                    if (eref.ChildNodes.Count == 0)
                    {
                        eref.AppendChild(new XmlText(""));
                    }
                }
                node = eref;
                break;
            }

            case XmlNodeType.ProcessingInstruction:
                node = new XmlProcessingInstruction(reader.Name, reader.Value, this.doc);
                break;

            case XmlNodeType.Comment:
                node = new XmlComment(reader.Value, this.doc);
                break;

            default:
                throw new InvalidOperationException(string.Format(Res.GetString(Res.Xdom_Load_NodeType), reader.NodeType.ToString()));
            }

            return(node);
        }
Beispiel #35
0
        public override XmlNode CloneNode(bool deep)
        {
            XmlText newText = OwnerDocument.CreateTextNode(Data);

            return(newText);
        }
		/// <summary>
		/// Inserts a text node before the currently selected
		/// node.
		/// </summary>
		public void InsertTextNodeBefore(XmlText textNode)
		{
			InsertTextNode(textNode, InsertionMode.Before);
		}
		/// <summary>
		/// Inserts a new text node before the currently selected
		/// node.
		/// </summary>
		public void InsertTextNodeBefore(XmlText textNode)
		{
			xmlElementTreeView.InsertTextNodeBefore(textNode);
		}
		/// <summary>
		/// Inserts a text node after the currently selected
		/// node.
		/// </summary>
		public void InsertTextNodeAfter(XmlText textNode)
		{
			InsertTextNode(textNode, InsertionMode.After);
		}
		/// <summary>
		/// Inserts a new text node after the currently selected
		/// node.
		/// </summary>
		public void InsertTextNodeAfter(XmlText textNode)
		{
			xmlElementTreeView.InsertTextNodeAfter(textNode);
		}
		/// <summary>
		/// Inserts a new text node either before or after the 
		/// currently selected node.
		/// </summary>
		void InsertTextNode(XmlText textNode, InsertionMode insertionMode)
		{
			ExtTreeNode selectedNode = (ExtTreeNode)SelectedNode;
			if (selectedNode != null) {
				XmlElementTreeNode parentNode = (XmlElementTreeNode)selectedNode.Parent;
				XmlTextTreeNode newNode = new XmlTextTreeNode(textNode);
				int index = parentNode.Nodes.IndexOf(selectedNode);
				if (insertionMode == InsertionMode.After) {
					index++;
				}
				newNode.Insert(index, parentNode);
			}
		}
		/// <summary>
		/// Removes the currently selected text node.
		/// </summary>
		public void RemoveTextNode(XmlText textNode)
		{
			xmlElementTreeView.RemoveTextNode(textNode);
		}
		/// <summary>
		/// Finds the specified text node in the tree.
		/// </summary>
		XmlTextTreeNode FindTextNode(XmlText textNode)
		{
			XmlTextTreeNode selectedTextTreeNode = SelectedNode as XmlTextTreeNode;
			if (selectedTextTreeNode != null && selectedTextTreeNode.XmlText == textNode) {
				return selectedTextTreeNode;
			} else {
				return FindTextNode(textNode, Nodes);
			}
		}
		/// <summary>
		/// Updates the corresponding tree node's text.
		/// </summary>
		public void UpdateTextNode(XmlText textNode)
		{
			xmlElementTreeView.UpdateTextNode(textNode);
		}
Beispiel #44
0
        // LoadNodeDirect does not use creator functions on XmlDocument. It is used loading nodes that are children of entity nodes,
        // because we do not want to let users extend these (if we would allow this, XmlDataDocument would have a problem, because
        // they do not know that those nodes should not be mapped). It can be also used for an optimized load path when if the
        // XmlDocument is not extended if XmlDocumentType and XmlDeclaration handling is added.
        private XmlNode LoadNodeDirect()
        {
            XmlReader r      = _reader;
            XmlNode   parent = null;

            do
            {
                XmlNode node = null;
                switch (r.NodeType)
                {
                case XmlNodeType.Element:
                    bool       fEmptyElement = _reader.IsEmptyElement;
                    XmlElement element       = new XmlElement(_reader.Prefix, _reader.LocalName, _reader.NamespaceURI, _doc);
                    element.IsEmpty = fEmptyElement;

                    if (_reader.MoveToFirstAttribute())
                    {
                        XmlAttributeCollection attributes = element.Attributes;
                        do
                        {
                            XmlAttribute attr = LoadAttributeNodeDirect();
                            attributes.Append(attr);     // special case for load
                        } while (r.MoveToNextAttribute());
                    }

                    // recursively load all children.
                    if (!fEmptyElement)
                    {
                        parent.AppendChildForLoad(element, _doc);
                        parent = element;
                        continue;
                    }
                    else
                    {
                        node = element;
                        break;
                    }

                case XmlNodeType.EndElement:
                    Debug.Assert(parent.NodeType == XmlNodeType.Element);
                    if (parent.ParentNode == null)
                    {
                        return(parent);
                    }
                    parent = parent.ParentNode;
                    continue;

                case XmlNodeType.EntityReference:
                    node = LoadEntityReferenceNode(true);
                    break;

                case XmlNodeType.EndEntity:
                    continue;

                case XmlNodeType.Attribute:
                    node = LoadAttributeNodeDirect();
                    break;

                case XmlNodeType.SignificantWhitespace:
                    node = new XmlSignificantWhitespace(_reader.Value, _doc);
                    break;

                case XmlNodeType.Whitespace:
                    if (_preserveWhitespace)
                    {
                        node = new XmlWhitespace(_reader.Value, _doc);
                    }
                    else
                    {
                        continue;
                    }
                    break;

                case XmlNodeType.Text:
                    node = new XmlText(_reader.Value, _doc);
                    break;

                case XmlNodeType.CDATA:
                    node = new XmlCDataSection(_reader.Value, _doc);
                    break;

                case XmlNodeType.ProcessingInstruction:
                    node = new XmlProcessingInstruction(_reader.Name, _reader.Value, _doc);
                    break;

                case XmlNodeType.Comment:
                    node = new XmlComment(_reader.Value, _doc);
                    break;

                default:
                    throw UnexpectedNodeType(_reader.NodeType);
                }

                Debug.Assert(node != null);
                if (parent != null)
                {
                    parent.AppendChildForLoad(node, _doc);
                }
                else
                {
                    return(node);
                }
            }while (r.Read());

            return(null);
        }
        private void ValidateElement()
        {
            _nsManager.PushScope();
            XmlElement elementNode = _currentNode as XmlElement;

            Debug.Assert(elementNode != null);

            XmlAttributeCollection attributes = elementNode.Attributes;
            XmlAttribute           attr       = null;

            //Find Xsi attributes that need to be processed before validating the element
            string xsiNil  = null;
            string xsiType = null;

            for (int i = 0; i < attributes.Count; i++)
            {
                attr = attributes[i];
                string objectNs   = attr.NamespaceURI;
                string objectName = attr.LocalName;
                Debug.Assert(_nameTable.Get(attr.NamespaceURI) != null);
                Debug.Assert(_nameTable.Get(attr.LocalName) != null);

                if (Ref.Equal(objectNs, _nsXsi))
                {
                    if (Ref.Equal(objectName, _xsiType))
                    {
                        xsiType = attr.Value;
                    }
                    else if (Ref.Equal(objectName, _xsiNil))
                    {
                        xsiNil = attr.Value;
                    }
                }
                else if (Ref.Equal(objectNs, _nsXmlNs))
                {
                    _nsManager.AddNamespace(attr.Prefix.Length == 0 ? string.Empty : attr.LocalName, attr.Value);
                }
            }
            _validator.ValidateElement(elementNode.LocalName, elementNode.NamespaceURI, _schemaInfo, xsiType, xsiNil, null, null);
            ValidateAttributes(elementNode);
            _validator.ValidateEndOfAttributes(_schemaInfo);

            //If element has children, drill down
            for (XmlNode child = elementNode.FirstChild; child != null; child = child.NextSibling)
            {
                ValidateNode(child);
            }
            //Validate end of element
            _currentNode = elementNode; //Reset current Node for validation call back
            _validator.ValidateEndElement(_schemaInfo);
            //Get XmlName, as memberType / validity might be set now
            if (_psviAugmentation)
            {
                elementNode.XmlName = _document.AddXmlName(elementNode.Prefix, elementNode.LocalName, elementNode.NamespaceURI, _schemaInfo);
                if (_schemaInfo.IsDefault)
                { //the element has a default value
                    XmlText textNode = _document.CreateTextNode(_schemaInfo.SchemaElement.ElementDecl.DefaultValueRaw);
                    elementNode.AppendChild(textNode);
                }
            }

            _nsManager.PopScope(); //Pop current namespace scope
        }