private void ActualProcess(XmlNode node, bool isRoot, ITemplate template, IRenderFunction currentRenderFunction) { foreach (INodeProcessor p in processors) { if (p.TryProcess(this, node, isRoot, template, currentRenderFunction)) return; } throw ParserUtils.TemplateErrorException("The node " + node.ToString() + " could not be handled."); }
private void ReceivedAvatarMetadata(JID from, string node, XmlNode items) { if (items.ChildNodes.Count == 0) return; Console.WriteLine("Received Avatar Data"); Console.WriteLine(items.ToString()); }
/// <summary> /// Returns the section parameter /// </summary> /// <param name="parent"></param> /// <param name="configContext"></param> /// <param name="section"></param> /// <returns>section</returns> public object Create(object parent,object configContext,XmlNode section) { if (Log.IsInfoEnabled) Log.Info("CodeColorizer AppSettings:\n" + section.ToString() ); return section; }
/// <summary> /// ɾ��ָ����XML�ڵ� /// </summary> /// <param name="clsRootNode">��ɾ���Ľڵ�</param> /// <returns>�Ƿ�ɾ���ɹ�</returns> public static bool DeleteXmlNode(XmlNode clsDeletedNode) { if (clsDeletedNode == null) return true; try { if (clsDeletedNode.ParentNode != null) clsDeletedNode.ParentNode.RemoveChild(clsDeletedNode); return true; } catch (Exception ex) { LogManager.Instance.WriteLog("GlobalMethods.DeleteXmlNode" , new string[] { "clsDeletedNode" }, new string[] { clsDeletedNode.ToString() }, ex); return false; } }
/// <summary> /// Función para marcar la cadena de texto /// </summary> /// <param name="refPattern">Expresión regular</param> /// <param name="refString">Cadena para buscar coincidencias</param> /// <param name="refStruct">Instrucciones de marcado</param> /// <returns>La cadena marcada</returns> private String markupText(String refPattern, String refString, XmlNode refStruct) { if (log.IsInfoEnabled) log.Info("Begin"); if (log.IsDebugEnabled) log.Debug("markupText(refPattern: " + refPattern + ", refString: " + refString + ", refStruct: " + refStruct.ToString() + ")"); /* Definición de variables */ bool singleOptionMatch = false; int singleOptionMatched = 0; String replaceGeneral = ""; String patternString = null; String subjectString = null; String tagStringOpen = null; String tagStringClose = null; String backreference = null; String backreferencePostValue = null; String backreferencePreValue = null; String replaceString = null; String resultString = ""; String multipleOptionPattern = null; String singleOptionPattern = null; Regex objRegExp = null; Regex multipleOptionRegExp = null; String openTag = "<"; String closeTag = ">"; RegexOptions options = RegexOptions.Compiled | RegexOptions.Multiline; Match matchResults = null; Match multipleOptionsMarchResults = null; XmlNode structNode = null; XmlNodeList multipleOptions = null; XmlNode singleOptionStruct = null; /* Verificamos si la cadena es nula antes de evaluarla */ if (refString != null) { /* Iniciando búsqueda del patron en la cadena de texto */ objRegExp = new Regex(refPattern, options); matchResults = objRegExp.Match(refString); /* Verificamos si hay alguna coincidencia e iteramos todas las coincidencias encontradas*/ if (matchResults.Success) { while (matchResults.Success) { replaceGeneral = ""; /* Iteramos los nodos dentro del xml que nos dan el contenido de las citas */ foreach (XmlNode itemXML in refStruct.ChildNodes) { /* Verificamos que el nodo hijo sea diferente de prevalue, postvalue y attr */ if (itemXML.Name != "prevalue" && itemXML.Name != "postvalue" && itemXML.Name != "attributes") { /* Verificamos si el nodo es una etiqueta(tag) o no */ if (itemXML.Name == "tag") { /*Verificamos y agregamos atributos por omisión a la etiqueta de apertura*/ if (itemXML.SelectSingleNode("attributes") == null) { tagStringOpen = openTag + itemXML.Attributes["name"].Value + closeTag; } else { tagStringOpen = openTag + itemXML.Attributes["name"].Value; foreach (XmlNode attrNode in itemXML.SelectSingleNode("attributes")) { if (attrNode.Attributes["name"].Value == "dateiso" && attrNode.InnerText == "") { tagStringOpen += " " + attrNode.Attributes["name"].Value + "=\"" + objRegExp.Replace(refString, itemXML.SelectSingleNode("value").InnerText) + "0000\""; } else { tagStringOpen += " " + attrNode.Attributes["name"].Value + "=\"" + attrNode.InnerText + "\""; } } tagStringOpen += closeTag; } tagStringClose = openTag + "/" + itemXML.Attributes["name"].Value + closeTag; } else { tagStringOpen = null; tagStringClose = null; } /* Verificamos si el nodo contiene un valor directo para la etiqueta(tag) o si su valor esta compuesto otras etiquetas(tag) */ if (itemXML.SelectSingleNode("value") == null) { /* Verificamos si hay que poner un valor antes de la etiqueta(tag) */ if (itemXML.SelectSingleNode("prevalue") != null) { backreferencePreValue = itemXML.SelectSingleNode("prevalue").InnerText; replaceGeneral += backreferencePreValue; } /* Si esta compuesto de otras etiquetas(tag) volvemos a enviar la cadena y el patron con los nodos hijos de la etiqueta(tag) */ replaceGeneral += tagStringOpen + this.markupText(refPattern, refString, itemXML) + tagStringClose; /* Verificamos si hay que poner un valor despues de la etiqueta(tag) */ if (itemXML.SelectSingleNode("postvalue") != null) { backreferencePostValue = itemXML.SelectSingleNode("postvalue").InnerText; replaceGeneral += backreferencePostValue; } } else { /* Deacuerdo al valor que tenemos indicado en el xml extramos la cadena de texto correspondiente */ backreference = itemXML.SelectSingleNode("value").InnerText; subjectString = objRegExp.Replace(matchResults.Value, backreference); /* Verificamos si a la cadena de texto resultante tiene multiples opciones, hay que aplicarle un patron nuevo ó si agregamos las etiquetas(tag) directamente */ if (itemXML.SelectSingleNode("multiple") != null) { /* Inicializamos la variables locales*/ multipleOptions = itemXML.SelectSingleNode("multiple").ChildNodes; multipleOptionPattern = null; singleOptionMatch = false; /* Armamos la expresion regular para todas las opciones y asignamos un namedgroup a cada una */ for (int i = 0; i < multipleOptions.Count; i++) { singleOptionPattern = multipleOptions[i].SelectSingleNode("regex").InnerText; singleOptionStruct = multipleOptions[i].SelectSingleNode("struct"); if (i == 0) { multipleOptionPattern += "(?<op" + i + ">" + singleOptionPattern + ")"; } else { multipleOptionPattern += "|(?<op" + i + ">" + singleOptionPattern + ")"; } } /* Inicializamos un nuevo metro para evaluar la expresion regular de todas la opciones */ multipleOptionRegExp = new Regex(multipleOptionPattern, options); multipleOptionsMarchResults = multipleOptionRegExp.Match(subjectString); /* Verificamos que opcion es la que coincidio*/ for (int i = 0; i < multipleOptions.Count && !singleOptionMatch; i++) { if (multipleOptionsMarchResults.Groups["op" + i].Success) { singleOptionMatched = i; singleOptionMatch = true; } } singleOptionPattern = multipleOptions[singleOptionMatched].SelectSingleNode("regex").InnerText; singleOptionStruct = multipleOptions[singleOptionMatched].SelectSingleNode("struct"); /* Verificamos si hay que poner un valor antes de la etiqueta(tag) */ if (itemXML.SelectSingleNode("prevalue") != null) { backreferencePreValue = itemXML.SelectSingleNode("prevalue").InnerText; replaceGeneral += backreferencePreValue; } /* Enviamos la expresion regular de la opcion que coincidio junto con el grupo de ordenamiento */ replaceGeneral += tagStringOpen + this.markupText(singleOptionPattern, subjectString, singleOptionStruct) + tagStringClose; /* Verificamos si hay que poner un valor despues de la etiqueta(tag) */ if (itemXML.SelectSingleNode("postvalue") != null) { backreferencePostValue = itemXML.SelectSingleNode("postvalue").InnerText; replaceGeneral += backreferencePostValue; } } else if (itemXML.SelectSingleNode("regex") != null) { /* Verificamos si hay que poner un valor antes de la etiqueta(tag) */ if (itemXML.SelectSingleNode("prevalue") != null) { backreferencePreValue = itemXML.SelectSingleNode("prevalue").InnerText; replaceGeneral += backreferencePreValue; } structNode = itemXML.SelectSingleNode("struct"); patternString = itemXML.SelectSingleNode("regex").InnerText; /* Enviamos la cadena resultante con el patron nuevo a aplicar y las etiquetas(tag) que debe contener y el resultado lo ponemos dentro de la etiqueta(tag) correspondiente */ replaceGeneral += tagStringOpen + this.markupText(patternString, subjectString, structNode) + tagStringClose; if (itemXML.SelectSingleNode("postvalue") != null) { backreferencePostValue = itemXML.SelectSingleNode("postvalue").InnerText; replaceGeneral += backreferencePostValue; } } else { replaceString = null; /* Verificamos si hay que poner un valor antes de la etiqueta(tag) */ if (itemXML.SelectSingleNode("prevalue") != null) { backreferencePreValue = itemXML.SelectSingleNode("prevalue").InnerText; replaceString += backreferencePreValue; } /* Armamos la etiqueta(tag) con su valor */ replaceString = replaceString + tagStringOpen + backreference + tagStringClose; if (itemXML.SelectSingleNode("postvalue") != null) { backreferencePostValue = itemXML.SelectSingleNode("postvalue").InnerText; replaceString += backreferencePostValue; } replaceGeneral += replaceString; } } } } /*Verificamos si la cadena resultString no esta vacia esto ocurre cuando hubo mas de un resultado en la misma cadena como los autores *En este caso tenemos que agregar el resultado previo hasta donde se encuentra el nuevo resultado mas el nuevo resultado desde su comienzo */ if (matchResults.Index > 0 && resultString != "") { String searchStringIndex = refString.Substring(matchResults.Index); resultString = resultString.Substring(0, resultString.LastIndexOf(searchStringIndex)) + objRegExp.Replace(refString, replaceGeneral, 1, matchResults.Index).Substring(matchResults.Index); } else { resultString = objRegExp.Replace(refString, replaceGeneral, 1, matchResults.Index); } matchResults = matchResults.NextMatch(); } } else { resultString += refString; } } else { resultString += refString; } if (log.IsDebugEnabled) log.Debug("resultString: " + resultString); if (log.IsInfoEnabled) log.Info("End"); return resultString; }
/// <summary> /// Parses the XML node and imports it. /// </summary> /// <param name="rowNode">The node.</param> protected void ProcessRow(XmlNode rowNode) { XmlNodeList cells = rowNode.ChildNodes; if (cells.Count != kNumberOfColumns) { Console.WriteLine ("ERROR: Wrong number of columns in row {0}", rowNode.ToString ()); return; } //------------ Add to DB string lastName = cells[kLastNameColumnIndex].InnerText; string firstName = cells[kFirstNameColumnIndex].InnerText; if (firstName == null || firstName.Equals ("")) { firstName = "Nezname"; } string birthYear = cells[kBirthYearColumnIndex].InnerText; string birthPlace = cells[kBirthPlaceColumnIndex].InnerText; string[] countryStrings = new string[2]; countryStrings[0] = cells[kStateFirstColumnIndex].InnerText; countryStrings[1] = cells[kStateSecondColumnIndex].InnerText; List<Country> countries = ConvertStringCountriesToCountryArray (countryStrings); string dbAdditionYear = cells[kAddedToDatabaseYearColumnIndex].InnerText; string sexValue = cells[kSexColumnIndex].InnerText; Sex sex = Sex.Male; if (sexValue != null) { sex = sexValue.Equals (kMaleSexIdentifier) ? Sex.Male : Sex.Female; } string department = cells[kDepartmentColumnIndex].InnerText; string departmentComment = cells[kDepartmentCommentColumnIndex].InnerText; string administration = cells[kAdministrationColumnIndex].InnerText; string administrationComment = cells[kAdministrationCommentColumnIndex].InnerText; string pozorka1 = cells[kPozorkaFirstColumnIndex].InnerText; string pozorka2 = cells[kPozorkaSecondColumnIndex].InnerText; Person p = TryToFindPerson (firstName, lastName, birthYear, sex, birthPlace); if (p == null) { // Need to create a new person p = new Person (); p.FirstName = firstName; p.Surname = lastName; if (birthYear != null && !birthYear.Equals ("")) { p.BirthDate = birthYear; } p.Sex = sex; p.Nationality = Nationality.Unknown; p.Note = string.Format ("{0} {1}\n{2} {3}\n{4} {5}\n{6} {7}", kPlaceOfBirthNoteCaption, birthPlace, kPozorka1NoteCaption, pozorka1, kPozorka2NoteCaption, pozorka2, kAddedToStbDatabaseNoteCaption, dbAdditionYear); if (countries.Count > 0) { p.Citizenships = countries; } _ctx.Entities.Add (p); } StbDivision StbDepartment = GetStbDivisionByName (department); StbDivision StbAdministration = GetStbDivisionByName (administration); Relation departmentRelation = null; Relation administrationRelation = null; ICollection<Relation> relations = p.ObjectiveRelations; if (relations != null) { foreach (Relation r in relations) { if (StbDepartment != null && r.SubjectiveEntityId == StbDepartment.Id) { departmentRelation = r; } else if (StbAdministration != null && r.SubjectiveEntityId == StbAdministration.Id) { administrationRelation = r; } } } if (departmentRelation == null && StbDepartment != null) { // Need to add a relation AddStbRelationToPerson (p, StbDepartment, departmentComment, GetRelationType (kRelationDepartmentType)); } if (administrationRelation == null && StbAdministration != null) { // Need to add a relation AddStbRelationToPerson (p, StbAdministration, administrationComment, GetRelationType (kRelationAdministrativeType)); } _ctx.SaveChanges (); }
/// <summary> /// test the given node, if it is a comment or is empty; if it is empty, try the next nodes. /// </summary> /// <param name="cur2">the current node</param> /// <returns>the current or the first next node with actual content /// </returns> public static XmlNode NextNotBlank(XmlNode cur2) { XmlNode cur; cur = cur2; while (true) { if (cur == null) { return cur; } if ((cur.NodeType == System.Xml.XmlNodeType.Text) && (cur.ToString().Length == 0)) { cur = cur.NextSibling; continue; } if (cur.Name == "comment") { cur = cur.NextSibling; continue; } if (cur.Name == "#comment") { cur = cur.NextSibling; continue; } return cur; } }