Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

How to read and parse a remote XML file with Java

Thread view: 
Thomas Armstrong - 31 Aug 2007 12:46 GMT
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.
Andrew Thompson - 31 Aug 2007 15:12 GMT
...
>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>

Signature

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

Thomas Armstrong - 31 Aug 2007 15:37 GMT
> 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.
Ian Wilson - 31 Aug 2007 16:43 GMT
>> 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?
[quoted text clipped - 4 lines]
> 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.
Lew - 31 Aug 2007 17:15 GMT
> Why Java 1.4.2[1]
[2]
> and not a current Java?
> Are you comparing it with Perl 4 and PHP 3?
[quoted text clipped - 4 lines]
>
> [1] From original posting.

[2] which is in its "End-of-Life" process.
<http://java.sun.com/j2se/1.4.2/>
> J2SE 1.4.2 has begun the Sun End of Life (EOL) process.
> The EOL transition period is from Dec, 11 2006,
> until the General Availability (GA) of the next Java version,
> Java SE 7, currently planned for the summer of 2008.
> With this notice, customers are strongly encouraged to migrate
> to the current release, Java SE 6.

Signature

Lew

Mark Space - 31 Aug 2007 16:56 GMT
>> And what if someone had a link to a web page that
>> had simple, but not *very* simple, code to do that?
[quoted text clipped - 5 lines]
> 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.
Arne Vajhøj - 30 Sep 2007 21:49 GMT
> 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
Roedy Green - 01 Sep 2007 13:11 GMT
On Fri, 31 Aug 2007 11:46:23 -0000, Thomas Armstrong
<tarmstrong@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>Using J2SE v1.4.2, I'd like to read and parse a remote file:
>http://foo.com/file.xml
[quoted text clipped - 3 lines]
>
>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
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.