Java - Parse XML dynamically and insert elements and values into a stack or deque

Viewed 102

I have a requirement where I should be able to take any XML document, parse it dynamically and store into a stack/deque for further processing.

Can someone recommend what is a good way to parse XMLs dynamically in JAVA.

Consider this XML

<Response>
 <Stock>
  <RecordID>130</RecordID>
  <SegmentLength>0023</SegmentLength>
  <Account>
   <Number>233342</Number>
   <Type>P</Type>
  </Account>
 </Stock>
<Stock>
 <RecordID>030</RecordID>
 <SegmentLength>1023</SegmentLength>
  <Account>
   <Number>255673</Number>
   <Type>P</Type>
 </Account>
</Stock>
</Response>

How can I write a method that parsers this XML dynamically and pushes elements into a stack/deque.

I cannot use DOM as DOM requires me to provide the element tag while parsing. The program should be able to accept any XML and parse it dynamically

0 Answers
Related