XML Namespace tutorial for complete Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello and welcome to this session I am Raghav and in this session, We are going to learn all about XML namespace Do not worry If you have no prior knowledge on this topic I will go very basic step by step and we will start from scratch. So let's get started Let us see this example We have an XML where we have a table element and inside the table element We have 3 more elements and with the information, it is giving us It looks like we are talking about a Furniture table here. If you look at this another XML here again, we have our table element and then we have elements like TR TD, which is for rows and columns and it looks like here we are talking about HTML table Now This is all fine If these two tables- if these are two XML's I used separately and they are not associated with each other in any ways However, if we happen to combine these To xml's together, they will be a conflict because of the common table element and to resolve this conflict We can use a prefix in our elements For example, if I talk about the furniture table here, I can add a prefix and here you can see we have added a prefix called f for all the elements here And now for the HTML table we can do something similar here We have added a prefix h in front of all the elements and now these two elements are different and they can be used together and then they will be no conflict because we are using different names now until now we have just talked about prefixes that will help us to resolve the conflicts when we have common elements We need to understand about the XMLns or XML namespace attribute whenever we are using prefixes in our XML a namespace for the prefix must be defined and here is the syntax We say xmlns whatever the prefix we have used equals to our URI For example, if we happen to combine our earlier 2 xml's together. I will create a root element and then here we have our first XML that talks about HTML table and here we have a prefix H already added to all the elements and here I will say xmlns:h which is the prefix equals to r u r i so this is how we can declare a namespace and the namespace can be declared and defined in the starting of the element or the starting of the XML in the root element itself And then all the child elements for that particular tag or element will be associated with the same namespace and here you can see the other XML here I can define a XML namespace attribute like this and I will give the prefix here and this is how I can Define it and we can also Define or declare all the name spaces in the root element itself so that we do not have to Define him Define the XML namespace or declare them every time in the rest of the XML here is how we do that You can see I have defined both the XML namespaces in the root element itself Now I do not need to declare them again in the XML Let me show you an example I will go to Google and search for Sample web service so that I can show you some XML and I'm going to this calculator web service here And here if I go to this service description, which will be a XML document You can see here All the namespaces are declared in the starting in the root element itself And then in the rest of the XML I do not need to declare them again, I can directly use the prefixes and this is how we can use a XML namespace now We need to understand about default name spaces Now if you define a Default namespace for an element all the child elements will be associated with that name space and it will save us from using prefixes in all the child elements. And this is how we do it We say XMLns = namespace URI and here you can see an example here I have added the XML namespace attribute and all the child elements will be now associated with this XML namespace and I do not need to add the fixes for all the elements and this is another example, let me show you here This is our XML document and this is actually a wsdl which is web services description language And this is what we use in soap API's Now do not worry about that I have a separate video to explain what is wsdl, but just for parsing this document this XML document I can use a extension on my Chrome browser So if I go to the web store and On my Chrome I can use extension called Whistler and this is used to parse a wsdl document And this is the extension I have already added it And here it is This will pass the XML document So I will click this and it shows me all the services in this XML I can click on any of the service and it shows me the XML of that API service or that request and here you can see this is how we can define a XML namespace and all the child elements will be associated with this particular namespace now in case any of the child elements needs to be associated with a different name space You can also do like this So here the add element belongs to this namespace and all its child elements will now be associated with this particular namespace. So this is how you can Define default namespaces now Wikipedia says that XML Spaces are used for providing uniquely named elements and attributes in an XML document and I hope now you understand this. We have learned this in a very simple way I hope all this was useful You can go and share your knowledge with everyone also Let me know how did you like this video and I will meet you in the next session Thank you for watching.
Info
Channel: Automation Step by Step
Views: 95,931
Rating: undefined out of 5
Keywords: automation testing beginner tutorials, what is namespaces in xml, xml namespace tutorial, what is namespace, how to create namespace, what is the use of namepsaces in xml, xml beginner tutorial, xml for beginners, learn xml full course
Id: VTQRGDhH6WQ
Channel Id: undefined
Length: 6min 43sec (403 seconds)
Published: Thu Nov 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.