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

Extract int from stream in Java
Processing, bullet position for firing
Error:(44) No resource identifier found for attribute 'fab_labelStyle' in package 'abtech.waiteriano.com.waitrer'
Adding a maven library into Netbeans Web Project
Menu Bar, Color, and Image not adding to frame
How to change response http header in get request by spring RestTemplate?
Is there any way to check user session once authenticated on navigating HTML pages in Spring MVC?
Using JavaMail with SSL and TLS
Password encryption in Spring MVC
Store boolean using sharedpreferences in android [duplicate]
Javacc How can i make a variable accessible to scanner and parser
I want to convert httpresponse to json object
Display bill total, Java public void display() error
How to reuse the variable used for for loop first level inside for loop second level in nested for loop
Error Incompatible types: Not able to understand Function<R,T> in the java8
Parsing XML in Java manually

Categories

HOME
twitter
vbscript
plone
grep
adb
sqlite3
fsm
icloud
callback
flyway4
azure-storage-tables
uber-api
qore
fancybox-3
spring-kafka
event-handling
dynamics-crm-online
progressive-web-apps
custom-wordpress-pages
accessor
extjs5
apache-commons-io
media-queries
yadcf
functor
karaf
wpf-controls
automake
objectlistview
unobtrusive-validation
webdriver-manager
elasticsearch-plugin
hp-ux
mapzen
grid.mvc
mime
checkboxlist
sencha-touch-2.3
scorm
chain-builder
alphabet
jxcore
tactic
composite-key
jquery-filter
ableton-live
infix-notation
database-optimization
storekit
contact-list
react-native-listview
rtbkit
ora-00900
cyclomatic-complexity
citrus-pay
quicklisp
sankey-diagram
generic-programming
sortedlist
dundas
website-monitoring
codeigniter-url
client-side-templating
has-many-through
uitouch
bundles
cloud-connect
dataservice
ora-00911
shellexecute
mylyn
tinn-r
selected
itmstransporter
rdoc
netbeans-6.9
cufon
nsdatecomponents
mercurial-server
stage
spyware
hirefire
disclosure
html-input
h.323
digest-authentication
temporal-database

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