示例#1
0
        // Set an attribute to a specific value.
        public virtual void SetAttribute(String name, String value)
        {
            XmlAttribute attr = GetAttributeNode(name);

            if (attr != null)
            {
                attr.Value = value;
            }
            else
            {
                attr       = OwnerDocument.CreateAttribute(name);
                attr.Value = value;
                /* TODO : figure out if this is better done lower down */
                attr.parent = this;
                Attributes.Append(attr);
            }
        }
示例#2
0
        // Sets the value of the attribute with the specified name
        // and namespace.
        public virtual string SetAttribute(string localName, string namespaceURI, string value)
        {
            XmlAttribute attr = GetAttributeNode(localName, namespaceURI);

            if (attr == null)
            {
                attr       = OwnerDocument.CreateAttribute(string.Empty, localName, namespaceURI);
                attr.Value = value;
                Attributes.InternalAppendAttribute(attr);
            }
            else
            {
                attr.Value = value;
            }

            return(value);
        }
示例#3
0
        /// <summary>
        /// Insert a row into this section.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public HtmlElement InsertRow(int index = -1)
        {
            var row = (HtmlElement)OwnerDocument.CreateElement(TagsNames.Tr);

            var rows = Rows;

            if (rows.Count == 0 || index == -1)
            {
                AppendChild(row);
            }
            else
            {
                InsertBefore(row, rows[index]);
            }

            return(row);
        }
示例#4
0
        /// <summary>
        /// Insert an empty TD cell into this row.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public HtmlElement InsertCell(int index = -1)
        {
            var newCell = (HtmlElement)OwnerDocument.CreateElement("td");

            var cells = Cells;

            if (cells.Count == 0 || index == -1)
            {
                AppendChild(newCell);
            }

            var cell = Cells[index];

            InsertBefore(newCell, cell);

            return(newCell);
        }
示例#5
0
        public void CreateList()
        {
            string  eleNode = PageName + "UserCreateNumber";
            XmlNode node    = OwnerDocument.SelectSingleNode("//" + eleNode + "");

            if (node != null && node is XmlElement)
            {
                list = new List <string>();
                foreach (XmlElement ele in node.ChildNodes)
                {
                    if (!string.IsNullOrEmpty(ele.GetAttribute("number")))
                    {
                        string index = ele.GetAttribute("number");
                        list.Add(index);
                    }
                }
            }
        }
示例#6
0
        public void CreateList()
        {
            string  eleNode = PageName + "CreateNumber";
            XmlNode node    = OwnerDocument.SelectSingleNode("//" + eleNode + "");

            if (node != null && node is XmlElement)
            {
                list = new List <int>();
                foreach (XmlElement ele in node.ChildNodes)
                {
                    if (!string.IsNullOrEmpty(ele.GetAttribute("number")))
                    {
                        int index = Utility.Convert.PxStringToInt(ele.GetAttribute("number").Substring(4));
                        list.Add(index);
                    }
                }
            }
        }
示例#7
0
        // Set an attribute to a specific value.
        public virtual String SetAttribute
            (String localName, String namespaceURI, String value)
        {
            XmlAttribute attr = GetAttributeNode(localName, namespaceURI);

            if (attr != null)
            {
                attr.Value = value;
            }
            else
            {
                attr = OwnerDocument.CreateAttribute
                           (localName, namespaceURI);
                attr.Value = value;
                Attributes.Append(attr);
            }
            return(attr.Value);
        }
示例#8
0
        public bool ReplaceCommentNode(string origCommentLine, string newCommentLine)
        {
            ChoIniCommentNode newCommentNode = new ChoIniCommentNode(OwnerDocument, newCommentLine);
            ChoIniCommentNode commentNode    = GetCommentNode(origCommentLine);

            if (!OwnerDocument.OnNodeChanging(this, commentNode, newCommentNode, ChoIniNodeChangedAction.ReplaceNode))
            {
                OwnerDocument.Dirty = true;
                object oldValue = commentNode;
                commentNode.Value = newCommentLine;
                OwnerDocument.OnNodeChanged(this, oldValue, newCommentNode, ChoIniNodeChangedAction.ReplaceNode);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#9
0
 /// <summary>
 /// Add a child element.  The element can be from a different document.
 /// </summary>
 /// <param name="value"></param>
 public void AddChild(XmlElement value)
 {
     if (OwnerDocument == value.OwnerDocument)
     {
         AppendChild(value);
     }
     else
     {
         var element = value as Element;
         if (element != null)
         {
             AppendChild(element.CloneNode(true, OwnerDocument));
         }
         else
         {
             AppendChild(OwnerDocument.ImportNode(value, true));
         }
     }
 }
示例#10
0
        private void SelectAtomObject_Do(string mediaType, MediaItemViewModel file, bool asAnswer)
        {
            var index = CurrentPosition;

            if (index == -1)
            {
                index = Count - 1;
            }

            OwnerDocument.BeginChange();

            try
            {
                if (asAnswer)
                {
                    if (!_isComplex)
                    {
                        AddMarker_Executed(null);
                        index = Count - 1;
                    }
                }
                else if (string.IsNullOrWhiteSpace(this[index].Model.Text))
                {
                    RemoveAt(index--);
                }

                var atom = new AtomViewModel(new Atom {
                    Type = mediaType, Text = ""
                });
                Insert(index + 1, atom);

                OwnerDocument.Document.SetLink(atom.Model, file.Model.Name);
                OwnerDocument.ActiveItem = null;
            }
            catch (Exception exc)
            {
                OwnerDocument.OnError(exc);
            }
            finally
            {
                OwnerDocument.CommitChange();
            }
        }
示例#11
0
        // Clone this node in either shallow or deep mode.
        public override XmlNode CloneNode(bool deep)
        {
            XmlElement clone = OwnerDocument.CreateElement
                                   (Prefix, LocalName, NamespaceURI);

            if (attributes != null)
            {
                foreach (XmlAttribute attr in Attributes)
                {
                    clone.Attributes.Append
                        ((XmlAttribute)(attr.CloneNode(true)));
                }
            }
            if (deep)
            {
                clone.CloneChildrenFrom(this, deep);
            }
            return(clone);
        }
示例#12
0
        void SetEntityContent()
        {
            if (lastLinkedChild != null)
            {
                return;
            }

            XmlDocumentType doctype = OwnerDocument.DocumentType;

            if (doctype == null)
            {
                return;
            }

#if NOT_PFX
            DTDEntityDeclaration decl = doctype.DTD.EntityDecls [name];
            if (decl == null)
            {
                return;
            }

            XmlNamespaceManager nsmgr = this.ConstructNamespaceManager();

            XmlParserContext ctx = new XmlParserContext(OwnerDocument.NameTable, nsmgr,
                                                        doctype != null ? doctype.DTD : null,
                                                        BaseURI, XmlLang, XmlSpace, null);

            XmlTextReader xmlReader = new XmlTextReader(decl.EntityValue, XmlNodeType.Element, ctx);

            xmlReader.XmlResolver = OwnerDocument.Resolver;

            do
            {
                XmlNode n = OwnerDocument.ReadNode(xmlReader);
                if (n == null)
                {
                    break;
                }
                InsertBefore(n, null, false, false);
            } while (true);
#endif
        }
示例#13
0
        internal bool InsertBeforeIniNode(int index, ChoIniNode iniNode)
        {
            if (!OwnerDocument.OnNodeInserting(this, iniNode))
            {
                OwnerDocument.Dirty = true;
                if (index - 1 < 0)
                {
                    _iniNodes.Insert(0, iniNode);
                }
                else
                {
                    _iniNodes.Insert(index - 1, iniNode);
                }

                OwnerDocument.OnNodeInserted(this, iniNode);
                return(true);
            }

            return(false);
        }
示例#14
0
        internal bool InsertAfterIniNode(int index, ChoIniNode iniNode)
        {
            if (!OwnerDocument.OnNodeInserting(this, iniNode))
            {
                OwnerDocument.Dirty = true;
                if (index + 1 >= _iniNodes.Count)
                {
                    _iniNodes.Add(iniNode);
                }
                else
                {
                    _iniNodes.Insert(index + 1, iniNode);
                }

                OwnerDocument.OnNodeInserted(this, iniNode);
                return(true);
            }

            return(false);
        }
示例#15
0
        // Split this node in two.
        public virtual XmlText SplitText(int offset)
        {
            int length = Length;

            if (offset < 0)
            {
                offset = 0;
            }
            else if (offset > length)
            {
                offset = length;
            }
            String  data = Data;
            XmlText node;

            node = OwnerDocument.CreateTextNode(data.Substring(offset));
            Data = data.Substring(0, offset);
            parent.InsertAfter(node, this);
            return(node);
        }
示例#16
0
        private void LoadExample(NXmlElement element)
        {
            string groupNamespace = NExamplesHomePage.GetNamespace(element);
            string name           = element.GetAttributeValue("name");
            string type           = groupNamespace + "." + element.GetAttributeValue("type");

            try
            {
                type = "Nevron.Nov.Examples." + type;
                Type exampleType = Type.GetType(type);
                if (exampleType != null)
                {
                    NDomType domType = NDomType.FromType(exampleType);
                    NDebug.Assert(domType != null, "The example type:" + type + " is not a valid type");

                    // Create the example
                    DateTime     start   = DateTime.Now;
                    NExampleBase example = domType.CreateInstance() as NExampleBase;
                    example.Title = name;
                    example.Initialize();
                    m_Splitter.Pane2.Content = example;

                    string stats = "Example created in: " + (DateTime.Now - start).TotalSeconds + " seconds, ";

                    // Evaluate the example
                    start = DateTime.Now;
                    OwnerDocument.Evaluate();
                    stats += " evaluated in: " + (DateTime.Now - start).TotalSeconds + " seconds";

                    m_StatusLabel.Text = stats;
                }

                // Set the breadcrumb
                CreateBreadcrumb(element);
            }
            catch (Exception ex)
            {
                NTrace.WriteException("Failed to load example", ex);
                m_Splitter.Pane2.Content = new NErrorPanel("Failed to load example. Exception was: " + ex.Message);
            }
        }
示例#17
0
        public override XmlNode CloneNode(bool deep)
        {
            XmlElement node = OwnerDocument.CreateElement(
                name.Prefix, name.LocalName, name.NS, true);

            for (int i = 0; i < Attributes.Count; i++)
            {
                node.SetAttributeNode((XmlAttribute)
                                      Attributes [i].CloneNode(true));
            }

            if (deep)
            {
                for (int i = 0; i < ChildNodes.Count; i++)
                {
                    node.AppendChild(ChildNodes [i].CloneNode(true), false);
                }
            }

            return(node);
        }
示例#18
0
        //public bool Remove(ChoIniNode iniNode)
        //{
        //    if (iniNode == null)
        //        return false;

        //    if (_iniNodes.Contains(iniNode))
        //    {
        //        _iniNodes.Remove(iniNode);
        //        return true;
        //    }
        //    else
        //        return false;
        //}

        public bool Remove(ChoIniNode iniNode)
        {
            ChoGuard.ArgumentNotNull(iniNode, "Node");

            int index = _iniNodes.FindIndex((node) => node == iniNode);

            if (index < 0)
            {
                throw new ChoIniDocumentException(String.Format("Can't find node. [Node: {0}]", iniNode, iniNode.ToString()));
            }

            if (!OwnerDocument.OnNodeRemoving(this, iniNode))
            {
                _iniNodes.RemoveAt(index);
                OwnerDocument.Dirty = true;
                OwnerDocument.OnNodeRemoved(this, iniNode);
                return(true);
            }

            return(false);
        }
示例#19
0
        public override bool Uncomment()
        {
            if (CommentChar == ChoChar.NUL)
            {
                return(false);
            }

            if (!OwnerDocument.OnNodeChanging(this, null, null, ChoIniNodeChangedAction.Uncomment))
            {
                OwnerDocument.Dirty = true;
                ResetCommentChar();
                foreach (ChoIniNode iniNode in _iniNodes)
                {
                    iniNode.Uncomment();
                }
                OwnerDocument.OnNodeChanged(this, null, null, ChoIniNodeChangedAction.Uncomment);

                return(true);
            }

            return(false);
        }
示例#20
0
        public override bool FromXML(System.Xml.XmlElement myElement)
        {
            if (null != myElement)
            {
                this.cells.Clear();

                foreach (XmlNode node in myElement.ChildNodes)
                {
                    if (node.Name == "table-cell")
                    {
                        TPTextCell cellEle = OwnerDocument.CreateElementByXML(node as XmlElement) as TPTextCell;
                        cellEle.Parent   = this;
                        cellEle.OwnerRow = this;

                        this.cells.Add(cellEle);
                        this.ChildElements.Add(cellEle);
                    }
                }
                return(true);
            }
            return(false);
        }
示例#21
0
        public override bool Comment(char commentChar)
        {
            if (CommentChar != ChoChar.NUL)
            {
                return(false);
            }

            if (!OwnerDocument.OnNodeChanging(this, null, null, ChoIniNodeChangedAction.Comment))
            {
                OwnerDocument.Dirty = true;
                CommentChar         = commentChar;
                foreach (ChoIniNode iniNode in _iniNodes)
                {
                    iniNode.Comment(commentChar);
                }
                OwnerDocument.OnNodeChanged(this, null, null, ChoIniNodeChangedAction.Comment);

                return(true);
            }

            return(false);
        }
示例#22
0
        public void DeleElement()
        {
            XmlNode node = OwnerDocument.SelectSingleNode("//userAddNumber");

            if (node == null)
            {
                return;
            }
            foreach (XmlElement ele in node.ChildNodes)
            {
                if (ele.Name.Equals(PageName + "UserCreateNumber"))
                {
                    foreach (XmlElement eleChild in ele.ChildNodes)
                    {
                        if (eleChild.GetAttribute("number").Equals(UserOldNumber))
                        {
                            ele.RemoveChild(eleChild);
                        }
                    }
                }
            }
        }
        public override XmlNode AppendChild(XmlNode newChild)
        {
            try
            {
#if OUTXML_CACHE
                outerXMLCache = null;
#endif
                if (newChild.OwnerDocument != OwnerDocument)
                {
                    if (newChild.NodeType == XmlNodeType.Text)
                    {
                        newChild = OwnerDocument.CreateTextNode(newChild.InnerText);
                    }
                }
                return(base.AppendChild(newChild));
            }
            catch (Exception e)
            {
                writeToLog("ERROR: newnode.AppendChild " + e);
                return(null);
            }
        }
示例#24
0
        public virtual void DeleteData(int offset, int count)
        {
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "Must be non-negative and must not be greater than the length of this instance.");
            }

            int newCount = data.Length - offset;

            if ((offset + count) < data.Length)
            {
                newCount = count;
            }

            string oldValue = data;
            string newValue = data.Remove(offset, newCount);

            OwnerDocument.onNodeChanging(this, this.ParentNode, oldValue, newValue);

            data = newValue;

            OwnerDocument.onNodeChanged(this, this.ParentNode, oldValue, newValue);
        }
