>Regex regexXml = new Regex(@"\<(?'field'[^/].*?)\>(?'data'.*?)\</\k'field'\>"); > > MatchCollection matches = regexXml.Matches(tcSQML);>
> String input = "<func>GetResLog</func><tcOperator>ADMIN</tcOperator><tcSalespoint>TICKETS</tcSalespoint><tnReservNo>1001001</tnReservNo><tcReturnType>DSP</tcReturnType>";>
>String input = @"<func>getqtyremaining</func><tcoperator>ADMIN</tcoperator><tcreturntype>XML</tcreturntype> ><tcsalespoint>TICKET004001</tcsalespoint><ttdatetime>03/11/2013 01:19 PM</ttdatetime> ><TCDCILIST><DCI>ACTIVITIESSKYDIVING 1000 </DCI><DCI>ACTIVITIESSKYDIVING 1030 </DCI> ><DCI>ACTIVITIESSKYDIVING 1100 </DCI><DCI>ACTIVITIESSKYDIVING 1130 </DCI><DCI>ACTIVITIESSKYDIVING 1200 </DCI> ><DCI>ACTIVITIESSKYDIVING 1230 </DCI><DCI>ACTIVITIESSKYDIVING 1300 </DCI><DCI>ACTIVITIESSKYDIVING 1330 </DCI> ><DCI>ACTIVITIESSKYDIVING 1400 </DCI><DCI>ACTIVITIESSKYDIVING 1430 </DCI></TCDCILIST>";>
>public static void PopulateFromSQML(this Dictionary<String, String> tDictionary, String tcSQML) > { > Regex regexXml = new Regex(@"\<(?'field'[^/].*?)\>(?'data'.*?)\</\k'field'\>"); > > MatchCollection matches = regexXml.Matches(tcSQML); > foreach (Match m in matches) > { > try > { > if (!tDictionary.ContainsKey(m.Groups["field"].ToString())) > tDictionary.Add(m.Groups["field"].ToString(), m.Groups["data"].ToString()); > } > catch (Exception) > { > // Don't care > } > } > }>
public static void PopulateFromSQML(this Dictionary<String, String> tDictionary, String tcSQML) { tDictionary.Clear(); string pattern = @"<(?<field>[^/>]+)>(?<data>.*)</\k<field>>"; MatchCollection matches = Regex.Matches(tcSQML, pattern, RegexOptions.Singleline); foreach (Match m in matches) { //Console.WriteLine("Key: {0}\nValue: {1}\n", m.Groups["field"], m.Groups["data"]); if (!tDictionary.ContainsKey(m.Groups["field"].ToString())) tDictionary.Add(m.Groups["field"].ToString(), m.Groups["data"].ToString()); } }