Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Searching for a value in a large XML file

 
ratna sargurp
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have a large XML file (1GB) that I have to parse through and search for content in a particular element. Is SAX better or JDOM a better approach to this problem?

Any suggestions are appreciated.

Thanks
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDOM is a framework for XML processing that supports SAX, so you can't compare the two. You'll definitely want to use either a SAX, or StAX approach to processing the file, instead of DOM (I think you confused this with JDOM).
 
Campbell Ritchie
Sheriff
Pie
Posts: 49770
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult a question for “beginning”. Moving thread.
 
ratna sargurp
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I started using SAX parser and was able to parse the data except now I have hit a road block. The input XML file cannot be modified at all. I can only read it. This input file has entity referenced like &rdquo that the parser does not like. The entities are not declared within the XML file. They reside in a separate file.

In order to resolve this issue, I wrote a separate entity resolver by overriding resolveEntity. Please see my code below:



And in my SAX parser code I call this resolver:

xmlReader.setEntityResolver(new CustomEntityResolver());

But this code is not working.

Please note that I have separate public ID strings for each of the entities and have only shown one here as an example.

Any tips or suggestions are appreciated.



 
Paul Clapham
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the parser is balking at ” because it isn't properly declared by a DTD in the document, then I don't see what the point is of the string "ISO 8879-1986//ENTITIES Alternative Greek Symbols//EN" in that code.

Or is that entity reference supposed to be resolved by a schema which the parser doesn't know about?

Or is the problem that there is a DTD but the parser can't access it? That would be a problem solved by your EntityResolver, so perhaps the problem isn't that.

Anyway it would help if you told us what the actual problem was, rather than trying to get us to help with a solution which might not be the solution to the actual problem.
 
ratna sargurp
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. My issue is to be able to somehow ignore those non-xml entities while parsing the data. The two problems are that I cannot modify the XML file, it has no DTD declaration and the DTD itself resides outside the file.

That was the reason I started writing the Entity Resolver.

What is your suggestion to this issue?

 
Paul Clapham
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, plainly if your XML uses those entity references but doesn't contain a DTD which declares them, then it's not a well-formed XML document. And parsers won't parse it.

Do you have any other processes which parse this document? If so, maybe you can find out how they persuade the parser to refer to the DTD.

Or perhaps you could get the people who produced that document to modify their processes so that they produce well-formed XML.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic