-1

Please have a look at both xml files.

file 1:

<employees>
   <employee>
     <name>xyz</name>
     <nickname>xy</nickname>
   </employee>
    <employee>
     <name>xyz1</name>
     <nickname>xz1</nickname>
   </employee>
</employees>

file 2:

<employees>
   <employee>
     <name>xyz</name>
     <nickname>xy</nickname>
     <DOB>12-12-2002</DOB>  
   </employee>
    <employee>
     <name>xyz1</name>
     <nickname>xz1</nickname>
     <DOB>12-12-2012</DOB>
   </employee>
</employees>

From both files need to extract only name and nickname elements values. Number of elements in a file may change or file schema may be change but name of elements which want to extract will be always fix(example : name and nickname) . I want to use Jaxb to get these values(name and nickname). There is any way to do this using JAXB? any other technology in Java except Jaxb.

  • 1
    SO is not a code writing service, post an effort of your own and we'll assist in make it work for you. – Kurt Van den Branden Jul 13 '16 at 07:36
  • Hi Kurt, I have wrote down code for an xml file which schema is fixed, and that is working fine. But Here I am asking about for different schema xml files. There is any solution for that using same code can parse two different xml files for getting an elements which name is same in both files. – Rajesh Verma Jul 13 '16 at 07:50

1 Answers1

-2

Have you considered creating your own schema from sample XML files using Trang?

Trent Bartlem
  • 2,213
  • 1
  • 13
  • 22
  • I am getting you point, as I said new elements may added into file I am just giving an example. – Rajesh Verma Jul 13 '16 at 07:29
  • In that case, you've gone two steps beyond XML Schemas, and you'll need to look at techniques from consumer-driven contracts instead. (http://martinfowler.com/articles/consumerDrivenContracts.html) Good luck. – Trent Bartlem Jul 13 '16 at 12:22