public void identifyLogic(Word.Range range) { foreach (Word.ContentControl cc in range.ContentControls) { if (cc.Tag == null) { // Its just some content control we don't care about continue; } TagData td = new TagData(cc.Tag); if (cc.Tag.Contains("od:xpath")) { xpathsXpath xp = srcXppe.getXPathByID( td.getXPathID() ); identifyLogicInXPath(xp, range, cc); } else if (cc.Tag.Contains("od:repeat")) { testOldestRepeatIncluded(range, cc); xpathsXpath xp = srcXppe.getXPathByID(td.getRepeatID()); // TODO: Clone, so we can write source to just the clone //xp.Serialize //xpathsXpath.Deserialize // TODO consider cloning issue further. I've implemented it // below for xpaths, but since we're throwing the objects // away, it doesn't matter that we're altering them? BBxpaths.Add(xp); string questionID = xp.questionID; question q = srcQuestionnaire.getQuestion(questionID); BBquestions.Add(q); // Answer - just need to do this for the outermost repeat Word.ContentControl oldestRepeat = RepeatHelper.getOldestRepeatAncestor(cc); if (oldestRepeat.ID.Equals(cc.ID)) { foreach (object o in srcAnswers.Items) { if (o is repeat) { repeat a = (repeat)o; if (a.qref.Equals(questionID)) // question ID == answer ID { BBrepeats.Add(a); log.Debug("Added outermost repeat!"); break; } } } } } else if (cc.Tag.Contains("od:condition")) { // Add the condition condition c = srcCpe.getConditionByID(td.getConditionID()); BBconditions.Add(c); // Find and add questions and xpaths used within it //List<xpathsXpath> xpaths = ConditionsPartEntry.getXPathsUsedInCondition(c, srcXppe); List<xpathsXpath> xpaths = new List<xpathsXpath>(); c.listXPaths(xpaths, srcCpe.conditions, srcXppe.getXPaths()); foreach (xpathsXpath xp in xpaths) { identifyLogicInXPath(xp, range, cc); } } } }