-3
<?xml version="1.0" encoding="UTF-8"?>
  <filepaths>
    <application_information_ticker>
      <desc>Ticker1</desc>
      <folder_path>../atlas/info/</folder_path>
    </application_information_ticker>
    <document_management_system>
      <desc></desc>
      <folder_path>../atlas/dms/</folder_path>
    </document_management_system>
  </filepaths>

I have a xml file like this. I need to convert this xml file into java object using JAXB. Because of nested tags, I couldn't perform the operation. Please suggest me a solution for this

NIDHEESH KRISHNA
  • 147
  • 1
  • 1
  • 10

1 Answers1

1
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();
  InputSource is = new InputSource( new StringReader( xmlString) );
  Document doc = builder.parse( is );

  XPathFactory factory = XPathFactory.newInstance();
  XPath xpath = factory.newXPath();
  xpath.setNamespaceContext(new PersonalNamespaceContext());
  XPathExpression expr = xpath.compile("//src_small/text()");

  Object result = expr.evaluate(doc, XPathConstants.NODESET);
  NodeList nodes = (NodeList) result;
  List<String> list = new ArrayList<String>();
  for (int i = 0; i < nodes.getLength(); i++) {
      list.add (nodes.item(i).getNodeValue());
      System.out.println(nodes.item(i).getNodeValue());
Stack Overflow
  • 2,416
  • 6
  • 23
  • 45
  • 1
    I have two xml files like this. First file has small difference with second. For eg, second file contains only instead of . I need to find the changes of this two xml files and update the second file by comparing first one – NIDHEESH KRISHNA May 05 '16 at 07:17
  • 1
    Its not the original question, Try the bellow link: http://stackoverflow.com/questions/141993/best-way-to-compare-2-xml-documents-in-java – Stack Overflow May 05 '16 at 07:20