Presenter:Beth Massi
Visual Basic developers will learn how to enable XML IntelliSense using schemas and how XML namespaces are used when querying and creating XML documents.
Click here to go to original video page
Minute 0
Honey my name is Beth Massey and today I m going to show you how you can enable XML IntelliSense when working with link to XML and Visual Basic and how you can use XML namespace is in the previous video I showed you how Visual Basic provides deep support for link to XML through what s called XML literals and XML access properties these features allow you to use familiar convenient syntax for working with XML in your Visual Basic code and even though you re welcome to call the link to XML APIs directly only Visual Basic allows you to declare XML literals directly access XML access properties and as well as provide XML IntelliSense on those properties I ve got Visual Studio 2008 opened and I ve already created a simple console application here and I bet to XML files when his plants and one is customers as they show the previous video we can love these documents into an ex document object and start writing
Minute 1
Days immediately for instance I can just do declare a variable here XML plants equals X document load and it ll be in my current or current directory and is just called plants XML case of this will load the XML into this X document object and already we can just write queries like I d show the previous video package a simple query here to MTU for instance we can just say from P N XML plants I plants did you notice I m not really getting any IntelliSense at all except on in the keywords here and not getting any and XML IntelliSense but we can still query
Minute 2
Prick teasing plate heat com in I have to know the structure of XML galas iterate over this is as good as return a a collection of strings so missed an essay for each PE and do what is right to the Council face of assists in a five and I ll show you there Cory worked okay but it really want to do is enable IntelliSense a day because I wanted to kick in when I access the XML access properties so let s see how we can quickly
Minute 3
Enable XML IntelliSense is a tool on the Visual Basic developer centers the download section called the XML to scheme until this will add a new item template into Visual Studio so you can easily infer from any XML resource on the web bomb 80 the eczema you have a desk where you can even paste the XML directly in from your clipboard so let s go ahead download this tool and install it really only takes a few minutes probably less than that in case an outstanding install just a new item template gay
Minute 4
Did you go ahead and right click on a project select add new item and assays go down to the bottom here I ll see in my templates XML schema and the innateness plans this will then open up based on the wizard here and you can now select a set ad from file on disk from the web are just as XML and I m an ad from file and there s my plants XML and you can actually add multiple resources pay so undecided it is a for this first example of an okay and in one fell swoop in and at this plant access the file now we know the structure we can go back into the module and I can write another query let s say we want to select all of the plants that cost more than five dollars so we ll just dim pricing plans
Minute 5
From claimed in an XML planet and now I m at the descendents that he ll notice that I get some IntelliSense may notice there s little question marks next to that IntelliSense list and that s because when I access be descended asked if that means I m trying to find any matching on elements in the entire document that s not exactly sure what a talented property would be so I m going to select plant when take it down into the cellar though it will know what we are now and open up the child axis is the check marks indicating that because under plant element they are definitely these children okay so now disconnects the price value
Minute 6
Tank is greater than it s been five and a will select the name equal to plant again now access the child and you ll see a distinct common value is the common name can t we just do for each event So it s another collection of names tanks of the plant is just a string days let s go ahead and run that when a comment is went all out okay so there is our result of our query
Minute 7
At how we can enable XML IntelliSense quite easily but you ll notice I ve got to XML documents in here so how do I work with multiple documents in the same file while that s where XML namespace is command we can imported namespace at the top of our file so that Visual Basic will know exactly which schema would be exposed to use similar to the way net organizes its massive framework in a namespace is to minimize name collisions when we use XML in her programs it also helps to add an XML namespace in the final desire to have won this XML namespace is used by Visual Basic to map the schema to the actual file you re working the namespace can be in the form of a URI which means it can be either a URL or you are and so that s not a namespace to our planet XML file and read for our schema so I m just going to delete the access to the file and
Minute 8
Into our plants in XML and I m going to add a namespace here some skin and a namespace XML and as equal to an end for this example will just say you re in my come and he samples plants became so just save that and we ll go ahead and read for our schema and now you ll notice we open the access key file that can he have a target namespace now came that s the namespace just a generic snuff out a case in that we can go back in your module and we can import namespace a sale on imported
Minute 9
Just the same way you import ask them at net namespace its case you import XML namespace is the same white case to understand you XML and asked Colin on the call this place and you ll see there is are namespace plants can t so now I m going to write queries to him keep equals from plant in XML plant and they ll UCR IntelliSense in now with the namespace and pay so there we go ahead with plant and will adjust to a select gain equal to plan to dive in and bears are valid child descendent
Minute 10
Sentences to common name again okay so now it looks value excuse me since he is a value to know if he can work with multiple XML schemas in the same file so you notice that I ve got customers XML and have already defined in the namespace and its customers to pay so when I do it now and for the customers XML file their schema for it easy and be XML to schema template again and he had from file customers this time and member academic the same time just for this example it to them separately they open up customers you ll see that the target namespace ratepayers customers tanks and I can go back to my module here we can import the namespace
Minute 11
Except this time I caught customers such as the prefix will be in there ago there s her namespace is we have defined in the project and now I can go ahead and create a new document I loaded up with our customers this time and I can write more queries and no notice now that you can see both of the schema s tag as it doesn t really know which one we re trying to
Minute 12
Are here yet so missed SA customers that customer Kay and now that when they do not it knows where we are in a retail tag so these are the valid children underneath the customer elements that some disconnect items like game thanks so that s basically how it works on disastrous for a completeness I ll just iterate through the queue to excuse me for each day soon have another collection of strings and pay site is select all of the customer names so you go ahead and run this
Minute 13
Full name spaces and schemas in our projects so I d like to thank you for your time if you d like to check out the Visual Basic developer Center will be posting updates these videos there please also check out the Visual Basic team blog and my blog for more information basic
Sunday, May 25, 2008
Video: How Do I: Enable XML IntelliSense and Use XML Namespaces?
Labels:
linq,
xml intellisense,
xml namespaces
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment