XLinq Pierre Lagarde pierlag@microsoft.com

Preview:

Citation preview

XLinq

Pierre Lagardepierlag@microsoft.com

http://blogs.developpeur.org/fox

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

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>

Démo

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");…

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")

))

);

XAttributeXNode

XComment XContainer

XDeclaration

XDocument

XDocumentType

XElement

XName

XProcessingInstructionXText

XNamespace XStreamingElement

XLinq Class Hierarchy

Chargement et Génération

Chargement depuis une stringXElement.Parse

GénérationSelect new XElement

Ajout / Modification / SuppressionAdd

Remove

ReplaceContent

Démo

Requête XLinq

Where

Select

SelectMany

OrderBy

GroupBy

Take

Démo

Mix entre Linq et XLinq

Démo

Recommended