-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>
2

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.