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

jmx mbean server throw InstanceAlreadyExistsException when change c3p0 version
Unable to evaluate the selected expression ? - Eclipse lib debug error
Tomcat 8 on Azure websites
How to approach base exception thrown by API method?
Spring Maven project commons-logging LogFactory NoClassDefFoundError
own MultiMap implementation, problems with put
How to handle wait and response in servlet?
How to skip NoSuchElementException in Selenium
Why we cant use execAndWait interceptor using ServletActionContext?
Spring Batch Java Config #EnableBatchProcessing Annotation Error
MediaPlaying seeking UI lag
What _L1 : _L2: mean? [closed]
Extending in a package
How to find out efficiently total size of a file to be downloaded without using Content-Length
Static class variables are created when Static methods are being called - Java
When should the HttpClient be closed?

Categories

HOME
ibm-bluemix
openlayers
osgi
gerrit
iterator
onedrive
office365api
yahoo-oauth
spring-jdbc
rubygems
jxls
survey
retrofit
cross-browser
medical
cloudkit
session-variables
gorm
communication
metatrader4
here-api
nano-server
nstableview
correlation
timeout
gz
vaadin7
lombok
seaborn
ab-testing
oracle-coherence
text-rendering
karma-jasmine
plunker
java-3d
opennlp
su
selectedindexchanged
url-scheme
info.plist
semantic-versioning
scorm2004
code-contracts
openoffice.org
y86
wixsharp
revolution-slider
libraries
objectlistview
webdriver-manager
particles.js
quadratic-programming
total-commander
s
galleria
komodoedit
celery-task
worker-thread
font-size
windows-iot-core-10
pdfclown
pycaffe
migradoc
setuptools
firmata
pcf
xml-attribute
bstr
ubuntu-10.04
rvest
ptrace
revolution-r
wapiti
browser-link
ios8-today-widget
tmuxinator
kcachegrind
varargs
embedded-code
riak-cs
responsive-images
nsmutabledictionary
dia
pick
coldbox
google-style-guide
asp.net-dynamic-data
p4java
picturefill
balanced-payments
cloud-connect
mbr
geos
tws
jquery-mobile-dialog
unc
libstdc++
word-processor
jspinclude
parametric-equations
removeclass
coredump
rfc1123
propagation
imac
suppress
meego
zend-tool
iweb
sustainable-pace
signal-handling

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