@pspeed,
Thanks for the link, I had been using:
http://www.jmonkeyengine.org/doc/
Which seems to be quite outdated.
I looked through the documentation to try to see if I could figure out my problem, and I’ve done a pretty extensive amount of debugging but I just can’t seem to find the root of my problem.
I’ll go into more detail about my problem:
I have been working on using XML generation to lay out levels for my game, which grew out of the game that you can make using the jME beginner’s guide. I originally used DOM, which proved to be really frustrating, but worked. I recently rewrote my entire level generator class, using XPath instead of DOM.
I have working code that parses my levels, but it will only work in the context of the IDE. The XPath library that I used is javax.xml.xpath. In order to evaluate XPath expressions, you need an InputSource object.
Here is some relevant code:
Constructor for map generator with InputSource that works, but is specific to the IDE.
[java]
public MapGenerator(String level, SimpleApplication app) {
xpath = XPathFactory.newInstance().newXPath();
this.assetManager = app.getAssetManager();
this.inputSource = new InputSource(“assets/XML/” + level + “.lvl.xml”);
}[/java]
Method for evaluating XPath expressions:
[java]
public String getValue(String expression) {
try {
return xpath.evaluate(expression, inputSource);
} catch (XPathExpressionException ex) {
System.out.println(ex.getCause());
return null;
}
}[/java]
I got DOM working by creating a class that implements AssetLoader, and built a Document object from the InputStream. To get XPath working, I created a very similar class to the Document object one:
[java]
public class XMLLoader implements AssetLoader {
public InputSource load(AssetInfo assetInfo) {
return createSourceFromStream(assetInfo.openStream());
}
public static InputSource createSourceFromStream(InputStream inputStream) {
try {
return new InputSource(inputStream);
} catch (Exception ex) {
return null;
}
}
}[/java]
To try to implement this, I changed the constructor to this:
[java]
xpath = XPathFactory.newInstance().newXPath();
this.assetManager = app.getAssetManager();
assetManager.registerLoader(XMLLoader.class, “lvl.xml”);
this.level = level;
this.inputSource = (InputSource) assetManager.loadAsset(“XML/” + level + “.lvl.xml”);
[/java]
Here is where my problem finally comes in. When the program begins parsing through the XML file, it can get the very first item from the XML file. I confirmed this with a System.out.println() call. The problem seems to be that when I use the AssetManager to load the XML file, it closes the InputSource’s byte stream. I was trying to look through the documentation to see if I could figure anything out, but I couldn’t.
If someone actually read through all of this, wow, thank you, you are awesome and thanks for trying to take the time to help.
If this isn’t enough code or explanation I’d be happy to post more.
Thanks!