java


How to process XML file with repeated fields in Java


I know how to parse an XML file that has one of each field e.g. Name, ID, Age by getting sub-elements using DOM parser and putting them into a Nodelist.
However I don't know how to parse and store data from an XML file with repeated fields. For example, each facility has more than one item, and it has more than one "link" with a distance to each link, for instance Seattle has a link to Fargo in this XML file, with a distance of 1426.
How would I approach parsing for the items and links? I can't simply match by the substring item, since I have multiple items.I don't know if it's appropriate to use a Nodelist, so I'm not sure which kind of data structure to use.
I've googled XML parsing in Java and I'm still confused, and I don't know what kind of data structure to use to store all this information.
<Facility>
<Name>Seattle, WA</Name>
<ProcessingRate>8</ProcessingRate>
<ProcessingCost>300</ProcessingCost>
<Link>
<Name>Fargo, ND</Name>
<Distance>1426</Distance>
</Link>
<Link>
<Name>San Francisco, CA</Name>
<Distance>808</Distance>
</Link>
<Item>
<Id>ABC123</Id>
<Quantity>45</Quantity>
</Item>
<Item>
<Id>JBL3100</Id>
<Quantity>52</Quantity>
</Item>
<Item>
<Id>PL132-C</Id>
<Quantity>54</Quantity>
</Item>
<Item>
<Id>PU238</Id>
<Quantity>60</Quantity>
</Item>
</Facility>
<Facility>
You can read this xml file to a class object like this:
class Facility {
String Name;
String ProcessingRate;
String ProcessingCost;
List<ChildObject> links;
List<ChildObject> items;
}
class ChildObject {
String name;
String value;
String type;
}

Related Links

Importing the Resin source into Eclipse
Real-time collaboration in Eclipse
Package (free or commercial) for building GUI for standalone Java based Application
HQL: Trouble with trivial select with aggregate function
extend an array of String dynamically
Can proguard leave out the unused classes of the libraries?
Restlets 2.1-RC1- sample performant ClientResource code needed
Java: How do I get an xpath for a org.w3c.dom.Node?
Attempt to write an excel file with Apache POI causing OutOfMemoryError
With SAX, is it possible to exit from processing?
Java system properties and environment variables
Round corners in a progress bar Android
Multiple submit buttons, javascript
Best library for protocol handling in Java? [closed]
#ManyToMany association isn't inserted in the second table
problem in understanding the setRunning (boolean run) method

Categories

HOME
compiler-construction
gerrit
debugging
minimum-spanning-tree
mockito
tizen
homebrew
iot
dot
spring-cloud-stream
microservices
jpeg
pivotal-cloud-foundry
acquia
adfs
nano-server
dax
phaser
visual-studio-cordova
clojurescript
angular-ui
flux
code-review
karma-jasmine
kryo
java-3d
google-search-api
telerik-reporting
microsoft-r
java-7
sqlcipher
javacv
entitlements
linkerd
web-api-testing
maquette
assistant
dbclient
gitignore
google-cloud-nl
delicious-api
unboundid
karaf
winrt-xaml-toolkit
atl
force-layout
wpf-controls
suricata
git-merge
streamsets
webdriver-manager
ensembles
hp-ux
mapzen
avro4s
node-gyp
nomethoderror
gpx
chain-builder
elgg
minimization
angular-strap
phishing
underscore.js-templating
nsfilemanager
paypal-express
player
sdf
bluegiga
livequery
two-factor-authentication
pyke
tcpserver
qtableview
msys
metaclass
simple-framework
tmuxinator
varargs
0xdbe
microbenchmark
angular-local-storage
formatjs
block-device
modalpopup
tween
dd
tt-news
wordpress-theme-customize
eol
uitouch
dml
app42
farseer
tidy
sitemesh
inbox
bulkloader
batterylevel
pushbackinputstream
seed
pvrtc
hamiltonian-cycle
path-separator
work-stealing
boost-filesystem
hamachi
self-extracting
yslow
dbal
procedural-music

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