我正忙于使用大量XML的Erlang项目,并且正在尝试学习如何使用erlsom在Erlang中编写XML。在挣扎了整整2天之后,我现在把头发拉了出来,现在我读的越多,我就越困惑。
包含代码停止工作的部分的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.xsd
与csta.xsd
我做错了什么?
答案 0 :(得分:3)
include_dirs
接受字符串的列表,而不是一个字符串。
由于库没有尽早检查类型,最终会出现一个神秘的错误,大致转化为erlsom_lib:findFileInDirs/2
最终调用filename:join(47, "my_envelope.xsd")
的事实(可能是因为你的参数的第一个元素) include_dirs
为47
,ASCII值为/
)。
这应该可以解决您的最新错误:
erlsom:compile_xsd_file(XsdFile, [{include_dirs, [XsdDir]}]).