public IParserData GetData(int index) { IParserData xmlData = (IParserData)Activator.CreateInstance(_dataType); XmlNode progNode = _nodeList.Item(index); if (progNode != null) { for (int i = 0; i < _data.Fields.Count; i++) { XmlField field = _data.Fields[i]; XmlNode node; if ((node = progNode.SelectSingleNode(field.XmlName)) != null) { xmlData.SetElement(field.FieldName, node.InnerText); } if ((node = progNode.Attributes.GetNamedItem(field.XmlName)) != null) { xmlData.SetElement(field.FieldName, node.InnerText); } } } return(xmlData); }
public bool ParseRow(string source, ref IParserData data) { ArrayList sourceData = GetElements(source); for (int i = 0; i < _templateData.Count && i < sourceData.Count; i++) { string template = (string)_templateData[i]; if (template.IndexOf("#") != -1) { string rowSource = (string)sourceData[i]; data.SetElement(template, rowSource); } } return true; }
public bool ParseRow(string source, ref IParserData data) { ArrayList sourceData = GetElements(source); for (int i = 0; i < _templateData.Count && i < sourceData.Count; i++) { string template = (string)_templateData[i]; if (template.IndexOf("#") != -1) { string rowSource = (string)sourceData[i]; data.SetElement(template, rowSource); } } return(true); }
public IParserData GetData(int index) { IParserData jSONData = (IParserData)Activator.CreateInstance(_dataType); JSONNode progNode = _nodeList[index]; if (progNode != null) { for (int i = 0; i < _data.Fields.Count; i++) { JSONField field = _data.Fields[i]; List <JSONNode> subNode = progNode.GetNodes(field.JSONName, null); if (subNode.Count > 0) { jSONData.SetElement(field.FieldName, subNode[0].GetValue("")); } } } return(jSONData); }
/// <summary> /// Parses the section. /// </summary> /// <param name="source">The source.</param> /// <param name="data">The data.</param> /// <returns>bool - success/fail</returns> public bool ParseSection(string source, ref IParserData data) { Sections sourceData = GetSections(source); bool hasOptional = false; bool hasMatched = false; int dataFound = 0; if (sourceData.dataFields.Count == 0) { return false; } if (sourceData.dataFields.Count > _templateData.minFields) { hasOptional = true; } int s = 0; for (int t = 0; t < _templateData.dataFields.Count; t++) { DataField templateField = (DataField)_templateData.dataFields[t]; if (templateField.optional) { if (!hasOptional) { continue; } } if (s < sourceData.dataFields.Count) { DataField sourceField = (DataField)sourceData.dataFields[s]; if (!templateField.hasData && templateField.htmlTag != null && sourceField.htmlTag != null) { if (templateField.htmlTag.SameType(sourceField.htmlTag)) { s++; } } else { if (templateField.source != string.Empty && templateField.hasData) { int index = 0; for (int i = 0; i < templateField.dataElements.Count; i++) { ElementData element = (ElementData)templateField.dataElements[i]; int startPos; if (index < sourceField.source.Length) { if (element.start == string.Empty || (startPos = sourceField.source.IndexOf(element.start, index, StringComparison.OrdinalIgnoreCase)) == -1) { startPos = index; } else { startPos = startPos + element.start.Length; } int endPos; if (element.end == string.Empty || (endPos = sourceField.source.IndexOf(element.end, startPos, StringComparison.OrdinalIgnoreCase)) == -1) { endPos = sourceField.source.Length; } string elementSource = sourceField.source.Substring(startPos, endPos - startPos); if (elementSource != string.Empty) { if (element.name[0] == '*') { if (hasMatched && element.name == "*VALUE") { data.SetElement(_matchField, elementSource); hasMatched = false; } else { if (IsMatch(element.name, elementSource)) { hasMatched = true; } } } else { data.SetElement(element.name, elementSource); } dataFound++; if (dataFound == _templateData.dataTags) { break; } } index = endPos + element.end.Length; } } } s++; } } } if (dataFound == 0 && _templateData.dataTags > 0) { return false; } return true; }
/// <summary> /// Parses the section. /// </summary> /// <param name="source">The source.</param> /// <param name="data">The data.</param> /// <returns>bool - success/fail</returns> public bool ParseSection(string source, ref IParserData data) { Sections sourceData = GetSections(source); bool hasOptional = false; bool hasMatched = false; int dataFound = 0; if (sourceData.dataFields.Count == 0) { return(false); } if (sourceData.dataFields.Count > _templateData.minFields) { hasOptional = true; } int s = 0; for (int t = 0; t < _templateData.dataFields.Count; t++) { DataField templateField = (DataField)_templateData.dataFields[t]; if (templateField.optional) { if (!hasOptional) { continue; } } if (s < sourceData.dataFields.Count) { DataField sourceField = (DataField)sourceData.dataFields[s]; if (!templateField.hasData && templateField.htmlTag != null && sourceField.htmlTag != null) { if (templateField.htmlTag.SameType(sourceField.htmlTag)) { s++; } } else { if (templateField.source != string.Empty && templateField.hasData) { int index = 0; for (int i = 0; i < templateField.dataElements.Count; i++) { ElementData element = (ElementData)templateField.dataElements[i]; int startPos; if (index < sourceField.source.Length) { if (element.start == string.Empty || (startPos = sourceField.source.IndexOf(element.start, index, StringComparison.OrdinalIgnoreCase)) == -1) { startPos = index; } else { startPos = startPos + element.start.Length; } int endPos; if (element.end == string.Empty || (endPos = sourceField.source.IndexOf(element.end, startPos, StringComparison.OrdinalIgnoreCase)) == -1) { endPos = sourceField.source.Length; } string elementSource = sourceField.source.Substring(startPos, endPos - startPos); if (elementSource != string.Empty) { if (element.name[0] == '*') { if (hasMatched && element.name == "*VALUE") { data.SetElement(_matchField, elementSource); hasMatched = false; } else { if (IsMatch(element.name, elementSource)) { hasMatched = true; } } } else { data.SetElement(element.name, elementSource); } dataFound++; if (dataFound == _templateData.dataTags) { break; } } index = endPos + element.end.Length; } } } s++; } } } if (dataFound == 0 && _templateData.dataTags > 0) { return(false); } return(true); }