java


UnknownHostException after the attempt of reading a XML file


I have to serialise key/values of a map to a XML file, and then deserialise them.
Map<String,Integer> map = new HashMap<>();
// ...
LinkedList<Element> l = new LinkedList<Element>();
Element root = new Element("root");
for (String str : map.keySet()) {
l.add(new Element(str)); // key
l.getLast().appendChild(map.get(str).toString()); // value
root.appendChild(l.getLast());
}
Document d = new Document(root);
BufferedWriter out = new BufferedWriter(new FileWriter("data.xml"));
out.write(d.toXML());
out.close();
d = new nu.xom.Builder().build("data.xml"); // !
Elements e = d.getRootElement().getChildElements();
But when I try to read the XML file, UnknownHostException is thrown on the marked line.
Exception in thread "main" java.net.UnknownHostException: file
The XML file is created succesfully though. The formatted version looks like:
<?xml version="1.0"?>
<root>
<through>1</through>
<don>1</don>
<backed>1</backed>
<I>2</I>
<asList>1</asList>
// ....
</root>
Could you please explain me what is the problem?
According to the doc pointed by #delephin, its better to use build(File in) version of build method, pass the File instance associated with your data.xml to your build() method, as below
d = new nu.xom.Builder().build(new File("data.xml"));
The build method expects an URL: Builder.build(String)
You need to pass a proper URL to build(), this includes local files.
You can get the URL for a local file using:
new File(path).toURI().toURL();

Related Links

The meaning of bindings annotation with provider methods
How to compare session attribute and string java
Wrong cipher text length when using 3DESede with PKS5 padding of javax.crypto
SimpleXMLConverter parse xml nodes
Spring Pageable PageRequest order by doesn't work
REST SECURE SECRET KEY
Java - How to make button color appear in GUI Interface Graphing in Mac
Why object instantiation is not needed in some cases such as this?
Spring Security 4 #PreAuthorize Http 405 POST not supported
JSP useBean: Undefined type error
Mouse coordinate issues in Slick2D
How to set java JList to prevent expanding with long strings
How to use Spring Integration Aggregator for 'look-ahead' releasing?
Java - Utilize avail data structure or create new data structure
Unable to display result of camera activity in ImageView
Why does my app crash without any errors?

Categories

HOME
maven
java
arduino-uno
hive
atom-editor
minimum-spanning-tree
ngrx
heroku
push-notification
path-finding
alfresco
react-redux
enterprise-library-5
flyway4
maude-system
reveal.js
imacros
google-cloud-spanner
windows-server-2012
ups
hapi
decimal
seaborn
reactcsstransitiongroup
one-hot-encoding
web-sql
wijmo
hammerspoon
url-scheme
react-css-modules
virtualdub
bootstrap-material-design
tooltipster
fifo
facebook-apps
newline
gsoap
instant-messaging
tinymce-4
azure-sql-database
http-referer
force-layout
git-merge
hilbert-curve
az-application-insights
azure-ml
broadcastreceiver
elmah
modelmapper
flashair
scorm
apple-news
long-polling
chain-builder
revapi
return-value
libusb-win32
windows-mobile-6.5
spring-mongodb
google-cdn
parallel-data-warehouse
abcpdf9
spring-android
vmware-tools
android-textview
intrusion-detection
disque
dlna
dataview
suffix-tree
photobucket
collapse
tmuxinator
tarjans-algorithm
embedded-code
ionic
microbenchmark
service-accounts
dereference
formatjs
markers
android-radiobutton
valuechangelistener
java.nio.file
mbr
industrial
page-layout
xsockets.net
access-rights
inbox
google-cloud-save
eventlistener
anonymous-methods
coderush
semantic-diff
netdna-api
boost-filesystem
libc++
genshi
coredump
sudzc
coda-slider
.nettiers
meego
webkit.net
privilege
commodore

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App