为什么可以';XML验证是否找到我的XSD?
我正在为一个大型XML文件创建模式文件,其中它的XSD文件使用了许多其他模式文件,这些文件包括其他小型模式文件。每次我尝试验证时,它都会出现,并说它找不到元素的模式信息 我曾尝试添加为什么可以';XML验证是否找到我的XSD?,xml,xsd,include,Xml,Xsd,Include,我正在为一个大型XML文件创建模式文件,其中它的XSD文件使用了许多其他模式文件,这些文件包括其他小型模式文件。每次我尝试验证时,它都会出现,并说它找不到元素的模式信息 我曾尝试添加targetNamespaces或使用import,但总是出现错误。Config XSD文件包括所有其他较小的模式文件,没有任何问题 <Config xmlns="C:\Users\xs\Desktop\Config.xsd" xmlns:xsi="http://www.w3.org/2001/
targetNamespaces
或使用import
,但总是出现错误。Config XSD文件包括所有其他较小的模式文件,没有任何问题
<Config xmlns="C:\Users\xs\Desktop\Config.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="C:\Users\xs\Desktop\Config.xsd">
<test>
<test2>
<TestDatabase Key="no">
<Class>blablabla</Class>
</TestDatabase>
<TestTimetable Key="no">
<Class>blablabla</Class>
<Report>
<Component>1</Component>
<Connection>1</Connection>
</Report>
<Connect>
<Delay>15</Delay>
<Period>30</Period>
</Connect>
<Abc>
<Factory>jk</Factory>
<Url>www.jk.com</Url>
<Topic>a</Topic>
<Queue>1</Queue>
<User>p1</User>
<Password>xxx</Password>
</Abc>
</TestTimetable>
</test2>
</test>
</Config>
喋喋不休
喋喋不休
1.
1.
15
30
jk
www.jk.com
A.
1.
p1
xxx
配置XML文件的架构文件:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="file:///C:\Users\xs\Desktop\TestDatabase.xsd" />
<xs:include schemaLocation="file:///C:\Users\xs\Desktop\TestTimetable.xsd" />
<xs:element name="Config">
<xs:complexType>
<xs:sequence>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element name="Test2">
<xs:complexType>
<xs:sequence>
<xs:element name="TestDatabase" type="TestDatabaseType" />
<xs:element name="TestTimetable" type="TestTimetableType" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
和
TestTimetableType
都有自己的include,它来自于类似报告
和连接
的模式 看起来您希望在没有名称空间的情况下执行此操作
(1)删除XML文件中的此行:
xmlns="C:\Users\xs\Desktop\Config.xsd"
xsi:schemaLocation="C:\Users\xs\Desktop\Config.xsd">
xsi:noNamespaceSchemaLocation="file:///C:\Users\xs\Desktop\Config.xsd">
(2)更改XML文件中的此行:
xmlns="C:\Users\xs\Desktop\Config.xsd"
xsi:schemaLocation="C:\Users\xs\Desktop\Config.xsd">
xsi:noNamespaceSchemaLocation="file:///C:\Users\xs\Desktop\Config.xsd">
对此:
xmlns="C:\Users\xs\Desktop\Config.xsd"
xsi:schemaLocation="C:\Users\xs\Desktop\Config.xsd">
xsi:noNamespaceSchemaLocation="file:///C:\Users\xs\Desktop\Config.xsd">
说明:
xmlns="C:\Users\xs\Desktop\Config.xsd"
xsi:schemaLocation="C:\Users\xs\Desktop\Config.xsd">
xsi:noNamespaceSchemaLocation="file:///C:\Users\xs\Desktop\Config.xsd">
属性适用于具有名称空间的情况。需要 名称空间URI对;使用xsi:schemaLocation
指定不带命名空间的XSDxsi:noNamespaceSchemaLocation
- 如果希望指定本地XSD的完整路径,请使用
file://
还要注意,XML是区分大小写的,因此
test
与test
等不同。如果显示整个Config.xsd文件(省略了xs:schema元素及其属性)并且共享特定的错误消息,可能会有所帮助。这个问题可能与名称空间有关。感谢您对schemaLocation的帮助和澄清,错误是在其他模式的包含中出现了拼写错误。