xml - 使用 erlsom 编写 XML 时出现问题

标签 xml xsd erlang

我正忙于 Erlang 中使用大量 XML 的项目,并且正在尝试学习如何使用 erlsom 在 Erlang 中编写 XML。在奋斗了整整两天之后,我现在已经抓狂了,而且我读得越多,我就越感到困惑。

XSD 文件 (csta.xsd) 的摘录,其中包含代码停止工作的部分:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 rel. 4 U (http://www.xmlspy.com) by Thomas Miller (Siemens Enterprise Networks) -->
<xsd:schema targetNamespace="http://www.ecma-international.org/standards/ecma-323/csta/ed3" xmlns:csta="http://www.ecma-international.org/standards/ecma-323/csta/ed3" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="my_envelope.xsd"/>
  <xsd:annotation>
    <xsd:documentation>csta</xsd:documentation>
  </xsd:annotation>
  <xsd:annotation>
    <xsd:documentation>Capability Exchange Services</xsd:documentation>
  </xsd:annotation>
  <xsd:include schemaLocation="get-csta-features.xsd"/>
  <xsd:include schemaLocation="get-logical-device-information.xsd"/>
  <xsd:include schemaLocation="get-physical-device-information.xsd"/>
  <xsd:include schemaLocation="get-switching-function-capabilities.xsd"/>
  <xsd:include schemaLocation="get-switching-function-devices.xsd"/>
  <xsd:include schemaLocation="switching-function-devices.xsd"/>
  <xsd:annotation>
    <xsd:documentation>System Services</xsd:documentation>
  </xsd:annotation>

在 Erlang 中,我正在执行以下操作:

XsdFile = "/home/renato/projects/rnlib-erl/rnlib-erl/dmcc/xsd/csta-schemas/csta.xsd".
XsdDir = filename:dirname(XsdFile).
erlsom:compile_xsd_file(XsdFile).

出现错误:

{error,"Include file not found my_envelope.xsd"}

我可以(以某种方式)接受,所以我尝试:

erlsom:compile_xsd_file(XsdFile, [{include_dirs, XsdDir}]).

Erlang 返回以下错误:

** exception throw: {'EXIT',{function_clause,[{filename,join,
                                                        [47,"my_envelope.xsd"],
                                                        [{file,"filename.erl"},{line,409}]},
                                              {filename,join,1,[{file,"filename.erl"},{line,396}]},
                                              {erlsom_lib,findFileInDirs,2,
                                                          [{file,"erlsom_lib.erl"},{line,864}]},
                                              {erlsom_lib,findFile,4,[{file,"erlsom_lib.erl"},{line,828}]},
                                              {erlsom_compile,processImports,2,
                                                              [{file,"erlsom_compile.erl"},{line,306}]},
                                              {erlsom_compile,transform,2,
                                                              [{file,"erlsom_compile.erl"},{line,278}]},
                                              {erlsom_compile,compile_parsed_xsd,10,
                                                              [{file,"erlsom_compile.erl"},{line,250}]},
                                              {erlsom,compile_xsd,2,[{file,"erlsom.erl"},{line,142}]}]}}
     in function  erlsom:compile_xsd/2 (erlsom.erl, line 144)

my_envelope.xsdcsta.xsd 位于同一目录

我做错了什么?

最佳答案

include_dirs 根据 reference 接受字符串的列表,而不是一个字符串。 .

由于该库没有尽早检查类型,因此您最终会遇到一个神秘的错误,该错误大致翻译为 erlsom_lib:findFileInDirs/2 最终调用 filename:join(47 , "my_envelope.xsd") (可能是因为 include_dirs 参数的第一个元素是 47,即 / 的 ASCII 值>).

这应该可以修复您最近的错误:

erlsom:compile_xsd_file(XsdFile, [{include_dirs, [XsdDir]}]).

关于xml - 使用 erlsom 编写 XML 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39126197/

相关文章:

用于并发编程的 .NET 语言

datetime - Erlang 中的日期算术

erlang - Erlang 有完整的 REPL 吗?

c++ - find_last_of 不适用于 xml 字符串

PHP DOM XML - 创建多个命名空间属性?

android - `titleTextAppearance` 不工作

XML Schema Identity constraints - 我可以在选择器的 XPath 中使用绝对路径吗?

xml - s4s-att-不允许 : Attribute 'name' cannot appear in element 'simpleType'

java - 如何检查java类中是否有特定的方法?

xml - Xpath/XSLT : check if following sibling is a particular node