linq

single record get
===================

http://www.codeproject.com/Answers/182358/Linq-to-xml-output-element-value.aspx#answer1


http://www.dotnetperls.com/convert-milliseconds-seconds-minutes

http://rumandcode.wordpress.com/2008/09/03/multiple-join-fields-in-linq/

http://msdn.microsoft.com/en-us/library/bb397941.aspx


slibinlig
http://msdn.microsoft.com/en-us/library/bb675160.aspx

http://www.java2s.com/Code/XML/XSLT-stylesheet/precedingsiblingandfollowingsibling.htm

IEnumerable status = from obj in xmlDoc.Descendants("AvailFlt")
where (string)obj.Element("AirV") == (string)elementchild.Element("AirV") && (string)obj.Element("FltNum") == (string)elementchild.Element("FltNum")
&& (string)obj.Element("StartAirp") == (string)elementchild.Element("StartPt") && (string)obj.Element("EndAirp") == (string)elementchild.Element("EndPt")
&& (string)obj.Element("StartTm") == (string)elementchild.Element("StartTm") && (string)obj.Element("StartDt") == (string)elementchild.Element("StartDt")
&& (string)obj.Element("EndTm") == (string)elementchild.Element("EndTm")
select obj;






//XElement single;
//if (status.Count() == 0)
//{
// //handle no elements returned
//}
//else if (status.Count() > 1)
//{
// //handle more than 1 elements returned
//}
//else
//{
XElement single = status.Single();
//}

XElement el2 = ((IEnumerable)single
.XPathEvaluate("following-sibling::*[1]"))
.Cast()
.First();

dictionary

http://www.dotnetperls.com/dictionary-lookup


http://www.dotnetperls.com/dictionary-keys

Converting between XDocument and XmlDocument, XElement and XmlElement

http://brianary.blogspot.com/2010/02/converting-between-xdocument-and.html

 public static XmlDocument ToXmlDocument(this XDocument xdoc)
  {
    var xmldoc = new XmlDocument();
    xmldoc.Load(xdoc.CreateReader());
    return xmldoc;
  }
  
  ///
  /// Converts an XmlDocument to an XDocument.
  ///

  /// The XmlDocument to convert.
  /// The equivalent XDocument.
  public static XDocument ToXDocument(this XmlDocument xmldoc)
  {
    return XDocument.Load(xmldoc.CreateNavigator().ReadSubtree());
  }
  
  ///
  /// Converts an XElement to an XmlElement.
  ///

  /// The XElement to convert.
  /// The equivalent XmlElement.
  public static XmlElement ToXmlElement(this XElement xelement)
  {
    return new XmlDocument().ReadNode(xelement.CreateReader()) as XmlElement;
  }
  
  ///
  /// Converts an XmlElement to an XElement.
  ///

  /// The XmlElement to convert.
  /// The equivalent XElement.
  public static XElement ToXElement(this XmlElement xmlelement)
  {
    return XElement.Load(xmlelement.CreateNavigator().ReadSubtree());
  }



public XmlElement doAvail(XmlDocument xmlRequest, XmlDocument xmlFilter)
{

XmlElement xmlResponse = null;
try
{

XmlSelect xws = new XmlSelect();
NetworkCredential credentials = new NetworkCredential("PCC69TX", "Badur69tx");
CredentialCache cc = new CredentialCache();
cc.Add(new Uri(xws.Url), "Basic", credentials);
xws.Credentials = cc;

xws.PreAuthenticate = true;
xmlResponse = xws.SubmitXml("DynGalileoCopy_69TX", xmlRequest.DocumentElement, xmlFilter.DocumentElement);


XElement x = XmlLinqConversionExtensions.ToXElement(xmlResponse);

System.Xml.Linq.XDocument xmlDoc = new System.Xml.Linq.XDocument( x);

var persons = from person in xmlDoc.Descendants("AvailFlt")
select new
{
AirV = person.Element("AirV").Value,
FltNum = person.Element("FltNum").Value,
StartDt = person.Element("StartDt").Value,
StartAirp = person.Element("StartAirp").Value,
EndAirp = person.Element("EndAirp").Value,
NumStops = person.Element("NumStops").Value,
StartTm = person.Element("StartTm").Value,
EndTm = person.Element("EndTm").Value,
JrnyTm = person.Element("JrnyTm").Value,
EndDt = person.Element("EndDt").Value,

};
rptUserList.DataSource = persons;
rptUserList.DataBind();

}
catch (Exception ex)
{
// TextBox2.Text = "Error Message : \n " + ex.Message + "\n\n\n Stack Trace : \n" + ex.StackTrace;
}
return xmlResponse;
}

public XmlDocument BuildRequest()
{

XmlDocument doc = new XmlDocument();
DateTime tomorrow = DateTime.Today.AddDays(90.0);
string req = "\r\n";
req += " \r\n";
req += " \r\n";
req += " 1\r\n";
req += " \r\n";
req += " " + tomorrow.ToString("yyyyMMdd") + "\r\n";
req += " DEN\r\n";
req += " ORD\r\n";
req += " 1200\r\n";
req += " D\r\n";
req += " 0800\r\n";
req += " 1400\r\n";
req += " \r\n";
req += " B\r\n";
req += " B\r\n";
req += " \r\n";
req += "
\r\n";
req += "
\r\n";
req += "
\r\n";
doc.LoadXml(req);
return doc;

}

public XmlDocument BuildFilter()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<_/>");
return doc;
}

linq

http://stackoverflow.com/questions/4526734/how-to-read-xml-file-using-linq-in-c

http://www.techrepublic.com/blog/programming-and-development/access-xml-data-using-linq-to-xml/594


http://weblogs.asp.net/scottgu/archive/2007/08/07/using-linq-to-xml-and-how-to-build-a-custom-rss-feed-reader-with-it.aspx

http://www.dbtutorials.com/retrieve/linq-to-xml-cs.aspx
XDocument xmlDoc = XDocument.Load(Server.MapPath("personkrs.xml"));

var persons = from person in xmlDoc.Descendants("Person")
select new
{
Name = person.Element("Name").Value,
City = person.Element("City").Value,
//Age = person.Element("Age").Value,
};
GridView1.DataSource = persons;
GridView1.DataBind();





Paxton
Munich
29


Mike
Orlando
33


Ella
LA
13


Ingrid
Oslo
63