XML 命名空间如何在没有工作网络连接的情况下工

How do XML namespaces work without a working network connection?(XML 命名空间如何在没有工作网络连接的情况下工作?)
本文介绍了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:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.1.xsd">

  <context:component-scan
      base-package="com.springinaction.chapter01.knight" />

</beans>

上面的例子显示了一个带有多个命名空间的 XML 文件的例子.这些名称空间的目的是什么?最重要的是,为什么即使在没有 Internet 连接的情况下它们也能工作?

The above example shows an example of an XML file with several namespaces. What is the purpose of these namespaces and most importantly why do they work even where there is no Internet connection?

我认为以 xsi:schemaLocation 开头的第二位包含用于验证 XML 文档结构的 XML 模式文件.如果我在不在网络上的机器上运行使用此配置文件的应用程序,这些为什么仍然有效?这些 URL 是否是 JAR 文件的别名?

I think the second bit that starts with xsi:schemaLocation contains the XML schema files which are used to validate the structure of the XML document. How come these still work if I run the application that uses this configuration file on a machine that is not on a network? Are the URLs somehow aliases to JAR files?

推荐答案

假设我们有这个 XML 文档.

Let us assume we have this XML document.

<?xml version="1.0" encoding="UTF-8"?>
<html>
      <body>
        Your text here
      </body>
      <body>
        <height>182 cm</height>
        <weight>83 kg</weight>
      </body>
</html>

它包括 HTML,它有一个带有 HTML 渲染器语义含义的 body 标签.它还有另一个身体标签,其中包含有关特定人的信息.命名空间定义了这个标签的语义范围.如果没有命名空间(如提供的示例中所示),解析器就不可能区分它们,因为它们在语法上是相同的.

It includes HTML which has a body tag with a semantic meaning for a HTML renderer. It also has another body tag which carries information about a specific person. A namespace defines a semantic scope for this tag. Without a namespace(as in the example provided), it is impossible for a parser to tell the difference because they are syntactically the same.

这是同一文档的语义正确版本:

Here is the semantically correct version of the same document:

<?xml version="1.0" encoding="UTF-8"?>
<html:html xmlns:html="http://www.w3.org/TR/xhtml1/">
  <html:body>
    Your text here
  </html:body>
  <human:body xmlns:human="http://www.example.com/human/">
    <human:height>182 cm</human:height>
    <human:weight>83 kg</human:weight>
  </human:body>
</html:html>

因此,多亏了命名空间,我们不必担心具有不同含义的标签冲突.

Thus thanks to namespaces we do not have worry about conflicting tags with different meanings.

命名空间 URI 本身从未真正解析过,并且是任意的(因此您可以离线使用它们).

The namespace URIs themselves are never actually resolved, and are arbitrary (thus you can use them offline).

这篇关于XML 命名空间如何在没有工作网络连接的情况下工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)