元素类型“class”必须后跟属性规范,“>”或“/>”

时间:2017-10-27 14:19:46

标签: hibernate

我每次都会在第6行收到此xml错误。

<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
           "-//Hibernate/Hibernate Mapping DTD 3.0//EN"          
           "http://www.hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping package="com.ida.hibernate">
    <class name="Customer"table="customers"/>
    <id name="cid"column="cid"type="int">
    <genertor class="increment"/>
    </id>
    <property name="cname"column="cname"type="string"/>
    <property name="email"column="email"type="string"/>
    <property name="phone"column="phone"type="long"/>
    <property name="city"column="city"type="string"/>
    <property name="bal"column="bal"type="double"/>
    </class>
    </hibernate-mapping>

1 个答案:

答案 0 :(得分:0)


<class name="Customer"table="customers"/>
==&gt;这相当于<class name="Customer"table="customers"></class>
替换为
<class name="Customer" table="customers">

在属性

之间添加空格

您可以使用https://codebeautify.org/xmlvalidatorhttp://xmlbeautifier.com/等网站来验证和美化XML

<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping package="com.ida.hibernate">
    <class name="Customer" table="customers">
        <id name="cid" column="cid" type="int">
            <genertor class="increment" />
        </id>
        <property name="cname" column="cname" type="string" />
        <property name="email" column="email" type="string" />
        <property name="phone" column="phone" type="long" />
        <property name="city" column="city" type="string" />
        <property name="bal" column="bal" type="double" />
    </class>
</hibernate-mapping>