• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Question about loading an xml file into a file object

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to load an xml file from "http://localhost:61300"; into my file object. Shouldn't it look like this:

It seems to want to find it on my local file system. What do I need to do so it will load it form the web and not locally? Thanks in advance.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the java.net.Url class.
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a rough time, can you take a look? This is just one of the methods. I am trying to load the xml file in each. But I can't just do "xmlURL = new URL("http", "localhost", 61300, "/CoolMon.xml");" at the top because it needs to throw an error.

[ June 02, 2002: Message edited by: Chris Stewart ]
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java.io.File class is meant to only reference files on the file system, not arbitrary URLs. So you have to use one of the other parse methods of the DocumentBuilder:
- use an URL object and its openConnection() method to get an InputStream to parse from
- use an org.xml.sax.InputSource with the URL as systemId, or
- simply use the parse method that gets the url as String parameter
Hope this helps...
 
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic