Error reported: A global x type definition 'name' does already exist. (Nokogiri::XML::SyntaxError)

315 views
Skip to first unread message

Mark Stevens

unread,
Jan 29, 2016, 10:10:31 AM1/29/16
to nokogiri-talk

Hi everyone,

I would be grateful for any input you can give on the problem detailed below.

I would like to validate an xml document against an XSD schema that I have.  I have a small program that loads in the schema file, and an xml document, and uses the schema.validate()  method.  However, I am finding that the loading of the schema itself is failing.  I have the following line in my file:

schema = Nokogiri::XML::Schema(File.read(schema_file))


where schema_file is the full path to a given xsd file.   But when this line is executed, I get the following error:

Type': A global simple type definition 'suidRefHousingTypeModel' does already exist. (Nokogiri::XML::SyntaxError)
    from /usr/mlocal/packages/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/schema.rb:37:in `new'
    from /usr/mlocal/packages/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/schema.rb:8:in `Schema'
    from ./xml_schema_validate.rb:27:in `<main>'



So it obviously does not like my simple-type called 'suiidRefHousingTypeModel', but I can't understand why.

The XSD file that is being read (and causes the error above) has the general form:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified" jxb:version="1.0">
 
<xsd:include schemaLocation="some_other_schema.xsd"/>
  ...
 
<xsd:simpleType name="suidRefHousingTypeModel">
   
<xsd:annotation>
     
<xsd:appinfo>
       
<xmlcb>
         
<ptrRef type="HousingTypeModel"/>
       
</xmlcb>
     
</xsd:appinfo>
   
</xsd:annotation>
   
<xsd:restriction base="suidRef"/>
 
</xsd:simpleType>
  ...
 
<xsd:complexType name="HousingNode">
   
<xsd:complexContent>
     
<xsd:extension base="NodeCore">
       
<xsd:sequence>
          ...
         
<xsd:element name="kind_suid" type="suidRefHousingTypeModel"/>
          ...
       
</xsd:sequence>
     
</xsd:extension>
   
</xsd:complexContent>
 
</xsd:complexType>
  ...
 
</xsd:schema>


So the XSD defines the simpleType, and then uses it for an element later on. It definitiely is not defined twice (as the error reported by Nokogiri suggests), either in this schema or any of the included schemas.

I have used this schema to validate XML documents with other validators (eg Java JAXB), so I don't think it is an error with the schema or the document, so I can't see why Nokogiri is flagging the error that it is.

I have tried with the defintion of the simpleType placed before and after its use, but that made no difference.  I have also tried deleting the simpleType entirely, but I then just get an equivalent warning for a different type that is defined in the xsd file.

Any suggestions would be very welcom!

Thanks
Mark

Mike Dalessio

unread,
Jan 29, 2016, 10:12:16 AM1/29/16
to nokogiri-talk

Hi,

Can you please share all your code and documents so that we can reproduce what you're experiencing?

--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-tal...@googlegroups.com.
To post to this group, send email to nokogi...@googlegroups.com.
Visit this group at https://groups.google.com/group/nokogiri-talk.
For more options, visit https://groups.google.com/d/optout.

Mark Stevens

unread,
Jan 29, 2016, 10:39:55 AM1/29/16
to nokogiri-talk
Hi

Sorry - I should have thought of this before, but I think the problem is to do with circular dependencies in the schemas that are being loaded. 

The schemas involved here are large, old, and spread across a number of separate files.  I think that the problem is that the schema I'm using includes another, which itself includes the original schema (either directly or by including a further schema which does).

I can replicate the problem using two schemas:

a_types.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified" jxb:version="1.0">

 
<xsd:include schemaLocation="/user/me/tmp/b_types.xsd"/>
 
<xsd:simpleType name="aType">
   
<xsd:restriction base="xsd:long"/>
 
</xsd:simpleType>
</xsd:schema>



b_types.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified" jxb:version="1.0">

 
<xsd:include schemaLocation="/user/me/tmp/a_types.xsd"/>
 
<xsd:simpleType name="bType">
   
<xsd:restriction base="xsd:long"/>
 
</xsd:simpleType>
</xsd:schema>


The loading the schema using:

schema = Nokogiri::XML::Schema(File.read("/user/me/tmp/a_types.xsd"))

will cause the same error:

Type': A global simple type definition 'aType' does already exist. (Nokogiri::XML::SyntaxError)

Obvioulsy the example schemas shown above are trivial and the issue is easy to resolve.  With the schemas that I have to deal with, addressing the circular dependencies is not trivial at all.

So I guess the question changes to one of whether there is a work-around to cope with circular inclusion, or a configuration option to Nokogiri to say that I don't need/want to be informed of this particular error.

Thanks
Mark

Mike Dalessio

unread,
Jan 30, 2016, 2:36:53 PM1/30/16
to nokogiri-talk
It's not clear to me how to make libxml2 deal with circular references. You may want to ask on the upstream libxml2 mailing list:


I googled a bit but couldn't find anything useful.

Mark Stevens

unread,
Feb 3, 2016, 9:47:26 AM2/3/16
to nokogiri-talk
Hi

Thanks for the input and suggestions. 

In the end I wrote a program to build up an in-memory schema based on the contents of the schema file, plus the contents of all the schemas that it includes (and the ones they include, and so on...), but of course not including the contents of a schema if it had already been included.  Then validating my xml document against this combined schema.  This seemed to work OK.

Thanks
Mark
Reply all
Reply to author
Forward
0 new messages