示例#25
0
        protected override void CallDirectEventSubscribers(Event evt)
        {
            base.CallDirectEventSubscribers(evt);

            if (evt.Type == "click" && !evt.IsDefaultPrevented() && evt.Bubbles)
            {
                var href = Href.Trim();
                if (!href.StartsWith("JavaScript"))
                {
                    return;
                }

                var idx = href.IndexOf(':');
                if (idx < 0 || idx == href.Length - 1)
                {
                    return;
                }

                var code = href.Substring(idx + 1);

                OwnerDocument.HandleNodeScript(evt, code);
            }
        }
        public DomNode Wrap(DomContainer newParent)
        {
            if (newParent == null)
            {
                throw new ArgumentNullException(nameof(newParent));
            }

            if (OwnerDocument.DocumentElement == this)
            {
                // This is the document element, so we have to ensure that we
                // replace in such a way that there is only one document element
                // at a time
                RemoveSelf();
                OwnerDocument.Append(newParent);
                newParent.Append(this);
            }
            else if (ParentNode != null && !newParent.IsDocumentFragment)
            {
                After(newParent);
            }
            newParent.Append(this);
            return(newParent);
        }
示例#27
0
        // Splits the node into two nodes at the specified offset, keeping
        // both in the tree as siblings.
        public virtual XmlText SplitText(int offset)
        {
            XmlNode parentNode = this.ParentNode;
            int     length     = this.Length;

            if (offset > length)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            //if the text node is out of the living tree, throw exception.
            if (parentNode == null)
            {
                throw new InvalidOperationException(SR.Xdom_TextNode_SplitText);
            }

            int    count     = length - offset;
            string splitData = Substring(offset, count);

            DeleteData(offset, count);
            XmlText newTextNode = OwnerDocument.CreateTextNode(splitData);

            parentNode.InsertAfter(newTextNode, this);
            return(newTextNode);
        }
 // Creates a duplicate of this node.
 public override XmlNode CloneNode(bool deep)
 {
     Debug.Assert(OwnerDocument != null);
     return(OwnerDocument.CreateXmlDeclaration(Version, Encoding, Standalone));
 }
示例#29
0
        public override XmlNode CloneNode(bool deep)
        {
            XmlText newText = OwnerDocument.CreateTextNode(Data);

            return(newText);
        }
示例#30
0
 // Creates a duplicate of this node.
 public override XmlNode CloneNode(bool deep)
 {
     Debug.Assert(OwnerDocument != null);
     return(OwnerDocument.CreateTextNode(Data));
 }