Monday, 13 May 2013

linq for string


//Load by string
TextReader tr=new StringReader(string);
XDocument xdoc=XDocument.Load(tr);

//Load by path
XDocument xdoc=XDocument.Load(path);

var _text= from t in xdoc.Decidents()
           where t.Name.LocalName.ToLower()=="text"
           select t;
//Store in list
 List<XElement> _list=_text.ToList<XElement>();
//Store in  lines
 string _strText="";
 foreach(XElement e in _text)
   _strText=_strText+e.ToString()+"\r\n";

No comments:

Post a Comment