Hello, I have in the xml file data in the format:

 <AddOrder book="book-3" operation="SELL" price="100.80" volume="24" orderId="149" /> <AddOrder book="book-3" operation="BUY" price="100.20" volume="42" orderId="151" /> 

When reading a file (by the lines with the readLine() method), I load all the data from it into the HashMap , and the orderId parameter orderId that is, the value itself, is a digit that stands in quotes, as the key.

Tell me how to get me out of there in a civilized way? It is clear that I can come up with some kind of perversion like spreading a string into an array and poking around with the help of a pack of conditional operators, but I want to do it humanly. Surely for such a typical task, there is a normal API.

    1 answer 1

    There are two different types of parser for working with XML:

    If you have a Schema of your document or you are ready to create it yourself, then you can use the JAXB framework ( tutorial ). Using it, you will get a tree, where the nodes will be Java objects belonging to classes whose names will correspond to the nodes of your XML. In your case, you will have an AddOrder class.

    • I apologize I forgot the condition of the problem that you can use Java SE and this JAXB it does not apply to it? - Pavel
    • @Pavel JAXB is part of the SE. javax.xml.bind package - Mikhail Vaysman
    • one
      That is why the unfortunate smartphone, which really does not do anything, needs gigabytes of memory. - avp