How to read and parse a remote XML file with Java

T

Thomas Armstrong

Hi.

Using J2SE v1.4.2, I'd like to read and parse a remote file:
http://foo.com/file.xml

Is it possible with Java? I'd be extremely grateful if someone could
provide me any webpage showing a very simple code.

Thank you very much.
 
A

Andrew Thompson

Thomas Armstrong wrote:
...
Using J2SE v1.4.2, I'd like to read and parse a remote file:
http://foo.com/file.xml

It is possible using Java 1.1, but 1.4 makes it easier
in that 1.4 introduced API's specifically for parsing
XML (see the javax.xml hierarchy packages for
more details).
Is it possible with Java?
Yes.

...I'd be extremely grateful if someone could
provide me any webpage showing a very simple code.

And what if someone had a link to a web page that
had simple, but not *very* simple, code to do that?
Should they simply not reply?

<dws>Would you like us to code it for you?</dws>

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1
 
T

Thomas Armstrong

And what if someone had a link to a web page that
had simple, but not *very* simple, code to do that?
Should they simply not reply?

<dws>Would you like us to code it for you?</dws>

I'm not a Java programmer, and I only need a "hello world" sample in
order to make a comparative table between Perl, PHP, Python and Java
with Web Services.

Thank you very much.
 
I

Ian Wilson

Thomas said:
I'm not a Java programmer, and I only need a "hello world" sample in
order to make a comparative table between Perl, PHP, Python and Java
with Web Services.

Why Java 1.4.2[1] and not a current Java?
Are you comparing it with Perl 4 and PHP 3?

What type of XML parser are you using in Python, PHP and Perl? SAX? DOM?
other? It would be silly to compare a Perl SAX parser with a Java DOM
parser or vice versa.

[1] From original posting.
 
M

Mark Space

Thomas said:
I'm not a Java programmer, and I only need a "hello world" sample in
order to make a comparative table between Perl, PHP, Python and Java
with Web Services.


Try starting here; this will tell you how to go from a URL to an open
file for reading:

http://java.sun.com/docs/books/tutorial/networking/urls/index.html

I'm not having a lot of luck finding "simple" programming examples of
XML parsers. Here's one that at least includes a lot of examples:

http://www.totheriver.com/learn/xml/xmltutorial.html

Try doing some Google searches for "java xml parser tutorial" you might
find some that are better for you. Good luck.
 
L

Lew

Ian said:
Why Java 1.4.2[1] [2]
and not a current Java?
Are you comparing it with Perl 4 and PHP 3?

What type of XML parser are you using in Python, PHP and Perl? SAX? DOM?
other? It would be silly to compare a Perl SAX parser with a Java DOM
parser or vice versa.

[1] From original posting.

[2] which is in its "End-of-Life" process.
 
R

Roedy Green

Using J2SE v1.4.2, I'd like to read and parse a remote file:
http://foo.com/file.xml

Is it possible with Java? I'd be extremely grateful if someone could
provide me any webpage showing a very simple code.

Thank you very much.

Split the problem in two. 1. Get the file. 2.Parse it.

To get the file, have a look at the code at
http://mindprod.com/products1.html#SUBMITTER

It fetches an XML PAD file.

The http://mindprod.com/products.html#HTTP
and http://mindprod.com/products.html#FILETRANSFER
classes will be useful.

Then to parse it, see code at http://mindprod.com/jgloss/xml.html
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Thomas said:
I'm not a Java programmer, and I only need a "hello world" sample

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse((new URL(url)).openStream());
in
order to make a comparative table between Perl, PHP, Python and Java
with Web Services.

You don't do web services in Java like that, so I am very skeptical
about the outcome of your "comparison".

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top