XML parsing java confirmation -


this way made xml file java object(s). used "xjc" , valid xml schema, , got "generated" *.java files. imported them different package in eclipse. reading xml file in 2 way now.

1) loading xml file:

   system.out.println("using file approach:");    file f = new file ("c:\\test_xml_files\\complex.apx");    jaxbelement felement = (jaxbelement) u.unmarshal(f);    myobject fmainmyobject = (myobject) felement.getvalue (); 

2) using dom buider:

       system.out.println("using dom builder approach:");        jaxbelement element = (jaxbelement) u.unmarshal(test());;        myobject mainmyobject  = (myobject ) element.getvalue (); 

now in method "test()" code below included:

public static node test(){     document document = parsexmldom();    return document.getfirstchild(); }  private static document parsexmldom() {      document document = null;      try {        // getting default implementation of dom builder       documentbuilderfactory factory = documentbuilderfactory.newinstance();       documentbuilder builder = factory.newdocumentbuilder();        // parsing xml file       document = builder.parse(new file("c:\\test_xml_files\\myxml_file.apx"));      } catch (exception e) {       // catching exceptions       system.out.println();       system.out.println(e.tostring());     }     return document; } 

is standard way of doing xml java object? tested if access object , works fine. (so far) suggest different approach?? or 1 sufficient?

i don't know "standard way", either way looks ok me. first way looks simpler ( less code ) that's way i'd it, unless there other factors / requirements.

fwiw, i'd expect unmarshal(file) method implemented pretty doing in second approach.


however, (and co-workers) make judgments "sufficient" project.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -