public void Move4Test() { const string xml = "<xml><eins/><zwei/></xml>"; XmlDocument xmldoc = xml.ToXmlDocument(); var root = xmldoc.DocumentElement; var first = xmldoc.DocumentElement.FirstChild; string res = NodeMover.Move(root, first); }
public void Move2Test() { const string xml = "<xml><eins/><zwei/></xml>"; XmlDocument xmldoc = xml.ToXmlDocument(); var first = xmldoc.DocumentElement.FirstChild; var second = xmldoc.DocumentElement.LastChild; string res = NodeMover.Move(first, second); const string exp = "<xml><zwei><eins /></zwei></xml>"; StringAssert.Contains(res, exp); }
private void moveItem(TreeViewItem sourceItem, TreeViewItem targetItem) { ViewerNode source = (ViewerNode)sourceItem.Tag; ViewerNode target = (ViewerNode)targetItem.Tag; if (source == target) { return; } TaskDialogResult res = TaskDialog.Show( new TaskDialogOptions { AllowDialogCancellation = true, Owner = Application.Current.MainWindow, Title = "Move node", MainInstruction = "Where do you like to drop to source node?", Content = "Source: " + source + "\nTarget: " + target, CommandButtons = new[] { "Make child", "Insert before", "Insert after", "Cancel" }, MainIcon = VistaTaskDialogIcon.Information, ExpandedInfo = "Source: " + source.XPath + "\nTarget: " + target.XPath }); try { string newXml = null; switch (res.CommandButtonResult) { case 0: //make child newXml = NodeMover.Move(source.OriginalNode, target.OriginalNode); break; case 1: //insert before newXml = NodeMover.InsertBefore(source.OriginalNode, target.OriginalNode); break; case 2: //insert after newXml = NodeMover.InsertAfter(source.OriginalNode, target.OriginalNode); break; case 3: //cancel break; case null: //cancel by closing window break; default: Debug.Fail(""); break; } if (newXml != null) { Update(new XSDocument(newXml)); if (XmlChanged != null) { XmlChanged(newXml); } } } catch (Exception e) { MessageBox.Show(Application.Current.MainWindow, e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// When an answer's vary in repeat changes: /// - move the node /// - change its xpath /// - change the databinding in all relevant controls /// </summary> /// <param name="questionID"></param> /// <param name="xp"></param> /// <param name="answersPart"></param> public void moveIfNecessary(string questionID, xpathsXpath xp, Office.CustomXMLPart answersPart) { string varyInRepeat = getVaryingRepeat( ); if (varyInRepeat == null) { // make the answer top level and we're done. NodeMover nm = new NodeMover(); nm.Move(xp.dataBinding.xpath, "/oda:answers"); nm.adjustBinding(thisQuestionControls, "/oda:answers", questionID); } else { // Move it to the selected repeat // get the node corresponding to the repeat's row Office.CustomXMLNode node = answersPart.SelectSingleNode("//oda:repeat[@qref='" + varyInRepeat + "']/oda:row[1]"); if (node == null) { log.Error("no node for nested repeat " + varyInRepeat); } string toRepeat = NodeToXPath.getXPath(node); NodeMover nm = new NodeMover(); nm.Move(xp.dataBinding.xpath, toRepeat); nm.adjustBinding(thisQuestionControls, toRepeat, questionID); } }