java - Uknown XML file into pojo -


is there way take unknown schema xml file , convert values, tags, etc xml file pojo? looked @ jaxb , seems best way use if know xml schema. basically, want able parse tags xml put each own object maybe through use of arraylist. did not understand jaxb can or there better tool can this, or hard implement?

in hope helps understand situation!

public static void dumpallnodes( string path ) throws exception {     documentbuilder parser =        documentbuilderfactory.newinstance().newdocumentbuilder();     document doc = parser.parse(new file(path));     nodelist nodes = doc.getelementsbytagnamens( "*", "*" );     for( int = 0; < nodes.getlength(); i++ ){         node node = nodes.item( );         system.out.println( node.getnodetype() + " " + node.getnodename() );     } } 

the nodelist nodes contains element nodes, in document order (opening tag). thus, elements contained within elements in list, alike. obtain attributes of node, call

namednodemap map = node.getattributes(); 

the text content of node available by

string text = node.gettextcontent(); 

but be aware calling returns text in elements of subtree.

otoh, may call

element root = doc.getdocumentelement(); 

to obtain root element , descend tree recursively calling element.getchildnodes() , process nodes (element, attr, text,...) 1 one. also, note node.getparentnode() returns parent node, construct xpath each node flat list repeating call root.

it depends expect resulting data structure (what call arraylist). if, instance, create generic element type (myelement) containing 1 map attributes , 1 child elements, second map have be

map<string,list<myelement>> name2elements 

to provide repeated elements - makes access elements occurring once little awkward.

i hope have illustrated problems of generic xml parsing, not task jaxb can you.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -