Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2010, 12:46 PM   PM User | #1
dave0110
New to the CF scene

 
Join Date: Dec 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
dave0110 is an unknown quantity at this point
XML InputSource class and the retrieval/browser type

Hi all,
I hope this is the right forum subsection..
I'm trying to make an application which gets data in the form of XML using a URL but I don't think I'm getting the right data that I'm expecting returned to me.
The thing is, when I "view source" for the URL (which has search parameters encoded into it), using Firefox I get xml and using Chrome, I get something completely different so how can I choose which I want to use?

I'm currently using the InputSource class in org.xml.sax to access the URL but I think I'll probably have to use another class as well to achieve what I want if it's even possible.

Sorry if anything I've said doesn't make sense,

I appreciate any help, thank you!
dave0110 is offline   Reply With Quote
Old 12-03-2010, 01:34 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Connecting remotely you'll need something from the java.net package. Look into the use of java.net.url for this. Here are a couple of links for that:
http://stackoverflow.com/questions/2...-http-requests
http://www.javaprogrammingforums.com...bsite-url.html

Both of them look fairly good, the first is much more too the point so its a lot shorter. Capture your results in a string or a stream to use in the parser.

Once you have retrieved the data, what you do with it is up to you. A sax parser would work, but if memory is less of an issue and simplicity more of a desire, I'd actually look at using a DOM since it gives you better manipulation handling out of the box. Here is a simple link for those, I didn't go over this extensively, but it looks ok. Shows examples for using both a sax and dom approach to parse your data: http://www.rgagnon.com/javadetails/java-0408.html

Hope that gets you started!
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
dave0110 (12-03-2010)
Old 12-03-2010, 02:45 PM   PM User | #3
dave0110
New to the CF scene

 
Join Date: Dec 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
dave0110 is an unknown quantity at this point
Thumbs up

Thank you ever so much Fou-Lu!

I'm actually surprised to see that you said the first is shorter and more to the point, I actually thought it was a lot longer and the layout/font/highlighting makes it much harder for me to understand it whereas just a quick read through the code in the second link and it (at least) appears very simple/clean and I think I understand exactly how it works.

Since I'm mostly doing this as a learning exercise (well, it's a project for my course), I think I'll use SAX (since I think it'd be better for me to learn to use).

Thanks again, it's exactly what I was looking for!
dave0110 is offline   Reply With Quote
Old 12-03-2010, 07:20 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Sorry, I posted my links backwards >.<
The second is much shorter and to the point.

With a sax parser just be aware that it works backwards of the dom (sorta). Instead of loading an XML tree into memory you will trigger events when it comes across the desired matching elements in the tree. This is exceedingly handy because of its low overhead, but as I mentioned it will get complicated if you were to start managing the tree and altering its structure.
Just like everything, both dom and sax have there places. With the size of data you are working with, you won't see a noticeable problem with either, so go with whichever you feel best with using (or are required )
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
dave0110 (12-03-2010)
Old 12-03-2010, 11:06 PM   PM User | #5
dave0110
New to the CF scene

 
Join Date: Dec 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
dave0110 is an unknown quantity at this point
Ah okay, well that's good because it means I'm not finding it harder to understand (supposedly) easier stuff :P

And thank you for that additional information, it will be useful when I come to justify my choices; I won't be altering the XML in any way so I think I should be good with SAX

Thanks again!
dave0110 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:45 PM.


Advertisement
Log in to turn off these ads.