private static IDocument CreatePatternXMLDoc(IList <SsurgeonPattern> patterns) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance(); DocumentBuilder db = dbf.NewDocumentBuilder(); IDocument domDoc = db.NewDocument(); IElement rootElt = domDoc.CreateElement(SsurgeonPattern.EltListTag); domDoc.AppendChild(rootElt); int ordinal = 1; foreach (SsurgeonPattern pattern in patterns) { IElement patElt = domDoc.CreateElement(SsurgeonPattern.SsurgeonElemTag); patElt.SetAttribute(SsurgeonPattern.OrdinalAttr, ordinal.ToString()); IElement semgrexElt = domDoc.CreateElement(SsurgeonPattern.SemgrexElemTag); semgrexElt.AppendChild(domDoc.CreateTextNode(pattern.GetSemgrexPattern().Pattern())); patElt.AppendChild(semgrexElt); IElement uidElem = domDoc.CreateElement(SsurgeonPattern.UidElemTag); uidElem.AppendChild(domDoc.CreateTextNode(pattern.GetUID())); patElt.AppendChild(uidElem); IElement notesElem = domDoc.CreateElement(SsurgeonPattern.NotesElemTag); notesElem.AppendChild(domDoc.CreateTextNode(pattern.GetNotes())); patElt.AppendChild(notesElem); SemanticGraph semgrexGraph = pattern.GetSemgrexGraph(); if (semgrexGraph != null) { IElement patNode = domDoc.CreateElement(SsurgeonPattern.SemgrexGraphElemTag); patNode.AppendChild(domDoc.CreateTextNode(semgrexGraph.ToCompactString())); } IElement editList = domDoc.CreateElement(SsurgeonPattern.EditListElemTag); patElt.AppendChild(editList); int editOrdinal = 1; foreach (SsurgeonEdit edit in pattern.GetEditScript()) { IElement editElem = domDoc.CreateElement(SsurgeonPattern.EditElemTag); editElem.SetAttribute(SsurgeonPattern.OrdinalAttr, editOrdinal.ToString()); editElem.AppendChild(domDoc.CreateTextNode(edit.ToEditString())); editList.AppendChild(editElem); editOrdinal++; } rootElt.AppendChild(patElt); ordinal++; } return(domDoc); } catch (Exception e) { log.Error(typeof(Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.Ssurgeon).FullName, "createPatternXML"); log.Error(e); return(null); } }