0

我有一个非常简单的 XML 文件,其结构如下:

<?xml version="1.0" encoding="utf-8"?>

<Projects 
  xmlns="http://w3schools.com"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://w3schools.com project_schema.xsd">  

  <Project Path="..." />
  <Project Path="..." />
</Projects>

然后,我创建了一个相应的 XSD 文件,因为我需要确保在编辑 XML 时它是有效的。因此,我创建了以下内容:

<?xml version="1.0" encoding="utf-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.w3schools.com"
           xmlns="http://www.w3schools.com"
           elementFormDefault="qualified">
  <xs:element name="Projects">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Project">
          <xs:complexType>
            <xs:attribute name="Path" type="xs:string" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

问题是我仍然从 Visual Studio 2013 收到这些验证错误。

消息 1 找不到元素“ ...://w3schools.com:Projects ”的架构信息。 xxx\01_prerequisites.xml

消息 3 找不到属性“路径”的架构信息。xxx\01_prerequisites.xml

任何想法?

4

1 回答 1

0

问题在于

xmlns="http://www.w3school.com"

我在 Schema 和 XML 文件上都使用了自己的命名空间,现在它可以正常工作了

于 2013-11-08T10:47:59.813 回答