1.xsd文件:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://schemas.android.com/apk/res/android">
<xs:attribute name="debuggable" type="xs:string"/>
</xs:schema>
2.xsd文件:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
<xs:import xmlns:android="http://schemas.android.com/apk/res/android" namespace="http://schemas.android.com/apk/res/android" schemaLocation="1.xsd" />
...
<xs:attribute ref="android:debuggable" use="optional" fixed="false" />
...
当我尝试使用文件2.xsd调用assertValid
时,它将无法检测到debuggable
设置为true
。但是,当我将fixed="false"
移动到1.xsd(仍然将文件2加载为模式(时,它会起作用。是因为文件2中的键正在引用文件1中的属性,无法向其添加更多属性吗?无论如何,在不修改文件1的情况下绕过它?
原来lxml
有问题。。。我以后会想办法的。我用xmlschema
替换了lxml
库,没有做任何更改,一切都像一个符咒。
lxml
中的assertValid
返回true,而xmlschema
中的is_valid
返回false,这是一个非常奇怪的情况。
如果你遇到它,希望这能帮助别人节省一点时间。