Java 蚂蚁:build.xml; XML 文档结构必须在同一实体内开始和结束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18037041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:58:02  来源:igfitidea点击:

Ant:build.xml; XML document structure must start and end within the same entity

javaxmlant

提问by LeandreM

I have the following directory structure

我有以下目录结构

+project
    +--profile
         +---src
         +---WebContent
         +---build

I am trying to compile and copy using Ant, but when I execute the following build.xmlfile I get this error XML document structure must start and end within the same entityand nothing else. I checked a couple of almost similar questions but none of them helped, the only question similar to this was collected by adding any thing within like a comment which didn't work for me. What am I missing in the build file?

我正在尝试使用 Ant 进行编译和复制,但是当我执行以下build.xml文件时,我收到此错误XML 文档结构必须在同一实体中开始和结束,没有别的。我检查了几个几乎相似的问题,但没有一个有帮助,唯一与此类似的问题是通过在评论中添加任何对我不起作用的内容来收集的。我在构建文件中缺少什么?

<?xml version="1.0"?>
<project name="profile" basedir="." default="Task-of-build">
<property name="src.dir" value="src"/>
<property name="webcontent.dir" value="WebContent"/>
<property name="javadoc" value="doc"/>
<property name="name" value="profile"/>
<property name="build.dir" value="${webcontent.dir}/WEB-INF/classes"/>
<property name="backup.dir" value="C:/project/backup"/>

<path id="classpathvalue">
    <fileset dir="${webcontent.dir}/WEB-INF/lib">
        <include name="*.jar"/>
    <!-- this is a comment -->
    </fileset>
    <pathelement path="${build.dir}"/>
</path>

<target name="javadoc">
    <javadoc packagenames="com.mucyo.prep.profile.*" sourcepath="${src.dir}"
        destdir = "doc" version="true" windowtitle="Profile Mngt">
       <doctitle><![CDATA[<h1>=Profile Mgnt =</h1>]]</doctitle>
       <bottom><![CDATA[Copyright 2011. All Rights reserved></bottom>
       <group title="Beans packages" packages="com.mucyo.prep.profile.bean.*"/>
       <group title="Service packages" pachages="com.mucyo.prep.profile.services.*"/>
       <group title="servlets packages" packages="com.mucyo.profile.servlets.*"/>
    </javadoc>
</target>
<target name="Task-of-build">
    <echo message="This a build example"/>
</target>
<target name="build" description="compiling java files">
    <mkdir dir="${build.dir}"/>
    <javac destdir="${build.dir}" source="1.6" target="1.6" debug="true"
       deprecation="false" optimize="false" failonerror="true">
          <src path="${src.dir}"/>
          <classpath refid="classpathvalue"/>
    </javac>
</target>
<target name="create-war" depends="build">
    <war destfile="${name}.war" webxml="${webcontent.dir}/WEB-INF/web.xml">
       <fileset dir=".">
          <include name="**/*.*"/>
       </fileset>
    </war>
</target>
<target name="backup" depends="build">
    <mkdir dir="${backup.dir}"/>
    <copy todir="${backup.dir}" preservelastmodified="true">
       <fileset dir=".">
          <include dir="${src.dir}:${build.dir}"/>
       </fileset>
    </copy>
</target>
<target name="clean" depends="build">
    <delete>
       <fileset dir="${build.dir}">
          <include name="**/*.class"/>
       </fileset>
    </delete>
</target>
</project>

采纳答案by Jon Skeet

I believe this is the problem:

我相信这是问题所在:

<doctitle><![CDATA[<h1>=Profile Mgnt =</h1>]]</doctitle>
<bottom><![CDATA[Copyright 2011. All Rights reserved></bottom>

Neither of your CDATA sections are properly terminated, so your file is simply not valid XML. I think you should have:

您的 CDATA 部分都没有正确终止,因此您的文件根本不是有效的 XML。我认为你应该有:

<doctitle><![CDATA[<h1>=Profile Mgnt =</h1>]]></doctitle>
<bottom><![CDATA[Copyright 2011. All Rights reserved>]]></bottom>

... although as the second of these strings does anything which requires escaping in XML, I woudln't even use a CDATA section for it:

...虽然这些字符串中的第二个执行任何需要在 XML 中转义的操作,但我什至不会使用 CDATA 部分:

<doctitle><![CDATA[<h1>=Profile Mgnt =</h1>]]></doctitle>
<bottom>Copyright 2011. All Rights reserved></bottom>

... and even the first one just needs the open angle brackets escaping:

...甚至第一个只需要打开尖括号转义:

<doctitle>&lt;h1>=Profile Mgnt =&lt;/h1></doctitle>
<bottom>Copyright 2011. All Rights reserved></bottom>

(You might chose to convert >to &gt;as well, but I don't believe you have to.)

(你可能会选择转换>&gt;为好,但我不相信你有。)