java


How to skip certain elements when parsing XML file to DOM with Java


I am attempting to parse some XML documents into DOM so that I can run XPath queries against it. My code is in Java and have been using the Xerces org.apache.xerces.parsers.DOMParser implementation.
I am only interested in certain portions of the XML, under element elementICareAbout and can ignore other elements.
<top>
<elementICareAbout>...</elementICareAbout>
<elementToIgnore>...</elementToIgnore>
</top>
The XML file size can be quite large, and I would not like to have to hold onto elements in memory which I would not need as part of the processing, where I would expect an XPath query to /top/elementICareAbout to return data, but /top/elementToIgnore would just return nothing (as I don't need it to).
Looking over the Xerces DOMParser or the JAXP APIs I don't see any kind of way to explicitly ignore certain elements so that they are not part of the DOM tree in memory after parsed?
Is there a good way to construct a partial DOM Document from an XML file tailored to the parts that I need?
You could write a SAX filter and insert it into the processing pipeline between the (SAX) parser and the document builder. Or with rather less coding you could write an XSLT 3.0 streaming transformation. Or you could write an XQuery to select the parts of the document you want, and run it using a query processor that supports document projection. It all depends how wedded you are to Java/DOM coding - my preference would be for higher-level languages than that.

Related Links

Java do while loop with multiple conditions not executing properly
ObjectAnimator repeat loop delay
Loading application context via annotation in benchmark
Why does Java 8 sometimes allow a Consumer to have a return value but not always? [duplicate]
Java code cannot invoke method from scriptengine with new context
XMPP Smack client 4.1.8: collection node cannot be cast to Leaf node
How can I retrieve the speed with which user is walking
The code below can only insert 226 data OUT of the 20000 numbers from attached file into number column of the TEMPTABLE
How can I make one JComponent mirror another? [duplicate]
Scanner not asking input of string
FileNotFoundException: open failed: EACCES (Permission denied)
Recursion clarification
encountered “org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject”
How does finish() work in OnClick event?
Error while trying to read a file
Multi-dimensional array bug

Categories

HOME
coq
cookies
pycharm
smarty
session
vmware
read-eval-print-loop
jsp-tags
yarn
gps
ip
umd
onelogin
metatrader4
spring-kafka
volttron
nstableview
spring-tool-suite
visual-studio-cordova
circuit
vaadin7
seaborn
introduction
jtextfield
amazonsellercentral
abi
dcevm
extjs5
jndi
lcd
emgucv
bootstrap-duallistbox
assistant
nat
bcd
iframe-resizer
yadcf
scorm2004
stringtemplate
protovis
openoffice.org
accelerate-framework
language-concepts
wallpaper
normal-distribution
appfabric
web-mining
theano.scan
document.write
ansible-playbook
azure-ml
tasker
ibpy
appcompat
azure-application-gateway
domain-model
namecoin
python-cryptography
zendesk-app
cudafy.net
word-vba-mac
wdf
bonobo
ado.net-entity-data-model
xml-attribute
clang-static-analyzer
captivenetwork
vhd
intel-fortran
endeca-workbench
simple-framework
dukescript
apache-commons-fileupload
typekit
gulp-less
castle
imdbpy
pyhdf
jquery-mobile-dialog
lcs
delphi-6
free-variable
path-separator
broken-links
armcc
code-cleanup
invite
javax.script
celltable
gdlib
dmx512
modelstate
rescale
javap
project-hosting
geneva-server

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App