12
XLinq Pierre Lagarde [email protected] http://blogs.developpeur.org/fox

XLinq Pierre Lagarde [email protected]

Embed Size (px)

Citation preview

Page 1: XLinq Pierre Lagarde pierlag@microsoft.com

XLinq

Pierre [email protected]

http://blogs.developpeur.org/fox

Page 2: XLinq Pierre Lagarde pierlag@microsoft.com

XLinq pourquoi ?

XML PartoutData

Fichier de Config

Base de donnée

Office

Nouvelle API mémoire sur des données XMLDans la suite de Linq

Bénéficier du langage de requêtage de Linq plutôt que du XPath ou du XQuery

Bénéficier de la génération de XML grâce à XElement

En amont de DLinq

Page 3: XLinq Pierre Lagarde pierlag@microsoft.com

Un fichier XML simple

<contacts><contact>

<name>Patrick Hines</name><phone type="home">206-555-0144</phone><phone type="work">425-555-0145</phone><address>

<street1>123 Main St</street1><city>Mercer Island</city><state>WA</state><postal>68042</postal>

</address><netWorth>10</netWorth>

</contact></contacts>

Page 4: XLinq Pierre Lagarde pierlag@microsoft.com

Démo

Page 5: XLinq Pierre Lagarde pierlag@microsoft.com

XmlDocument

XmlDocument doc = new XmlDocument();

XmlElement name = doc.CreateElement("name");

name.InnerText = "Patrick Hines";

XmlElement phone1 =doc.CreateElement("phone");phone1.SetAttribute("type", "home");phone1.InnerText = "206-555-0144";

XmlElement phone2 = doc.CreateElement("phone");phone2.SetAttribute("type", "work");…

Page 6: XLinq Pierre Lagarde pierlag@microsoft.com

XElement

XElement contacts =new XElement("contacts",

new XElement("contact",new XElement("name", "Patrick Hines"),new XElement("phone", "206-555-0144", new XAttribute("type", "home")),new XElement("phone", "425-555-0145", new XAttribute("type", "work")),new XElement("address",

new XElement("street1", "123 Main St"),

new XElement("city", "Mercer Island"),new XElement("state", "WA"),new XElement("postal", "68042")

))

);

Page 7: XLinq Pierre Lagarde pierlag@microsoft.com

XAttributeXNode

XComment XContainer

XDeclaration

XDocument

XDocumentType

XElement

XName

XProcessingInstructionXText

XNamespace XStreamingElement

XLinq Class Hierarchy

Page 8: XLinq Pierre Lagarde pierlag@microsoft.com

Chargement et Génération

Chargement depuis une stringXElement.Parse

GénérationSelect new XElement

Ajout / Modification / SuppressionAdd

Remove

ReplaceContent

Page 9: XLinq Pierre Lagarde pierlag@microsoft.com

Démo

Page 10: XLinq Pierre Lagarde pierlag@microsoft.com

Requête XLinq

Where

Select

SelectMany

OrderBy

GroupBy

Take

Page 11: XLinq Pierre Lagarde pierlag@microsoft.com

Démo

Page 12: XLinq Pierre Lagarde pierlag@microsoft.com

Mix entre Linq et XLinq

Démo