What's the best way to retrieve two pieces of data from an XML file?
Posted
by Morinar
on Stack Overflow
See other posts from Stack Overflow
or by Morinar
Published on 2010-04-05T18:41:38Z
Indexed on
2010/04/05
18:43 UTC
Read the original article
Hit count: 299
I've got an XML document that is in either a pre or post FO transformed state that I need to extract some information from. In the pre-case, I need to pull out two tags that represent the pageWidth and pageHeight and in the post case I need to extract the page-height and page-width parameters from a specific tag (I forget which one it is off the top of my head).
What I'm looking for is an efficient/easily maintainable way to grab these two elements. I'd like to only read the document a single time fetching the two things I need.
I initially started writing something that would use BufferedReader
+ FileReader
, but then I'm doing string searching and it gets messy when the tags span multiple lines. I then looked at the DOMParser
, which seems like it would be ideal, but I don't want to have to read the entire file into memory if I could help it as the files could potentially be large and the tags I'm looking for will nearly always be close to the top of the file. I then looked into SAXParser
, but that seems like a big pile of complicated overkill for what I'm trying to accomplish.
Anybody have any advice? Or simple implementations that would accomplish my goal? Thanks.
© Stack Overflow or respective owner