public override void Do() { this.p = xe.ParentNode; // in case a prior command changed this! XmlAttribute a = null; if (autoGenPrefixes && XmlHelpers.MissingNamespace(name)) { a = XmlHelpers.GenerateNamespaceDeclaration(xe, name); } this.ne = xe.OwnerDocument.CreateElement(name.Prefix, name.LocalName, name.NamespaceUri); Redo(); if (a != null) { xmlns = new InsertNode(node, InsertPosition.Child, a, false, false); xmlns.Do(); } }
public override void Do() { XmlAttribute nsa = null; this.p = this.a.OwnerElement; // just in case a prior command changed this! if (autoGenPrefixes && XmlHelpers.MissingNamespace(name)) { nsa = XmlHelpers.GenerateNamespaceDeclaration(this.p, name); } this.na = a.OwnerDocument.CreateAttribute(name.Prefix, name.LocalName, name.NamespaceUri); this.na.Value = this.a.Value; // todo: copy children properly. Redo(); if (nsa != null) { xmlns = new InsertNode(node, InsertPosition.After, nsa, false, false); xmlns.Do(); } }
public ChangeNode(XmlTreeView view, XmlTreeNode node, XmlNodeType nt) { this.doc = view.Model.Document; this.nt = nt; this.view = view; this.node = node; XmlNode n = node.Node; if (n == null) return; init: this.oldnt = n.NodeType; string innerXml = (oldnt == XmlNodeType.Element) ? n.InnerXml : SpecialUnescape(oldnt, n.Value); string outerXml = n.OuterXml; string qname = n.Name; string localName = n.LocalName; string ns = n.NamespaceURI; bool noName = false; if (qname.StartsWith("#")) { qname = localName = ""; } noName = string.IsNullOrEmpty(qname); if (noName && IsNamedNodeType(nt)) { // Try parsing the content of the node as markup! (but first check for special unescaping // that we do for nested comment/cdata blocks) PasteCommand paste = new PasteCommand(doc, view, InsertPosition.Before, new TreeData(innerXml)); XmlTreeNode nte = paste.NewNode; if (nte != null && IsNamedNodeType(nte.NodeType)) { // then it worked - we extracted a node with a name, so start over. n = newNode = nte.Node; goto init; } } if (newNode == null || newNode.NodeType != nt) { switch (nt) { case XmlNodeType.Element: if (noName) { qname = "element"; } newNode = doc.CreateElement(qname, ns); newNode.InnerXml = innerXml; break; case XmlNodeType.Attribute: if (noName) { qname = "attribute"; } newNode = doc.CreateAttribute(qname, ns); newNode.Value = innerXml; break; case XmlNodeType.Comment: newNode = doc.CreateComment(SpecialEscape(nt, noName ? innerXml : outerXml)); break; case XmlNodeType.ProcessingInstruction: if (noName) { localName = "pi"; } newNode = doc.CreateProcessingInstruction(localName, innerXml); break; case XmlNodeType.Text: newNode = doc.CreateTextNode(noName ? innerXml : outerXml); break; case XmlNodeType.CDATA: newNode = doc.CreateCDataSection(SpecialEscape(nt, noName ? innerXml : outerXml)); break; } } InsertNode icmd = new InsertNode(node, InsertPosition.Before, newNode, true, true); newTreeNode = icmd.NewNode; DeleteNode del = new DeleteNode(doc, node); group = new CompoundCommand(this.Name); group.Add(icmd); group.Add(del); }
public override void Do() { if (td != null) { InsertNode icmd = new InsertNode(this.view); icmd.Initialize(source, this.target, position); this.cmd = icmd; this.cmd.Do(); if (this.source.Nodes.Count > 1) { this.source.Expand(); } } }