Presenter:Mike Taulty
LINQ to XML offers radically new and slick ways to create XML. In this session we'll take a look at how we can statically and dynamically generate XML from VB.
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
Oh miners might alternate with Microsoft in the UK and this is one of a number of sessions about the new technology coming in visual studio coming August August will be the next version of visual studio that follows on from 2005 and the technology would regret he is cool language integrated query to XML what this does is a new XML API in Donovan 3 5 which will come with visual studio cut in August and it puts the language integrated query pattern on top of that new API giving is interesting ways to query and create XML in this particular video without a quick look at how we would create XML with Visual Basic using link to XML and new API that we ve got gay I m here in visual studio code in August it is the March technology preview it was the latest publicly available preview at the time of making the video and register a new project inside visual studio will pick a VB project will go for car
Minute 1
On application and then discover great about and in order to programme against the link to XML pieces at this point only to go out and add a reference to my project was good or haven t had a reference here and we re adding it to a friend at assembly that at the time of making the video lives in C Windows Microsoft net framework the time framework version and were looking for system xml link at his access to the new Irving to expel API is so the new API that we ve got four link to XML is a very intuitive way of creating XML documents and if you have a look very quickly creating some XML with it hopefully that will illustrate what we can do and how it works so one of the key classes in the API is a thing called an ex element it represents an XML element
Minute 2
So we can say straightaway left him of my route as new ex element and we can give that a name that all this route that gives us a root element straightaway let go and save that we can save from here will go to SECAM test xml and we can go and do something like I need to displayed up for a salt in processed start and will give it see Countess of XML as little a reconstructed in XML and we seen i e the guts of XML added there now in terms of creating child elements and so on we can very much so go ahead and say let s have another little call child and we can walk to the root element and we can add this child element and it is that what we get and here is an object or optionally we can also add a look at it
Minute 3
And parameter array of objects or a variable number of objects is significant that these objects and not ex nodes or something like that and will perhaps see why that is as we go along so I can absolutely adhere my child element and are getting a better five runner inside the environment than we get what we expected him to the XML that we are creating now what s really clever about this API is that the constructors are things like ex elements as you are the sort of hinted at can take as you can see here an object as content or in fact any number of parameters of type object which is anything as content as it has do s and only very natural way instead of creating a separate element and then adding the thing in what we ll do is simply passed the student constructor of ex element we can forget this call and we end up with that of the same thing that we saw a second ago but now
Minute 4
Constructing this in and very natural way fat and difficult consular an edited space in their everyone s out to children and of course we can copy this and have a second one of these in Cisco London finish braces ratify the man and there we are associated to us thanks to a fan of funky and the way that this works is the constructive play very well with the link syntax that we get in VB 9 took that 11 of that much greater a list of integers also deny as integer 2030 something like that and what would it here instead of just creating two elements feel safer on pound that the ex in either as a list of vintage that select a new ex element in the name of value or something like that in all but into that content is a
Minute 5
2 strain so now we dynamically iterated around this list of three numbers creating content from as gunrunner assimilated into the director now I can see that we get values that way and we could do the same thing with anchovies as well so let s just create one element here as a supplement so we ll have a new ex element will collect child again but into that what we ll do strictly attributes it will do from pound X in I select a new ex attribute now and in access it has given a name which is essentially at and will add an order to add the value of exit to make it easy for ourselves and will go out of the value of eggs in there as well such as dynamically creating attributes in Anfield on that but I managed to get them to missing a flight figure
Minute 6
And that there was it would dynamically creating attributes after 10 after 1020 to 30 and so on any idea about dynamically generating things in the way that closer links in tax we don t just have classes for ex element and let s attribute we have other classes so to some quick look at those the tournament onto something else in Phoebe but very the whole document so I offer and what you can do with ex element is a pretty big superset of what you can do an excellent document bar in the API there are a few more things you can do with document so great and dark as a new ex document notice that straightaway that is the fact that the intelligence that allows us to control the XML declaration so we can create a new ex declaration on the excellent document itself version 1 0 of externality easier 16
Minute 7
Since true as a stand alone document and within the air we can create things like elements so will go ahead an avenue ex element all this route within there are of course we can create additional ham subelements in fact before a greater element if I waited for the annexed processing instruction of the document tougher targets and some data and there will have some comments so having US comment on the document this is a common and everything great Alan Security seen on those elements such as finish lines are on those elements we can have attributes as you ve already seen a scoreless and my attribute and within those elements we can have other elements all we can have textual content just as a child of that element itself and hopefully figure of braces right we should be able to take that document and save it which have
Minute 8
Integer array s five Surrey managed to get until there is there where we just need to give this attribute of how you thousand and one is of the values of adverse discomfort of five Annie get XML created with God and XML declaration with processing industries with a comment with an element of an attribute and we got some textual content for the element that was created so that these is that we expect to see with an excellent document we can create using his classes ex element ex document ex comment ex attribute ex text and so on and so forth now where this gets particularly fond for VB is that VB has specific LAN support in the language for using this API so that it is back to basics and will declare ourselves
Minute 9
For is a driver s new instances of classes in the traditional way let s go and have route in Alice have a common and will also have a child on an unhonoured child and will have an attribute from within that will have some text content and essentially we can go and build that code and we can run at and we get the exact same effect as we saw below before and it s feeling about this is that the compiler notice that this is not text it is not tasted in terms of in the Midlands the compiler is clever enough and it is pretty clever to see this stuff here and turn it into an instance of ex element analyses this and turned into ex comment ex element ex attribute and ex text and suddenly be compiler can understand the effects of
Minute 10
Literals posted right into the middle of code so save the pain of having to type in all as class names and constructing ourselves now previously read it and dynamic generation so how would we do that with this new way of representing things so that Slovakia have other stuff integers again so will have 1020304050 and a list of integers and unimaginable we want to do is create a number of child elements that each one of those lists are intransigence on that list 20 comment on the minute and will add a little bit of dynamic content here and were going to say that within the bounds of this dynamic content will say from ex in I want we want to do is go ahead and select an hour back into the realms of some static content friend since a child and then there will pour
Minute 11
Iona lets have the value all ex or something like that is that where it is so extra to straying into the middle of the XML and I m probably missing a line continuation character somewhere the line continuation character into that and rebuild and missing a line continuation character and are doubtless built anything at all in our constructing is root Anderson dynamic stuff so it is piece of code and interspersed into that here is a little bit of static stuff again with the more dynamic stuff am static again and we gone on this and get the behaviour we expect with children 1020304050 coming naturally from creating a code and we can do a similar thing in terms of raising attributes so perhaps rather that our government with some attribute on it some of us have at your equals
Minute 12
And will go ahead and put in dynamic content into that instead was closed off out of element in regard and we can build that although sadly missed something status quo so I and every are again creating attributes that way too it gives a really neat and powerful intuitive obvious maintainable can you tell that I like it are really nice way of creating XML directly in code were still going all the power of those classes excelled in death attributes and so on and Ashley once recreated the SME reach into it to query it will still be giving the examined at attribute and so on but there s just has a really friendly way of constructing Excel straight from code spitting out the mixture of dynamic and static content which is often what you want to do in terms of XML generation if the generating something
Minute 13
In RSS feed in your low that the other names on the attribute names have been set in stone all you get to do is generate dynamic pits and that s where this kind of API and the inbuilt nature of the VB 9 language just play really well towards creating XML like this night as well as then if you re wondering why is not ultimately often thorny issue of economic spaces are not in our outlook on that adult learning spaces in a separate session just a quick summary monsignor we have new classes coming in that framework 2 5 with it was difficult importance that it was new ways of creating a query in Jackson we looked at creation he will look querying in another session those classes are called ex something ex document ex element ex attribute and so on and they have some very interesting constructors that letters create XML in a very intuitive way that plays very well with the language integrated query pattern we saw how we could use some enquiries
Minute 14
Aerodynamic bits of XML and even better than that with VB 9 we get explicit language support built right into the language for manipulating XML creating XML with these particular classes of 89 really went out three times here and that we get new and new API in mixes well with link as we get explicit support of the language in the life playing with that new API and using it now why can you have lots more of racial length at number one there is a great developer Centre on MSDN the URL is on screen and will find information are about all different aspects of linked including a link to XML that a good blog site of the linking action net that s only been reading quite a number of articles from that site as a great to be aware of if you re interested in link out if you want to ask the questions that we saw in the video feel free to mail me on my addresses the on screen and thank you for listening out to catch you at
Minute 15
Each events or
Click here to go to original video page
Monday, July 21, 2008
Video: Creating XML in VB with LINQ to XML
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment