问题描述
我正在尝试使用XSD验证XML。 XSD具有另一个XSD文件的导入。我不断收到错误PERL5LIB
。我正在使用Invalid XSD schema
软件包。版本libxmljs
0.19.7
测试文件
/src/
/script/
test.xsd
test1.xsd
testXML.xml
main.ts
test.xsd
@Injectable()
export class ScriptService {
async scriptFn() {
const rootPath: string = path.dirname(require.main.filename);
const xsdSchema = await fs.readFileSync(`${rootPath}/test.xsd`,'utf8');
const xsdDoc = parseXml(xsdSchema,{ baseUrl: `${rootPath}/` });
const xmlRequestString: string = await fs.readFileSync(`${rootPath}/testXML.xml`,'utf8');
const xmlRequest = parseXml(xmlRequestString);
await xmlRequest.validate(xsdDoc)
}
}
它似乎在以下行崩溃。导入确实有效。
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://schemas.w3.org/types"
elementFormDefault="qualified"
xmlns="http://schemas.w3.org/types"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:test="http://schemas.w3.org/TestTypes"
>
<xs:import namespace="test1.xsd" schemaLocation="test1.xsd" />
<!-- Import External elements-->
<xs:element name="type" type="test:type" />
<xs:element name="size" type="test:size" />
</xs:schema>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)