/// <summary> /// Build a tree of only one schema /// </summary> /// <param name="schemaA"></param> /// <returns></returns> public IDiffNode BuildTree(XmlSchemaObject obj) { // Setup the schema IDiffNode retVal = null; if (obj is XmlSchemaAttribute) retVal = new AttributeDiffNode() { Original = obj as XmlSchemaAttribute }; else if (obj is XmlSchemaElement) { retVal = new ElementDiffNode() { Original = obj as XmlSchemaElement }; CopyChildNodes((obj as XmlSchemaElement).SchemaType as XmlSchemaComplexType, retVal, new Stack<string>(), true); } else if (obj is XmlSchemaChoice) { retVal = new ChoiceDiffNode() { Original = obj as XmlSchemaChoice }; CopyChildNodes(obj as XmlSchemaChoice, retVal, new Stack<string>()); retVal = retVal.Children[0]; } else if (obj is XmlSchemaSequence) { retVal = new SequenceDiffNode() { Original = obj as XmlSchemaSequence }; CopyChildNodes(obj as XmlSchemaSequence, retVal, new Stack<string>()); if (TreatSequenceAsNode) retVal = retVal.Children[0]; } else return null; return retVal; }
/// <summary> /// Copy child nodes for a choice /// </summary> private void CopyChildNodes(XmlSchemaChoice choice, IDiffNode parent, Stack<String> typeStack) { if (choice.Content == null || choice.Content.Count == 0) return; ChoiceDiffNode chcNode = new ChoiceDiffNode() { Original = choice }; // Build the children of this foreach (XmlSchemaObject child in choice.Content) if (child is XmlSchemaChoice) CopyChildNodes(child as XmlSchemaChoice, chcNode, typeStack); else if (child is XmlSchemaSequence) CopyChildNodes(child as XmlSchemaSequence, chcNode, typeStack); else if (child is XmlSchemaElement) CopyChildNodes(child as XmlSchemaElement, chcNode, typeStack); else if (child is XmlSchemaAny) chcNode.AddChild(new DiffNode<XmlSchemaAny>() { Original = child as XmlSchemaAny }); // Don't duplicate on structure if (parent.Children == null || FindProbableCandidate(parent.Children, chcNode) == null) parent.AddChild(chcNode); }