假设我们具有以下XML结构:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>ProjectName</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<prefix>git</prefix>
<verbose>false</verbose>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/${artifactId}_git.properties</generateGitPropertiesFilename>
<format>json</format>
</configuration>
</plugin>
</plugins>
</build>
</project>
我在下一行中看到对artifactId
的引用,解析为 ProjectName (文件中的第一个artifactId),而不是 git-commit-id-plugin >(文件中的第二工件ID)。
<generateGitPropertiesFilename>${project.build.outputDirectory}/${artifactId}_git.properties</generateGitPropertiesFilename>
XML解析器如何解析对存在多次(在不同级别)的属性的引用?它是否解析为在当前级别之前可以找到的最高级别(假定根是最高级别)同名的属性??
答案 0 :(得分:1)
一个XML解析器...好吧...解析。它与xml内容的解释无关。 xml的使用者(需要该xml的程序的作者)由"${project.build.outputDirectory}/${artifactId}_git.properties"
这样的字符串组成。那只是一个字符串。 XML解析器没有其含义的概念。至于消费者,他可以用自己喜欢的任何东西代替artifactId
。它可能是project.artifactId
。它可能是project.build.plugins.plugin.artifactId
。甚至可能像诗一样奇怪。因此,直到阅读了该特定xml配置文件的文档,您才能知道。
PS。然后...还有XSLT。但这是一个不同的故事。但是输出相同-在阅读XSLT代码或一些文档之前,您永远都不知道结果是什么。
答案 1 :(得分:1)
该文档声称符合http://maven.apache.org/xsd/maven-4.0.0.xsd上的架构,因此,要查找名为工件ID的元素的含义,您需要查看该架构。 XML解析器本身会忽略架构,但是如果执行架构验证(可以在XML解析过程中或单独执行),则架构验证器将考虑架构施加的任何约束,例如, ,说一个元素的内容是对另一个元素名称的引用。
但是,在这种情况下,架构将artefactId定义为字符串。因此,该字符串的含义仅取决于处理XML的应用程序,并考虑到XML的发送者和接收者之间就字段的使用方式达成的任何显式或隐式协议。