The third of the Spring Series, XML parsing related

Source: Internet
Author: User

Through the introduction of the 2nd Chapter, we should know how spring can parse the BD object into the container from the XML step, and this process has a summary understanding.

The next step is to analyze the XML-related things in detail.

First, take a look at the XML document you are using.

<?xmlversion= "1.0" encoding= "UTF-8"? ><beansxmlns= "Http://www.springframework.org/schema/beans"         xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"         xsi:schemalocation= "http://www.springframework.org/schema/beans               http://www.springframework.org/schema/beans/ Spring-beans-3.1.xsd ">               <beanid= "Beijingcard" class= "Com.spring.examples.ioc.bean.Card"   >                      < Propertyname= "Cardno" value= "6220-52103-4123-456" ></property>                      <propertyname= " Bank "value=" Beijing/>              </bean>               <beanid= "Jianshecard" class= " Com.spring.examples.ioc.bean.Card ">                      <propertyname= "Cardno" value= "6227-52103-4123-456" > </property>                      <propertyname= "bank" value= "CCB"/>               </bean>                             <beanid= "Miyue"   class= "Com.spring.examples.ioc.bean.User" primary= "true"    Scope= "Singleton" >                     < Propertyname= "UserName" value= "芈 Month" ></property>                      <propertyname= "Email" value= "[email  protected] "></property>                      <propertyname= "Cardlist" >                              <list>                                            <refbean= "BeijingCard"/ >                                            <refbean= "Jianshecard"/>                              </list>                      </property>               </bean></beans>

A brief introduction to XML-related concepts.

XML refers to extensible Markup language.

The first line is the XML declaration. It defines the version of the XML (1.0) and the encoding UTF-8 used).


beans > (like saying, "This document contains more than one Bean"):

Next is the sub-element <bean>. The specific label meaning will not say.

What I'm trying to say is the head of the documentxmlns= ". *",    xmlns:xsi= ". *", xsi:schemalocation= ". *" a piece of code meaning similar to the typeface.

These are namespace namespaces.

1. Namespaces

A) Why do you have a namespace?
The XML namespace provides a way to avoid element naming conflicts.
In XML, the name of the element is defined by the developer, and a naming conflict occurs when two different documents use the same element name.
b) Default namespace (defaults namespaces)
Defining a default namespace for an element allows us to omit the work of using prefixes in all child elements.
Format: xmlns= "NamespaceURI"
c) xsi:schemalocation
<xsi:schemalocation= "List of AnyURI" >
The SchemaLocation property references an XML schema document that has a target namespace.
The value of the Xsi:schemalocation property consists of a URI reference pair, separated by a space character between two URIs. The first URI is the name of the namespace, the second URI gives the location of the schema document, and the pattern processor will read the schema document from this location, and the target namespace of the schema document must match the first URI

2.XSD (XML Schema Definition)

The purpose of XML schema
1. Define what elements are in an XML document
2. Define what attributes will be in an XML document
3. Defines what child nodes are in a node, how many subnodes can be, and the order in which child nodes appear
4. Defines the data type of an element or attribute
5. Defines the default or fixed value of an element or attribute

Specific grammar, will not speak, interested in can search.


The role of the DTD (document type definition documentation types definitions) is to define the legitimate building blocks of XML documents.
Functions are similar to XSD. The specific use is as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd" >
XSD, you know, you can use XSD validation in spring2.0.


Second, the analysis of XML needs to focus

How 1.XML documents are converted to system resources

2. What engine is used to resolve

3. Parse the document element and parse it into a data carrier object


Next, we will answer each of these three questions.

How 1.XML documents are converted to system resources

    Public intloadbeandefinitions (Resource Resource) throws beandefinitionstoreexception {

      return loadbeandefinitions (NewEncodedresource (Resource));

   }


This article is from a "simple" blog, so be sure to keep this source http://dba10g.blog.51cto.com/764602/1727708

The third of the Spring Series, XML parsing related

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.