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

Convert Postgis MultiPoligon Object to GeoJson
how to throw an exception in java
regex pattern won't match anything
Set picture as wallpaper but allowing user to resize it
Type safety in enum wrapper
Mbean deployment in Jboss
how to add style to gwt popup
Reading metadata from FLAC files with Java [closed]
Threadsafety : What is most recommended for this situation?
How to configure existing Application Context in Jersey-Spring using Grizzly embedded server?
Problems reading a CSV file in Java. Only the first line is read
Java collection property initialisation - best practice
Java Buffere Reader split add string
Can Daemon Threads be killed? [duplicate]
Call C from Android using JNI with only a C shared library and header file
How to use my Set/Get methods unto my main class?

Categories

HOME
pdf
jdo
clips
mfc
plot
react-virtualized
onedrive
rsyslog
gis
paw-app
jgroups
retrofit
fingerprint
opengl-es-2.0
webrequest
adfs
communication
dax
numeral.js
php-7.1
alignment
commonmark
task
size
fallback
graphlab
swingx
tokenize
devops
gsmcomm
flink-streaming
skia
lightswitch-2013
microsoft-chart-controls
media-queries
key-value-observing
galsim
airconsole
scorm2004
column-family
hybridauth
wallpaper
abstract-class
xenforo
az-application-insights
reportbuilder
bootstrapper
eigenvalue
modelmapper
flashair
theming
return-value
idisposable
yii2-extension
linode
imanage
sonarlint-vs
watchconnectivity
abcpdf9
passport-google-oauth
intrusion-detection
storekit
fputcsv
angstrom-linux
captivenetwork
bluegiga
uid
spim
intel-fortran
thredds
qdialog
citrus-pay
purge
varargs
muse
emailrelay
ami
umbraco6
fscommand
jsonpickle
dd
knuth
network-interface
phalanger
javafx-webengine
internet-connection
starcluster
seaside
datagridviewcolumn
balanced-payments
typo3-neos
batterylevel
django-nonrel
pushbackinputstream
jquery-knob
cisco-jtapi
first-responder
dsn
appconkit
punbb
rfc1123
winbugs14
celltable
remember-me
perfect-hash
simpletest
anti-piracy
sector
private-members

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