internal static XmlDiffPathNodeList SelectNodes( XmlDiffViewParentNode rootNode, XmlDiffViewParentNode currentParentNode, string xmlDiffPathExpr) { switch (xmlDiffPathExpr[0]) { case '*': if (xmlDiffPathExpr.Length == 1) { return(XmlDiffPath.SelectAllChildren(currentParentNode)); } XmlDiffPath.OnInvalidExpression(xmlDiffPathExpr); return((XmlDiffPathNodeList)null); case '/': return(XmlDiffPath.SelectAbsoluteNodes(rootNode, xmlDiffPathExpr)); case '@': if (xmlDiffPathExpr.Length < 2) { XmlDiffPath.OnInvalidExpression(xmlDiffPathExpr); } return(xmlDiffPathExpr[1] == '*' ? XmlDiffPath.SelectAllAttributes((XmlDiffViewElement)currentParentNode) : XmlDiffPath.SelectAttributes((XmlDiffViewElement)currentParentNode, xmlDiffPathExpr)); default: return(XmlDiffPath.SelectChildNodes(currentParentNode, xmlDiffPathExpr, 0)); } }
private static XmlDiffPathNodeList SelectAbsoluteNodes( XmlDiffViewParentNode rootNode, string path) { Debug.Assert(path[0] == '/'); var pos = 1; var node = (XmlDiffViewNode)rootNode; int startPos; while (true) { startPos = pos; var num = XmlDiffPath.ReadPosition(path, ref pos); if (pos == path.Length || path[pos] == '/') { if (node.FirstChildNode == null) { XmlDiffPath.OnNoMatchingNode(path); } var diffViewParentNode = (XmlDiffViewParentNode)node; if (num <= 0 || num > diffViewParentNode._sourceChildNodesCount) { XmlDiffPath.OnNoMatchingNode(path); } node = diffViewParentNode.GetSourceChildNode(num - 1); if (pos != path.Length) { ++pos; } else { break; } } else if (path[pos] != '-' && path[pos] != '|') { XmlDiffPath.OnInvalidExpression(path); } else { goto label_10; } } var diffPathNodeList = (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList(); diffPathNodeList.AddNode(node); return(diffPathNodeList); label_10: if (node.FirstChildNode == null) { XmlDiffPath.OnNoMatchingNode(path); } return(XmlDiffPath.SelectChildNodes((XmlDiffViewParentNode)node, path, startPos)); }
private static XmlDiffPathNodeList SelectAttributes( XmlDiffViewElement parentElement, string path) { Debug.Assert(path[0] == '@'); var pos = 1; var diffPathNodeList = (XmlDiffPathNodeList)null; while (true) { var name = XmlDiffPath.ReadAttrName(path, ref pos); if (diffPathNodeList == null) { diffPathNodeList = pos != path.Length ? (XmlDiffPathNodeList) new XmlDiffPathMultiNodeList() : (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList(); } var attribute = parentElement.GetAttribute(name); if (attribute == null) { XmlDiffPath.OnNoMatchingNode(path); } diffPathNodeList.AddNode((XmlDiffViewNode)attribute); if (pos != path.Length) { if (path[pos] == '|') { var index = pos + 1; if (path[index] != '@') { XmlDiffPath.OnInvalidExpression(path); } pos = index + 1; } else { XmlDiffPath.OnInvalidExpression(path); } } else { break; } } return(diffPathNodeList); }
private static XmlDiffPathNodeList SelectAllChildren( XmlDiffViewParentNode parentNode) { if (parentNode._childNodes == null) { XmlDiffPath.OnNoMatchingNode("*"); return((XmlDiffPathNodeList)null); } if (parentNode._childNodes._nextSibbling == null) { var diffPathNodeList = (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList(); diffPathNodeList.AddNode(parentNode._childNodes); return(diffPathNodeList); } var diffPathNodeList1 = (XmlDiffPathNodeList) new XmlDiffPathMultiNodeList(); for (var node = parentNode._childNodes; node != null; node = node._nextSibbling) { diffPathNodeList1.AddNode(node); } return(diffPathNodeList1); }
private static XmlDiffPathNodeList SelectAllAttributes( XmlDiffViewElement parentElement) { if (parentElement._attributes == null) { XmlDiffPath.OnNoMatchingNode("@*"); return((XmlDiffPathNodeList)null); } if (parentElement._attributes._nextSibbling == null) { var diffPathNodeList = (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList(); diffPathNodeList.AddNode((XmlDiffViewNode)parentElement._attributes); return(diffPathNodeList); } var diffPathNodeList1 = (XmlDiffPathNodeList) new XmlDiffPathMultiNodeList(); var attributes = parentElement._attributes; while (attributes != null) { diffPathNodeList1.AddNode((XmlDiffViewNode)attributes); } return(diffPathNodeList1); }
private void ApplyDiffgram(XmlNode diffgramParent, XmlDiffViewParentNode sourceParent) { sourceParent.CreateSourceNodesIndex(); XmlDiffViewNode currentPosition = null; var enumerator = diffgramParent.ChildNodes.GetEnumerator(); while (enumerator.MoveNext()) { if (((XmlNode)enumerator.Current).NodeType != XmlNodeType.Comment) { if (!(enumerator.Current is XmlElement)) { throw new Exception("Invalid node in diffgram."); } var current = enumerator.Current as XmlElement; if (current.NamespaceURI != "http://schemas.microsoft.com/xmltools/2002/xmldiff") { throw new Exception("Invalid element in diffgram."); } var attribute1 = current.GetAttribute("match"); XmlDiffPathNodeList matchNodes = null; if (attribute1 != string.Empty) { matchNodes = XmlDiffPath.SelectNodes(this._doc, sourceParent, attribute1); } switch (current.LocalName) { case "node": if (matchNodes.Count != 1) { throw new Exception("The 'match' attribute of 'node' element must select a single node."); } matchNodes.MoveNext(); if (current.ChildNodes.Count > 0) { this.ApplyDiffgram(current, (XmlDiffViewParentNode)matchNodes.Current); } currentPosition = matchNodes.Current; continue; case "add": if (attribute1 != string.Empty) { this.OnAddMatch(current, matchNodes, sourceParent, ref currentPosition); continue; } var attribute2 = current.GetAttribute("type"); if (attribute2 != string.Empty) { this.OnAddNode(current, attribute2, sourceParent, ref currentPosition); continue; } this.OnAddFragment(current, sourceParent, ref currentPosition); continue; case "remove": this.OnRemove(current, matchNodes, sourceParent, ref currentPosition); continue; case "change": this.OnChange(current, matchNodes, sourceParent, ref currentPosition); continue; default: continue; } } } }
private void ApplyDiffgram(XmlNode diffgramParent, XmlDiffViewParentNode sourceParent) { sourceParent.CreateSourceNodesIndex(); XmlDiffViewNode currentPosition = null; IEnumerator diffgramChildren = diffgramParent.ChildNodes.GetEnumerator(); while (diffgramChildren.MoveNext()) { XmlNode diffgramNode = (XmlNode)diffgramChildren.Current; if (diffgramNode.NodeType == XmlNodeType.Comment) { continue; } XmlElement diffgramElement = diffgramChildren.Current as XmlElement; if (diffgramElement == null) { throw new Exception("Invalid node in diffgram."); } if (diffgramElement.NamespaceURI != XmlDiff.NamespaceUri) { throw new Exception("Invalid element in diffgram."); } string matchAttr = diffgramElement.GetAttribute("match"); XmlDiffPathNodeList matchNodes = null; if (matchAttr != string.Empty) { matchNodes = XmlDiffPath.SelectNodes(_doc, sourceParent, matchAttr); } switch (diffgramElement.LocalName) { case "node": if (matchNodes.Count != 1) { throw new Exception("The 'match' attribute of 'node' element must select a single node."); } matchNodes.MoveNext(); if (diffgramElement.ChildNodes.Count > 0) { ApplyDiffgram(diffgramElement, (XmlDiffViewParentNode)matchNodes.Current); } currentPosition = matchNodes.Current; break; case "add": if (matchAttr != string.Empty) { OnAddMatch(diffgramElement, matchNodes, sourceParent, ref currentPosition); } else { string typeAttr = diffgramElement.GetAttribute("type"); if (typeAttr != string.Empty) { OnAddNode(diffgramElement, typeAttr, sourceParent, ref currentPosition); } else { OnAddFragment(diffgramElement, sourceParent, ref currentPosition); } } break; case "remove": OnRemove(diffgramElement, matchNodes, sourceParent, ref currentPosition); break; case "change": OnChange(diffgramElement, matchNodes, sourceParent, ref currentPosition); break; } } }
private static XmlDiffPathNodeList SelectChildNodes( XmlDiffViewParentNode parentNode, string path, int startPos) { var pos = startPos; XmlDiffPathNodeList diffPathNodeList; while (true) { int num1; do { num1 = XmlDiffPath.ReadPosition(path, ref pos); diffPathNodeList = pos != path.Length ? (XmlDiffPathNodeList) new XmlDiffPathMultiNodeList() : (XmlDiffPathNodeList) new XmlDiffPathSingleNodeList(); if (num1 <= 0 || num1 > parentNode._sourceChildNodesCount) { XmlDiffPath.OnNoMatchingNode(path); } diffPathNodeList.AddNode(parentNode.GetSourceChildNode(num1 - 1)); if (pos != path.Length) { if (path[pos] == '|') { ++pos; } } else { goto label_15; } }while (path[pos] != '-'); ++pos; var num2 = XmlDiffPath.ReadPosition(path, ref pos); if (num2 <= 0 || num2 > parentNode._sourceChildNodesCount) { XmlDiffPath.OnNoMatchingNode(path); } while (num1 < num2) { ++num1; diffPathNodeList.AddNode(parentNode.GetSourceChildNode(num1 - 1)); } if (pos != path.Length) { if (path[pos] == '|') { ++pos; } else { XmlDiffPath.OnInvalidExpression(path); } } else { break; } } label_15: return(diffPathNodeList); }