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

How to convert UTF-8 string to RTF string in java?
Can Java non-blocking io be used for the described application?
Rotating views in a LinearLayout problem
<f:ajax> Unable to attach <f:ajax> to non-ClientBehaviorHolder parent
Is it bad practice to use DiscriminatorFormula for migration of Hibernate databases?
Generate X509Certificate from byte[]?
wordpress, passwordhash, in java
How to document Java Web service API
Storage of private and public key in MySQL-DB
Another tool like Ireport (JasperReport) that support ejbql connections
How much “overhead” memory does JDOM need to generate XML files?
Java compiler optimization for repeated method calls?
The application requester cannot establish the connection. (Too many open files)
Unable to highlight text/variable in eclipse [duplicate]
eclipse breaking inside a class file
Hibernate Auto Increment

Categories

HOME
pdf
clips
tizen
stock
dot
cplex
xmpp
gis
elm
c#-2.0
ojdbc
fancybox
django-imagekit
in-app-purchase
ios-charts
pheatmap
add
vault
numeral.js
nstableview
apache-cayenne
flask-wtforms
iron-router
invantive-sql
oracle-coherence
interop
openedx
xlsxwriter
java-3d
scriptcs
jquery-ajaxq
facebook-instant-articles
language-agnostic
underflow
uninstall
replaceall
kendo-datasource
frame
avcapturesession
normal-distribution
nssegmentedcontrol
abstract-class
uft-api
impersonation
broadcastreceiver
email-templates
android-tabhost
spring-security-kerberos
midl
.net-4.6.2
slick-3.0
thin
angular2-meteor
dotcover
hibernate-tools
dds
winscp-net
powercli
libusb-win32
login-control
mathematica-frontend
xml-attribute
impresspages
pagedlist
ios8-today-widget
intel-fortran
mutation-observers
pundit
appfabric-cache
dundas
dereference
python-green
oxwall
network-interface
java.util.concurrent
gulp-less
openexr
yorick
xceed-datagrid
rtmfp
mcts
.aspxauth
sitemesh
runtime.exec
google-cloud-save
tws
simba
hamiltonian-cycle
parametric-equations
bubble-chart
hamachi
invite
sproutcore-2
firefox4
brewmp
sef
mtj
uiq3

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