Make erlsom:compile_xsd_file work with XSDs generated with W3C DTD to XSD converter
josemic opened this issue · 2 comments
Usually I create DTDs by hand and convert them to XSDs as these are easier to create without dedicated tool. (Though I am aware that XSDs are more accurate.)
I have created a DTD and validated it against an example XML files using xmllint.
When I convert the DTD into an XSD using the w3c DTD2Schema converter http://www.w3.org/2000/04/schema_hack/ perl script it fails. (I am assuming that the generated XSD is valid, if that assumption is not valid, please reject this issue.)
When however converting the DTD to XSD using MS Visual Studio erlsom:compile_xsd_file runs like charm.
Here the used DTD:
<!ELEMENT osm_traffic (traffic_api)>
<!ATTLIST osm_traffic version CDATA #FIXED "0.1">
<!ATTLIST osm_traffic generator CDATA #IMPLIED>
<!ELEMENT traffic_api (version, (tile_num |tile_deg), waynodes, (wayref, noderef?)?) >
<!ELEMENT version EMPTY>
<!ATTLIST version minimum CDATA #REQUIRED>
<!ATTLIST version maximum CDATA #REQUIRED>
<!ELEMENT tile_num EMPTY>
<!ATTLIST tile_num level CDATA #REQUIRED>
<!ATTLIST tile_num x CDATA #REQUIRED>
<!ATTLIST tile_num y CDATA #REQUIRED>
<!ELEMENT tile_deg EMPTY>
<!ATTLIST tile_deg level CDATA #REQUIRED>
<!ATTLIST tile_deg lat CDATA #REQUIRED>
<!ATTLIST tile_deg lon CDATA #REQUIRED>
<!ELEMENT waynodes EMPTY>
<!ATTLIST waynodes maximum CDATA #REQUIRED>
<!ELEMENT noderef EMPTY>
<!ATTLIST noderef id CDATA #REQUIRED>
<!ELEMENT wayref EMPTY>
<!ATTLIST wayref id CDATA #REQUIRED>
and the used XML file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE osm_traffic SYSTEM "update.dtd">
<osm_traffic version="0.1" generator="test">
<traffic_api>
<version minimum="0.1" maximum="0.1"/>
<tile_num level="14" x="34" y= "45"/>
<waynodes maximum="2000"/>
<wayref id="5000"/> <!-- optional, but mandatory if noderef below is given -->
<noderef id="5000"/> <!-- optional -->
</traffic_api>
</osm_traffic>
the generated XSD file by thw w3c converter:
<schema
xmlns="http://www.w3.org/2000/10/XMLSchema"
targetNamespace="http://www.w3.org/namespace/"
xmlns:t="http://www.w3.org/namespace/">
<element name="osm_traffic">
<complexType>
<sequence>
<element ref="t:traffic_api"/>
</sequence>
<attribute name="generator" type="string" use="optional"/>
</complexType>
</element>
<element name="traffic_api">
<complexType>
<sequence>
<element ref="t:version"/>
<choice>
<element ref="t:tile_num"/>
<element ref="t:tile_deg"/>
</choice>
<element ref="t:waynodes"/>
<sequence minOccurs="0" maxOccurs="1">
<element ref="t:wayref"/>
<element ref="t:noderef" minOccurs="0" maxOccurs="1"/>
</sequence>
</sequence>
</complexType>
</element>
<element name="version">
<complexType>
<attribute name="maximum" type="string" use="required"/>
</complexType>
</element>
<element name="tile_num">
<complexType>
<attribute name="y" type="string" use="required"/>
</complexType>
</element>
<element name="tile_deg">
<complexType>
<attribute name="lon" type="string" use="required"/>
</complexType>
</element>
<element name="waynodes">
<complexType>
<attribute name="maximum" type="string" use="required"/>
</complexType>
</element>
<element name="noderef">
<complexType>
<attribute name="id" type="string" use="required"/>
</complexType>
</element>
<element name="wayref">
<complexType>
<attribute name="id" type="string" use="required"/>
</complexType>
</element>
</schema>
Even when manually adding the namespace xs and adding the line:
<?xml version="1.0" encoding="UTF-8"?>
at the beginning of the schema, erlsom fails with the message:
** exception error: no match of right hand side value
{error,
[{exception,{error,"unknown tag: schema"}},
{stack,[undefined]},
{received,
{startElement,[],"schema","xs",
[{attribute,"targetNamespace",[],[],
"http://www.w3.org/namespace/"}]}}]}
in function erlsomtest:run/0 (src/erlsomtest.erl, line 6)
Hi,
I don't think the XSD is valid. Just about everything that is related to
namespaces looks wrong to me.
You can try it using (for example):
http://www.utilities-online.info/xsdvalidation/
Regards,
Willem
On Mon, Jul 6, 2015 at 11:08 PM, josemic notifications@github.com wrote:
Usually I create DTDs by hand and convert them to XSDs as these are easier
to create without dedicated tool. (Though I am aware that XSDs are more
accurate.)
I have created a DTD and validated it against an example XML files using
xmllint.When I convert the DTD into an XSD using the w3c DTD2Schema converter
http://www.w3.org/2000/04/schema_hack/ perl script it fails. (I am
assuming that the generated XSD is valid, if that assumption is not valid,
please reject this issue.)
When however converting the DTD to XSD using MS Visual Studio
erlsom:compile_xsd_file runs like charm.
Here the used DTD:and the used XML file:
<osm_traffic version="0.1" generator="test">
<traffic_api>
<tile_num level="14" x="34" y= "45"/>
</traffic_api>
</osm_traffic>the generated XSD file by thw w3c converter:
Even when manually adding the namespace xs and adding the line:
at the beginning of the schema, erlsom fails with the message:
** exception error: no match of right hand side value
{error,
[{exception,{error,"unknown tag: schema"}},
{stack,[undefined]},
{received,
{startElement,[],"schema","xs",
[{attribute,"targetNamespace",[],[],
"http://www.w3.org/namespace/"}]}}]}
in function erlsomtest:run/0 (src/erlsomtest.erl, line 6)—
Reply to this email directly or view it on GitHub
#33.
You are right the XSD generated by the w3c dtd2xsd perl converter does not seem to be valid against the XML. This applies also, but less servere, for the XSD generated from the DTD by Visual Studio, which however runs fine with erlsom.
Still it is a converter issue and not an erlsom issue, thus this issue can be closed.