-3

How I can read 'people=400000' and "Lubljana" data records from this xml file in Java?

And here is the sample of xml file which I already used.

<?xml version="1.0"?>
<countrys>
    <country people="3500000">
        <naziv>Slovenija</naziv>
        <glavnigrad people="400000">
            <naziv>Ljubljana</naziv>
        </glavnigrad>
        <povrsina jedinica="km2">51129</povrsina>
        <moneta naziv="KM" />
    </country>
</countrys>
David Conrad
  • 15,432
  • 2
  • 42
  • 54
Ve Lid
  • 1
  • 1
  • https://stackoverflow.com/questions/7704827/java-reading-xml-file – JHDev Dec 05 '18 at 18:27
  • See also: [How to read and write xml files?](https://stackoverflow.com/questions/7373567/how-to-read-and-write-xml-files?noredirect=1&lq=1) – David Conrad Dec 05 '18 at 20:01

1 Answers1

1

You basically have two options:

  • DOM style: The approach is to load the entire XML file into memory as a tree structure of nodes and leaves. You can imagine how this would be very memory intensive for a large or complicated structure.

Benefits: Provides object model in Java that can be easily referenced.

Drawbacks: Memory intensive for large XML structures. Potentially slower.

https://howtodoinjava.com/xml/read-xml-dom-parser-example/

  • SAX style: The approach is to scroll through the file and find the node reference directly.

Benefits: Less memory usage, potentially faster.

Drawbacks: Potential confusion in identifying nodes and/or duplicates outside of uniform tree structure.

https://howtodoinjava.com/xml/sax-parser-read-xml-example/

You should research and try each approach. Other approaches are derivatives of these basics.

ingyhere
  • 11,818
  • 3
  • 38
  • 52