// Remove null children of current node, and return true => current node is null public static bool RemoveNullChildren(this ElementNode node) { if (node == null) { return(true); } var children = node.Children().Cast <ElementNode>().ToList(); foreach (var child in children) { // Remove child if it is null => return true if (RemoveNullChildren(child)) { node.Remove(child); } } bool currentNodeIsEmpty = !node.Children().Any() && node.Value == null; bool currentNodeIsFhirResource = node.IsFhirResource(); if (currentNodeIsEmpty && !currentNodeIsFhirResource) { return(true); } else { return(false); } }
public override bool Visit(ElementNode node) { if (node.IsFhirResource()) { ProcessResult result = ProcessResourceNode(node); _contextStack.Push(new Tuple <ElementNode, ProcessResult>(node, result)); } return(true); }
public override void EndVisit(ElementNode node) { if (node.IsFhirResource()) { Tuple <ElementNode, ProcessResult> context = _contextStack.Pop(); ProcessResult result = context.Item2; if (context.Item1 != node) { // Should never throw exception here. In case any bug happen, we can get clear message for this exception. throw new ConstraintException("Internal error: access wrong context."); } if (_contextStack.Count() > 0) { _contextStack.Peek().Item2.Update(result); } if (AddSecurityTag && !node.IsContainedNode()) { node.AddSecurityTag(result); } } }