2

我的 XML

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
    xsi="http://www.w3.org/2001/XMLSchema-instance"
    schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                    http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Entities\Aplikasi" table="aplikasi">
        <field name="nama" type="string" column="nama" length="20" precision="0" scale="0" unique="1"/>
        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
        </id>
    </entity>
</doctrine-mapping>

我在尝试通过 Netbeans 验证它时得到了这个结果

XML validation started.
Checking file:/home/meh/doctrine2/Entities/Mappings/Entities.Apliksi.dcm.xml...
cvc-elt.1: Cannot find the declaration of element 'doctrine-mapping'. [5] 
XML validation finished.

我也未能在http://www.validome.org/xml/validate/上验证 XML

我如何确保它是有效的?

4

2 回答 2

1

我必须进行一些更改来验证 XML:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="EntitiesAplikasi" table="aplikasi">
        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
        </id>

        <field name="nama" type="string" column="nama" length="20" unique="1"/>
   </entity>
</doctrine-mapping>

我必须在之前添加前缀和xmlns之前xsi的前缀xsischemaLocation然后将 id 移到字段上方并删除精度和比例属性。

如果您在 Web 浏览器中导航到架构并选择查看源代码或只是下载它,您可以阅读架构以确定有效的 XML 应该是什么样子。

于 2010-11-27T05:54:58.870 回答
1

使用 Netbeans 验证任何 XML Schema(XSD 文件,如 any-xml-schema-name.xsd)时也会出现同样的问题。


在使用您的解决方案之前,我的代码是:

<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema" 

但它总是无法验证,并显示错误消息:“找不到元素'xs:schema'的声明”


现在,使用您的解决方案,我只是将上面的相同代码更改为:

<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema.xsd"

它正在工作。


谢谢!
马尔西奥·韦斯利·博尔赫斯
http://marciowb.info

于 2011-11-17T18:02:09.380 回答