c# - Extract xml from string using regular expression -


i have following log file server,i want extract xml following string.

2:00:11 pm >>response: <?xml version="1.0" encoding="utf-8"?>  <hotelml xmlns="http://www.xpegs.com/v2001q3/hotelml"><head><route destination="tr" source="00"><operation action="create" app="ultradirect-d1c1_" appver="v1_1" datapath="/hotelml" starttime="2013-07-31t08:33:13.223+00:00" success="true" totalprocesstime="711"/></route>............  </hotelml>   3:00:11 pm >>response: <?xml version="1.0" encoding="utf-8"?>  <hotelml xmlns="http://www.xpegs.com/v2001q3/hotelml"><head><route destination="tr" source="00"><operation action="create" app="ultradirect-d1c1_" appver="v1_1" datapath="/hotelml" starttime="2013-07-31t08:33:13.223+00:00" success="true" totalprocesstime="711"/></route>............  </hotelml>  5:00:11 pm >>response: <?xml version="1.0" encoding="utf-8"?>  <hotelml xmlns="http://www.xpegs.com/v2001q3/hotelml"><head><route destination="tr" source="00"><operation action="create" app="ultradirect-d1c1_" appver="v1_1" datapath="/hotelml" starttime="2013-07-31t08:33:13.223+00:00" success="true" totalprocesstime="711"/></route>............  </hotelml> 

i have written following regular expression same it's matching first entry in string.but want return xml string collection.

(?<= response:).*>.*</.*?> 

here's approach should leave list<xdocument>:

using system.io; using system.linq; using system.text.regularexpressions; using system.xml.linq;  class program {     static void main(string[] args)     {          var input = file.readalltext("text.txt");         var xmldocuments = regex             .matches(input, @"([0-9amp: ]*>>response: )")             .cast<match>()             .select(match =>                 {                     var currentposition = match.index + match.length;                     var nextmatch = match.nextmatch();                     if (nextmatch.success == true)                     {                         return input.substring(currentposition,                             nextmatch.index - currentposition);                     }                     else                     {                         return input.substring(currentposition);                     }                 })             .select(s => xdocument.parse(s))             .tolist();     } } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -