I am not familiar with Matlab APIs at all, but I would like to point out that using the DOM method described by Pursuit will take more time / memory if you want only certain values โโto be output from the XML stream that you are returning an HTTP connection .
While STAX will give you a quick approach to parsing in Java, using the API can be cumbersome, especially if you are not familiar with Java. You can use SJXP , which is an extremely subtle abstraction based on STAX analysis in Java (disclaimer: I'm the author), which allows you to define the paths to the elements you want, then you give the parser a stream (your HTTP stream in this case), and it pulls out all the values โโfor you.
As an example, suppose you want the values โโ/ root / state and / root / volume from the XML examples shown, the actual Java would look something like this:
// Create /root/state rule IRule stateRule = new DefaultRule(Type.CHARACTER, "/root/state") { @Override public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { System.out.println("State is: " + text); } } // Create /root/volume rule IRule volRule = new DefaultRule(Type.CHARACTER, "/state/volume") { @Override public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { System.out.println("Volume is: " + text); } } // Create the parser with the given rules XMLParser parser = new XMLParser(stateRule, volRule);
You can do all this initialization at program startup, and then when you process the stream from your HTTP connection, you will do something like:
parser.parser(httpConnection.getOutputStream());
or the like; then all the code of your handler that you defined in your rules will be called because the parser is launched through the stream of characters from the HTTP connection.
As I said, I am not familiar with Matlab and I donโt know the correct ways to "Matlab-i-fy" this code, but it seems from the first example you can more or less simply use the Java API directly in this case this solution will be faster and there will be significantly less memory for parsing, if important, than the DOM approach.