[Nifty] Using nifty.xsd

Hello,

I’m creating a dialog editor for my game.



I use the classic swing API for the editor and want to store resutls into XML readable by Nifty.



I have retrieved the file nifty.xsd and I intend to use castor xml serializer to store my results.

→ I tried to generate my classes corresponding to the xsd file via ant :



[java]

<target name="generate-sources" depends="test-jvm" description="Generate Java source files from XSD.">

<taskdef name="castor-srcgen" classname="org.castor.anttask.CastorCodeGenTask"

classpathref="Project.extra.classpath" />

<delete dir="generated-source" />

<mkdir dir="generated-source" />



<!-- nifty dialog.xsd –>

<castor-srcgen casesensitive="on"

verbose="yes" file="./src/nifty.xsd"

todir="generated-source"

package="com.didigame.acariaempire.xml.nifty"

types="j2" warnings="true" />



</target>

[/java]



When I launch ant, I receive this warning :


Warning: A class name generation conflict has occured between element '/effect{http://nifty-gui.sourceforge.net/nifty.xsd}' and element '/complexType:elementType/effect'. Please use a Binding file to solve this problem.Continue anyway [not recommended] (y|n|?)


So I have two questions :
- Is there a binding.xml file available on the repository ? I haven't found it )
- Is it necessary that I generate the sources ? ( Aren't there already somewhere inside nifty.jar )

Thanks in advance

I’ve created a file niftyBinding.xml which seems to work.



If someone is interested, here it is :



[java]

<binding xmlns=“http://www.castor.org/SourceGenerator/Binding” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://www.castor.org/SourceGenerator/Binding” >



<elementBinding name="/complexType:elementType/effect">

<java-class name=“elementEffect”/>

</elementBinding>



<elementBinding name="/complexType:styleType/effect">

<java-class name=“styleEffect”/>

</elementBinding>



<elementBinding name="/complexType:elementType/interact">

<java-class name=“elementInteract”/>

</elementBinding>



<elementBinding name="/complexType:styleType/interact">

<java-class name=“styleInteract”/>

</elementBinding>



<elementBinding name="/complexType:niftyType/controlDefinition">

<java-class name=“niftyControlDefinition”/>

</elementBinding>



<elementBinding name="/complexType:niftyType/popup">

<java-class name=“niftyPopup”/>

</elementBinding>



<elementBinding name="/complexType:screenType/layer">

<java-class name=“screenLayer”/>

</elementBinding>



</binding>

[/java]



And for using it :

[java]

<target name=“generate-sources” depends=“test-jvm” description=“Generate Java source files from XSD.”>

<taskdef name=“castor-srcgen” classname=“org.castor.anttask.CastorCodeGenTask”

classpathref=“Project.extra.classpath” />

<delete dir=“generated-source” />

<mkdir dir=“generated-source” />



<!-- nifty dialog.xsd -->

<castor-srcgen casesensitive=“on” bindingfile="./src/niftyBinding.xml"

verbose=“yes” file="./src/nifty.xsd"

todir=“generated-source”

package=“com.didigame.acariaempire.xml.nifty”

types=“j2” warnings=“true” />



</target>

[/java]



Edit : Is seems to be not enough.

Castor Source Generator semms to not support substitutionGroup. I will try to see if my informations are up to date

Hey, great work :slight_smile:



Maybe consider XmlBeans for this? We use it at work a lot and it’s really easy to integrate and use (IMHO). I haven’t tried it with the current nifty.xsd but the very first Nifty version did indeed use XmlBeans for reading XML-Files. It was removed later because people complained about the relative big size of the xmlbeans jar dependency :slight_smile:



But for an editor XmlBeans may be more appropriate.



Just my 2 cents tho :slight_smile:

Weell, I’ve done some tests.



I managed to create nifty xmls with castor via some modifications inside nifty.xsd

I replaced :

[java]

<xs:element name=“element” type=“elementType”/>

<xs:element name=“layer” type=“layerType” substitutionGroup=“element”/>

<xs:element name=“panel” type=“panelType” substitutionGroup=“element”/>

<xs:element name=“image” type=“imageType” substitutionGroup=“element”/>

<xs:element name=“control” type=“controlType” substitutionGroup=“element”/>

<xs:element name=“label” type=“labelType” substitutionGroup=“element”/>

<xs:element name=“text” type=“textType” substitutionGroup=“element”/>

<xs:element name=“popup” type=“popupType” substitutionGroup=“element”/>

[…]

<xs:complexType name=“controlDefinition”>

<xs:sequence>

<xs:element ref=“element” minOccurs=“0” maxOccurs=“unbounded”/>

</xs:sequence>

[…]

[/java]



By :

[java]

<xs:group name=“elementGroup”>

<xs:choice>

<xs:element name=“element” type=“elementType” />

<xs:element name=“layer” type=“layerType” />

<xs:element name=“panel” type=“panelType” />

<xs:element name=“image” type=“imageType” />

<xs:element name=“control” type=“controlType” />

<xs:element name=“label” type=“labelType” />

<xs:element name=“text” type=“textType” />

<xs:element name=“popup” type=“popupType” />

</xs:choice>

</xs:group>

[…]

<xs:complexType name=“controlDefinition”>

<xs:sequence>

<xs:group ref=“elementGroup” minOccurs=“0” maxOccurs=“unbounded” />

</xs:sequence>

[…]

[/java]



With that I can use the method addElementGroup() inside my code.



It worked but … after some tests, I finally conclued that creating directly Nifty XML via my editor was not good enough for want I wanted to do. :smiley:

( Since I want the dialogs to be modular )



If some people wants the modified nifty.xsd I’ve done, I think I still have it.

( It still respects the same grammar but the elements are defined in a manner that you can create nifty xml files thanks to Castor Souce Generator )



So I dropped my idea, and now I’m using one Nifty xml that serves as a dialog template and I fill it dynamicly with data from a xml file in my own format.