//ExEnd //ExStart //ExId:ExtractBetweenNodes_Helpers //ExSummary:The helper methods used by the ExtractContent method. /// <summary> /// Checks the input parameters are correct and can be used. Throws an exception if there is any problem. /// </summary> private static void VerifyParameterNodes(Node startNode, Node endNode) { // The order in which these checks are done is important. if (startNode == null) throw new ArgumentException("Start node cannot be null"); if (endNode == null) throw new ArgumentException("End node cannot be null"); if (!startNode.Document.Equals(endNode.Document)) throw new ArgumentException("Start node and end node must belong to the same document"); if (startNode.GetAncestor(NodeType.Body) == null || endNode.GetAncestor(NodeType.Body) == null) throw new ArgumentException("Start node and end node must be a child or descendant of a body"); // Check the end node is after the start node in the DOM tree // First check if they are in different sections, then if they're not check their position in the body of the same section they are in. Section startSection = (Section)startNode.GetAncestor(NodeType.Section); Section endSection = (Section)endNode.GetAncestor(NodeType.Section); int startIndex = startSection.ParentNode.IndexOf(startSection); int endIndex = endSection.ParentNode.IndexOf(endSection); if (startIndex == endIndex) { if (startSection.Body.IndexOf(startNode) > endSection.Body.IndexOf(endNode)) throw new ArgumentException("The end node must be after the start node in the body"); } else if (startIndex > endIndex) throw new ArgumentException("The section of end node must be after the section start node"); }
/// <summary> /// Checks if a node passed is an inline node. /// </summary> private static bool IsInline(Node node) { // Test if the node is desendant of a Paragraph or Table node and also is not a paragraph or a table a paragraph inside a comment class which is decesant of a pararaph is possible. return ((node.GetAncestor(NodeType.Paragraph) != null || node.GetAncestor(NodeType.Table) != null) && !(node.NodeType == NodeType.Paragraph || node.NodeType == NodeType.Table)); }