2010-12-20 65 views
0

我的Xml没有正确验证对XSD。 我希望浏览器通过ATLEAST某种一般性错误消息,当我打开XML文件为什么在验证我的xml时没有出现任何错误?

我的XML文件是低于 note.Xml

<?xml version="1.0"?> 
    <note 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:SchemaLocation="note.xsd"> 
     <from>Jani</from> 
     <heading>Reminder</heading> 
     <body>Don't forget me this weekend!</body> 
     </note> 

我的XSD文件低于 note.xsd

 <?xml version="1.0"?> 
     <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="note"> 
     <xs:complexType> 
     <xs:sequence> 
     <xs:element name="from" type="xs:string"/> 
     <xs:element name="heading" type="xs:string"/> 
     <xs:element name="body" type="xs:string"/> 
     </xs:sequence> 
     <xs:attribute name="to" type="xs:string" use="required"/> 
     </xs:complexType> 
      </xs:element></xs:schema> 

note.xml和note.xsd文件都在同一个文件夹中。 有人可以指导为什么我没有得到任何错误?所以任何人都可以帮助我如何使用xsd验证我的xml文件?谢谢你,

+0

你使用哪种编程语言? – 2010-12-20 13:28:29

+0

这个问题与xslt无关。重新加标签。 – 2010-12-20 15:00:20

回答

1

三个问题:

  1. xsi:schemaLocation属性值 应该命名空间URI的空白分开 顺序和模式 文件URI,如xsi:schemaLocation="http://www.w3schools.com note.xsd"
  2. 您写道:

    我希望浏览器能通过 至少有一种通用错误

    目前尚不清楚你是否使用一些验证工具实际上是 。没有 当您打开一个XML文档时,浏览器验证XML Schema 。

  3. 你的架构瞄准 http://www.w3schools.com命名空间 URI,但你的文件是根据空 (或空)的命名空间URI。这将使 最终出现验证错误,即使您使用 xsi:noNamespaceSchemaLocation 而不是xsi:schemaLocation 属性。也许你想在 输入源添加 默认命名空间声明一样 xmlns="http://www.w3schools.com" ...
相关问题