What are "xmlns" and "xsi:schemaLocation" in XML files?


Publication Date:January 18, 2021



INFOMARTION > What are "xmlns" and "xsi:schemaLocation" in XML files?

summary

I would like to explain what "xmlns", "xsi:schemaLocation", etc. mean in XML files.

Table of Contents

  1. What is an XML file?
  2. summary

1. What is an XML file?

XML stands for Extensible Markup Language and is specified by the World Wide Web Consortium (W3C). If you want to know more detailed specifications other than "xmlns" and "xsi:schemaLocation", please refer to the following sites.

https://www.w3.org/TR/xml/

1-1. What are "xmlns" and "xsi:schemaLocation"?

The following is an example of the first description in an XML file when using the Spring framework for Java application development.

applicationContext.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

In conclusion, "xmlns" and "xsi:schemaLocation" are settings for definitions about how XML is written. In Java application development, the Spring framework performs processing based on the data contained in this XML file. If there is no definition on how to write XML, you will not know how to write it. So, for example, they define "id attribute can be defined in the bean tag" and "constructor-arg tag can be defined in the inner tag of the bean tag".

1-2. What is xmlns?

xmlns refers to "XML namespace. Briefly, a namespace is an ID, or uniquely identifying value.

In the previous example, using "xmlns="http://www.springframework.org/schema/beans" as an example, "http://www.springframework.org/schema/beans" is the namespace, or the value that uniquely identifies The value of "" is a namespace, i.e., a uniquely identifying value.

It is a URL, but when the program processes it, it does not process it as a URL, but as an ID. Therefore, the process is performed by finding the XSD file (XML definition file) in which "http://www.springframework.org/schema/beans" is defined as an ID and checking whether it is described as defined in the XSD file. The process is performed by looking for an XSD file (XML definition file) with "" defined as the ID and checking if it is listed as defined in the XSD file. In the case of Spring, the XSD file is also stored as a set in the jar file.

1-3. What is "xmlns:xsi"?

xmlns" and "xmlns:xsi" are settings to avoid duplicate definitions. For example, if the same SAMPLE tag is defined for "xmlns" and "xmlns:xsi", it is impossible to determine which definition is being described. Therefore, by defining "xmlns" and "xmlns:xsi", it is possible to distinguish the definition of "xmlns" for "sample" and "xsi:sample" for "xmlns:xsi". In other words, "xmlns="~"" is the default value, and "xmlns:xxxx="~"" must be defined as "xxxx:tag name".

2. summary

xmlns" and "xsi:schemaLocation" are definition file settings for writing XML files correctly.

Thank you for taking the time to read this to the end.




■INFORMATION

Please click here to go to the top page of INFORMATION.


■PROFILE

Please click here to view the profile.


■For inquiries, please contact

For inquiries about the article, please contact us here.