微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

libxmljs使用已导入的xsd验证xml

如何解决libxmljs使用已导入的xsd验证xml

我正在尝试使用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 举报,一经查实,本站将立刻删除。