I found some tips for this problem, but still didn't help me.
我找到了一些关于这个问题的提示,但仍然没有帮助我。
Here is my XML
这是我的XML
<?xml version="1.0" encoding="UTF-8"?>
<work xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.w3.org/2001/XMLSchema-instance"
tns:schemaLocation="myXSDSchema.xsd">
<tns:Objects>
<tns:Object Name=":" Location=":">
</tns:Object>
</tns:Objects>
</work>
Here is my XSD file:
这是我的XSD文件:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns = "http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
(some checks)
</schema>
My XSD file is located in the same folder as the XML.
我的XSD文件与XML位于同一文件夹中。
How to link these 2 files?
如何链接这2个文件?
1 个解决方案
#1
9
How to link an XSD to an XML document depends upon whether the XML document is using namespaces or not...
如何将XSD链接到XML文档取决于XML文档是否使用命名空间...
Without namespaces
Use xsi:noNamespaceSchemaLocation
to provide a hint as to the XSD to be used:
使用xsi:noNamespaceSchemaLocation提供有关要使用的XSD的提示:
-
XML
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="example.xsd"> <!-- ... --> </root>
-
XSD
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="root"> <!-- ... --> </xsd:element> </xsd:schema>
XML
XSD
With namespaces
Use xsi:schemaLocation
to provide a hint as to the XSD to be used:
使用xsi:schemaLocation提供有关要使用的XSD的提示:
-
XML
<ns:root xmlns:ns="http://example.com/ns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://example.com/ns example-ns.xsd"> <!-- ... --> </ns:root>
-
XSD
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com/ns"> <xsd:element name="root"> <!-- ... --> </xsd:element> </xsd:schema>
XML
XSD
#1
9
How to link an XSD to an XML document depends upon whether the XML document is using namespaces or not...
如何将XSD链接到XML文档取决于XML文档是否使用命名空间...
Without namespaces
Use xsi:noNamespaceSchemaLocation
to provide a hint as to the XSD to be used:
使用xsi:noNamespaceSchemaLocation提供有关要使用的XSD的提示:
-
XML
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="example.xsd"> <!-- ... --> </root>
-
XSD
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="root"> <!-- ... --> </xsd:element> </xsd:schema>
XML
XSD
With namespaces
Use xsi:schemaLocation
to provide a hint as to the XSD to be used:
使用xsi:schemaLocation提供有关要使用的XSD的提示:
-
XML
<ns:root xmlns:ns="http://example.com/ns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://example.com/ns example-ns.xsd"> <!-- ... --> </ns:root>
-
XSD
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com/ns"> <xsd:element name="root"> <!-- ... --> </xsd:element> </xsd:schema>
XML
XSD