Google Search

Google
 

Monday, July 21, 2008

Video: LINQ to XML - Events and Annotations

Presenter:Mike Taulty

LINQ to XML has a way in which arbitrary objects can be used to "annotate" an XML tree. This provides a convenient way to associate a non XML data structure with data stored in an XML tree. You can also have a LINQ to XML tree fire events whenever its content is modified.In this video we take a look at both of these aspects of LINQ to XML.

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video


Minute 0

Hello and welcome to short video on the topic of the into XML mines might hold the eye with Microsoft in the UK this is not an overview of intellect now if you want an overview than that backed the website we found this video they should be in an overview kicking around there somewhere here would it I took a couple of topics they re fairly small topics listening to exist in them into XML API that you might never seen elsewhere namely events and annotations that switched viciously a look at this case I m hearing little suited as an eight and 72 with RTE and the product at the time of recording this video but haven t quite got there yet it takes a while annotations allow us to do is to take an exiled tree and associate additional objects with various places with a naturally Sophie think the second about one user trees you control you know that every note ability to control usually has a tag associated when you can just store any old object and is quite convenient thing to store any old object in that place when you look at p

Minute 1

XML API things ex element has a collection that are called annotations and also ex attribute has a collection called annotations and you can use this to store any old stuff that you like so and that I recorded this video is kind of season although any good Christmas so I thought what better tree to build on a Christmas tree sellers build ourselves a quick Christmas tree and will call this ex tree will create one will say X must tree is this you can be XML at an effusive of tears to this tree is also from high in let s say five tears to this true and select a new ex element or quality and open attribute on it level it can be I will build downwards that way sorry upwards at work and then inside of the elements just make sure we get this right but selecting new things also select

Minute 2

New eggs element will have a branch will put an attribute on acts remember the very simple trees or put this on the left hand side and will have another one which will pull on the right hand side which right hand side on week and are made of tree frogs are such civic and build a code would seem to be okay so my simple idea was to build a class and presenting a decoration and we can decorate the tree so at this very cheesy I realise so let s go ahead and try these code I ve got here he is a classical decoration decoration has has a name you deserve a stars and fairies reindeers and chocolate and so on I wrote a function and get random decoration that is pulls from this arrange a random decoration so what we can do that then it is restarted decorate trailers find all the branches so what do is write a query was safer on

Minute 3

Be in ex three descendants the local branch are selectively and then let it numerically to those things let safe reach ex element in this case of Colin Branch in query as they branch and what whenever it is adding an occasion to that things recall add annotation it estates get you can add any old thing you want in here so what we ll do his will use decoration get random decoration that Gilligan is a decoration that we pumped that trade is adding an object into an association with this ex element and you can do the same thing with ex attributes as well just a sort of as a sake decorated tree and XML tree with a bunch of additional data is that make sense you to do it of course you can also go ahead and so branch remove annotations or annotations and with the other particular type there and then we can go on to done this and decorator are treated not have a look at what all the

Minute 4

On what all the annotations so I guess we could do this in the originally but let s just do this again was safe each element be of rant again in query console write like let s get the allocation first of the said declaration D equals will got to the branch get the allocation or annotations must go for off type decoration here is get that and I will do is just console write 90 name Pacific and build that exactly failed this is the reckon an occasion to allocation of decoration and their let s build us a run a bigoted artery and had been decorated with some reindeers and chocolates and stars in fairies and so on as a

Minute 5

Boss does not especially random by the assassination of random so just a simple idea we want to add up a tree object and store them with ex elements in ex attributes and we can then pull them back in a pretty simple way you might find very useful for when using XML as a primary data structure in your programme but you need some other data structure that sign of maps up with the XML am I the really interesting thing to use it this way barely living we don t allow the side was the idea of events dissenting events that you know if somebody has altered the treat so we can do it we can walk up to particular elements here am let s go ahead and get a few things that get the ecstasy itself now to wonder if you give it some elements and attributes is not just about elements to go to the tree and we can say let me know whenever you have changed a Sun event handle call it on to be changed so that in and essentially

Minute 6

What that gives us down here here s an event marks we can switch on the event up such stately object change and you can see what we get all his ad name removed value so we can write out our beard we can write out a name change we can write out removed we can write out value change and this is largely the same across elements and arteries so let s just go ahead and walk up to the tree here and add something else that is just as a new ex element I am a something after the base of the tree and we should see if we has the rape and over here we stepped this code do we create up to three McColl aggregate break finally consumed has added something into that treat so again not notified at St added a roof in that tree week and let s confine preferences in particular branch of the tree so

Minute 7

Let s forget this and from minutes and let s forget the tree change that confined a branch so let s say ex elements branch three equals were holding on to find that within the tree works extra three descendants of the core branch but it s the one where the first where we have an essentially the element parents attribute skewed merely with the wrong air in Eireann that parents attribute a cold will level equals that say three that s fine that one was turned that into an integer and make that work so she given the particular branch that will got to that branch three and say again on changed as an advance and vehicle on branch change activist is reused on tree change will catch up on the second such a state that

Minute 8

I must reduce refractor that inform on branch changed gets as better now we ve got that only four of the ranch three lets say attributes I still say remove attributes were shrivelled out of its officer once again I said about pointlessness of 10 get branch three remove it attributes we can to get an object change telling us that we had something removed from that particular branch now I m into thinking that this would be what happens if we go back to changing this event handler so it is on the trees are axed she got changed at school refractor this once more distractedly consistent naming so every factor that once again and then we walk up the branch three and remove attributes what happens to we get our event handler not to do

Minute 9

Setting up an event handlers of the roots of the tree give you events on everything within the tree I answer is yes we know that something has been removed from the tree and even was on the roof of a particular branch of the Cherry set a uniquely powerful and nicely feel to know what s going on inside of your air exile document as were saying that you don t come to do this on Excel and deposited on its attribute and in fact it lives on our classical sex object which these things ultimately derive from if we follow this through let the less described as change meant to go to definition he ll known another such a definition here you can see it actually classical ex object living up there said it are a couple of things about this API and the eventing stuff and the allocation stuff that lets you do some nice intellectual tree that you might otherwise have to build code for so just a quick summary here when you look at ex element in exact route and in fact it s not just those two it s the other ex classes that you might find within and

Minute 10

Director Mel something like ex processing instruction and so on they all have these allegations collection and they has this changed in changing set of events the allegations collection I has to store arbitrary objects inside of the XML tree but the main leg and back at a later point can be a very useful thing if you primary data structures of type XML and an eventing stuff allows to respond to changes before they happen as they happen after they have happened within the tree so it yet notifications us as things occur within Iraq s law document now if you want more information on link as a day centre up on MSDN developer Centre at their anti war wife measure the specific video feel free to mail me and other than that sense of watching a funny useful and I would hope to catch up with the future perhaps that and in person event or via Wallabies can videos or e mail something like that the future

Click here to go to original video page

No comments: