fis*_*cme 3 php xml xsd xsd-validation
我正在尝试使用我编写的模式验证 xml 文件,但失败并显示以下行:
Element 'Route', attribute '{http://www.w3.org/XML/1998/namespace}space': The attribute '{http://www.w3.org/XML/1998/namespace}space' is not allowed.
Run Code Online (Sandbox Code Playgroud)
XML 文件有时包含以下内容:
<Route xml:space="preserve">
</Route>
Run Code Online (Sandbox Code Playgroud)
这显然是导致问题的原因,我可以对我的 xsd 文件做些什么来解决这个问题?
这是我的 XSD,删除了所有不相关的内容
<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet">
<xs:element name="Route" type="xs:string" minOccurs="0" />
<xs:element name="FurtherRequirements" type="xs:string" minOccurs="0" />
Run Code Online (Sandbox Code Playgroud)
等等等等
非常感谢所有帮助!
你必须Route从 is of type改变xs:string为 being of type string-with-xml-space,其中string-with-xml-space是一个内容简单的复杂类型,定义如下:
<xs:complexType name="string-with-xml-space">
<xs:complexContent>
<xs:extension base="xs:string">
<xs:attribute ref="xml:space"/>
Run Code Online (Sandbox Code Playgroud)
您还需要xs:importXML 命名空间的架构:
<xs:import namespace='http://www.w3.org/XML/1998/namespace'
schemaLocation='http://www.w3.org/2001/xml.xsd'/>
Run Code Online (Sandbox Code Playgroud)