The symbol is already defined. Use JAXB property to resolve conflict

I have an xsd file (yahoo.xsd) where I import another xsd file as follows:

<xs:import schemaLocation="stock.xsd"/> <xs:attribute name="lang" type="xs:NCName"/> 

The stock.xsd file is as follows:

 <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"> <xs:import namespace="http://www.yahooapis.com/v1/base.rng" schemaLocation="yahoo.xsd"/> <xs:element name="quote"> <xs:complexType> <xs:sequence> <xs:element ref="Symbol"/> </xs:sequence> <xs:attribute name="symbol" use="required" type="xs:NCName"/> </xs:complexType> </xs:element> <xs:element name="Symbol" type="xs:NCName"/> </xs:schema> 

When I compile using xjc, I get the following error message:

[ERROR] The Symbol property is already defined. Use <jaxb: property> to resolve this conflict.

I basically found a solution for this here on SO ( JAXB Compiling Issue - [ERROR] Property "Any" already defined ), but I can't get this to work. I assume my XPath is wrong.

This is the binding file I'm using:

 <bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1"> <bindings schemaLocation="yahoo.xsd" version="1.0" > <!-- rename the value element --> <bindings node="//xs:element[@name='quote']/xs:complexType/xs:sequence/xs:element[@ref='Symbol']"> <property name="SymbolAttribute"/> </bindings> </bindings> 

If I compile now with xjc -b, he says that evaluating XPath leads to an empty node target.

Will I probably have to rename the definition of Symbol and then ref? how to do it automatically?

+6
source share
1 answer

Let me ask about this line:

 <xs:element ref="Symbol"/> 

Character defined in yahoo.xsd or locally in the same xsd file?

I will try to deduce some facts.

I assume that you have two yahoo.xsd : yahoo.xsd and some.xsd (the first in your post). I am sure that the Symbol type is defined in some.xsd and not in yahoo.xsd . If it were otherwise, I would expect some namespace prefix ("yahoo: Symbol"?).

Now, is it true, your some.xsd looks something like this:

 <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" > <!-- It not important right now: --> <!--<xs:import namespace="http://www.yahooapis.com/v1/base.rng" schemaLocation="yahoo.xsd"/>--> <!-- declaration you omitted in your post, it only example --> <xs:element name="Symbol"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> <xs:maxInclusive value="100"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="quote"> <xs:complexType> <xs:sequence> <xs:element ref="Symbol"/> </xs:sequence> <xs:attribute name="symbol" use="required" type="xs:NCName"/> </xs:complexType> </xs:element> </xs:schema> 

If what I'm saying is true, then your jaxb binding should look like this:

 <bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1"> <bindings schemaLocation="some.xsd"> <!-- not yahoo.xsd --> <bindings node="//xs:element[@name='quote']/xs:complexType/xs:sequence/xs:element[@ref='Symbol']"> <property name="SymbolAttribute" /> </bindings> </bindings> </bindings> 

And the generated java class will be:

 @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "symbolAttribute" }) @XmlRootElement(name = "quote") public class Quote { @XmlElement(name = "Symbol") protected int symbolAttribute; @XmlAttribute(name = "symbol", required = true) @XmlJavaTypeAdapter(CollapsedStringAdapter.class) @XmlSchemaType(name = "NCName") protected String symbol; .... 
+6
source

All Articles