|
|
|
|
|
by specialist
4575 days ago
|
|
Thanks for the pattern matching tip. Will investigate. I'm looking for a better way to navigate of graphs. Objects graphs, DOMs, parse trees. Currently, I rely on iteration and glob style paths. http://en.wikipedia.org/wiki/Glob_(programming) For instance, excerpt from https://code.google.com/p/lox/source/browse/trunk/test/lox/t... InputStream in = new FileInputStream( "./test/lox/test/zooinventory.xml" );
Document doc = LOXHandler.load( in );
List<Element> animals = doc.find( "Inventory/Animal" );
System.out.println( "animals found: " + animals.size() );
for( Element animal : animals )
{
String habitat = animal.findFirstString( "Habitat" );
String lifestyle = animal.findFirstString( "Lifestyle" );
...
}
...
// Actual example of some globbing
List<Element> names = doc.find( "Inventory/*/Name" );
System.out.println( "names found: " + names.size() );
What I really want in a future language is for those glob paths to be first order objects, not magical strings. Then the compiler can do some sanity checking, editor can do autocompletion, etc.Warning: Lightweight Objects for XML is a personal project, very alpha. https://code.google.com/p/lox/ |
|