2

We have very large xml file(5-10MB) with lots of data in it and we need to develop POC in java to parse it and insert them in db tables by mainitaing proper releation.

Can anyone tell me what is best practice in this design? How can we parse them in more memory effiecient way?

user509755
  • 2,941
  • 10
  • 48
  • 82

1 Answers1

2

There are three main methods for parsing XML in Java.

DOM - Read the whole file into memory and walk around in it.

PUSH - e.g. SAX - parse the file and use callbacks to tell you what is happening as the file flies paqst the parser.

PULL - e.g. StAX - Parse the file on-the-fly but pull each element out of the file one-by-one.

See Parsing XML using DOM, SAX and StAX Parser in Java for a more general discussion.

See What is 'Push Approach' and 'Pull Approach' to parsing? for a good discussion about the Push/Pull debate. For large files, DOM will not work very well. For speed, either of the other two will work fine.

Community
  • 1
  • 1
OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213