// 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); } }
// 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); }
/// <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); }
/// <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); }
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); } } } }
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); } } } }
// 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); }
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); } }
/// <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)); } } }
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(); } }
// 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); }
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 }
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); }
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); }
// 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); }
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); } }
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); }
//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); }
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); }
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); }
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); }
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); } }
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); }
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); }
// 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)); }
public override XmlNode CloneNode(bool deep) { XmlText newText = OwnerDocument.CreateTextNode(Data); return(newText); }
// Creates a duplicate of this node. public override XmlNode CloneNode(bool deep) { Debug.Assert(OwnerDocument != null); return(OwnerDocument.CreateTextNode(Data)); }