0
<?xml version="1.0"?>

<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="test">
    <table_data name="test">
    <row>
        <field name="field1">406</field>
        <field name="field2">a2</field>
        <field name="field3">16</field>
        <field name="field4"></field>
        <field name="field5" xsi:type="xs:hexBinary">
[get the content from http://122.183.130.242/file/hex.txt path because i cannot give such a large content to stackoverflow]

        </field>
        <field name="field6">16</field>
    </row>
    </table_data>
</database>
</mysqldump>

I am trying to parse and read the content from the above xml file.

I am using a DOM parser and I also tried StAX parser to parse the XML but I cannot parse such a large file.

How can I parse large XML files?

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
Mohan
  • 877
  • 10
  • 20
  • 32
  • DOM is not a good option for such a large files. If SAX also failing only option you have I think will be increase memory. – kosa Feb 08 '12 at 19:27
  • ya, that is why am asking friend. what will be the better approach for this one. – Mohan Feb 08 '12 at 19:28
  • what error are you getting when you try to parse? – Robert Peters Feb 08 '12 at 19:28
  • am did not get any error. but file parsing is skipped. – Mohan Feb 08 '12 at 19:30
  • http://stackoverflow.com/questions/355909/parsing-very-large-xml-documents-and-a-bit-more-in-java – ethrbunny Feb 08 '12 at 19:53
  • @Mohan, I don't think there is one except memory increase (or) reduce file size, because you tried StaX also (which is some what last option for large files). – kosa Feb 08 '12 at 20:34
  • 1
    "file parsing is skipped" says that the parser isn't the problem, something else in your code is. If it were truly a problem of the file being too big, you'd get an OutOfMemoryError. To get better answers, post your code. – kdgregory Feb 08 '12 at 21:32
  • The file you linked to is 64 kilobytes. This is, by no means, "too large" to parse with even DOM – which wouldn't really bloat a file with a structure this simple anyway. (Assuming a desktop Java and its default memory settings.) Your error is somewhere else. – millimoose Feb 09 '12 at 02:15
  • yes, the problem is fixed after restarting my system. i don't know why the problem happen like this. thanks guys for spending your time with me. – Mohan Feb 09 '12 at 04:10
  • @Mohan - since the problem went away, please delete this question; it won't help anyone else. – kdgregory Feb 09 '12 at 12:18

1 Answers1

0

Use the SAX Parser method .parse(InputStream stream, HandlerBase handler)

For the handler, you use DefaultHandler.

For the 'stream' parameter, do this:

BufferedReader stream=new BufferedReader( new FileReader(String filename));

...where "filename" is, you guessed it, the name of your file. Now I expect you to know how to use the DefaultHandler. Basically you overwrite the methods you're interested in. Try to tweak the buffer size of the BufferedReader, and i think you'll be happy with the result.

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
vlad-ardelean
  • 7,480
  • 15
  • 80
  • 124
  • i have a question, does this SAX parser will allow to change and update the xml content? – Mohan Feb 08 '12 at 20:05