0

I have created simple XML file and need to get its each attribute individually and want to store into variables. Following is my XML file.

<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<MY_VERIFICATION xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <RESPONSE_DATA>\r\n    <RESPONSE_STATUS>\r\n      <CODE>100</CODE>\r\n      <MESSAGE>successful</MESSAGE>\r\n    </RESPONSE_STATUS>\r\n    <CITIZEN_NUMBER>656566585665</CITIZEN_NUMBER>\r\n    <PERSON_DATA>\r\n      <NAME>???? ???? ????</NAME>\r\n      <FATHER_HUSBAND_NAME>????????? ????</FATHER_HUSBAND_NAME>\r\n      <PRESENT_ADDRESS>??? ???? ??? ?? ???? 2?? ????? ?????26?? ?????? ?????19?? ??????  ???? ?????? ????</PRESENT_ADDRESS>\r\n </RESPONSE_DATA>\r\n</MY_VERIFICATION>

In the above example you can see the MESSAGE tag and its value is successfull and so on. So my question is that how can I get this value under Message tag, as well as all the attribute values. Many thanks in advance.

Rauf Abid
  • 346
  • 1
  • 8
  • 17
  • I would highly recommend using a serialization library for this task. Usually these require you define a process to reconstruct the data into an object, often using a class and a class method or two. Java appears to have the [xstream](http://stackoverflow.com/questions/13731322/xml-parsing-and-deserialization) library, though I'm sure there are many other good xml serialization libraries to investigate. You *can* write a parser, but it's often not worth the effort. – Aaron3468 Oct 07 '16 at 05:29
  • We are getting this file from someone vendor to get their individual values in our application. So serialization is not possible in this case, thanks – Rauf Abid Oct 07 '16 at 06:24
  • xml can be deserialized from a file... It should be very easy to use a library, you're welcome. – Aaron3468 Oct 07 '16 at 17:28

0 Answers0