- it is definitely better to parse a file by SAX if it can be huge (which can obviously be the case with XML-defined models), because DOM defines an object for each element of the XML tree and therefore can be extensively ressource-consuming...
Agreed, it's the reason I choose SAX. In 3d graphics, you never have enough speed.
- as for loading custom nodes without changing the code of the loader, what i can see without thinking a lot about it is have a capability to optionaly define the class fully qualified name somewere in the file when it is needed, then use reflection in the loader to do the job. This could result in heavy time consomption, but it could be reduced by creating a cache of previously loaded classes (for each of these names), and then just create new instances out of them...
That was my idea. See the sample code at the bottom. I don't think there's any other way to load "any" class. Yea it might be a tad slow to load, but
a) That's only for custom classes
b) they're only slow to load, not to use
- as for your XMLLoader code is it normal just to return null for resolveEntity ?
I'm using an xsd to validate my XML file. As far as I can tell, the
built in SAX reader for the current release of java doesn't support xsd validation (only DTD). Of course I could download one that does, and then make everyone else that uses jME download another 2MB file jsut for validation, but i figured it's not worth it. From what I read, Java 1.5 will have a SAX reader that supports xsd validation. Someone correct me if I'm wrong, but this is what I can gather so far.
- and why do you use this characters method ?
<Vertex name="blarg"> 1 2 3 4 5 6 </Vertex>
atts only gives me access to name="blarg", but not 1 2 3 4 5 6. I need to use characters to do that. Of course I could change it to
<Vertex name="blarg" data="1 2 3 4 5 6"/>
but the first seemed more natural when data could be 1000 elements long. I'm open to discussion on which is better though
- and last, I like very much the stack design
My design idea was to use a Stack to keep track of where I'm at in the XML file because all lower elements can be .attachChild() or .addController() to the element above them. I use a hashtable to put the same "thing" in multiple places. So for example to save memory I could make one refrence to a Mesh or RenderState in the XML and put the same refrence in 4-5 places.
Here was my idea for dynamic class loading
interface XMLloader{
public static Object createFromXML(String args);
public String writeToXML();
}
Any class that is unknown to the parser that wants to be saved would have its writeToXML() function called on the -object- and the returning string data would be saved like for example
Box b=new Box("myBox",new Vertex(-1,-1,-1),new Vertex(1,1,1));
b.writeToXML(); // would return "myBox -1 -1 -1 1 1 1"
So the XML file would look like
<genericjmeobject type="com.jme.scene.box" args="myBox -1 -1 -1 1 1 1/>
When the XML file is loaded, the static method of -type- would be called and -args- passed, returning an object and that object would be added to the scene graph in a way fit for that object.
Just ideas of course