Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    dave0110 (12-03-2010)

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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!

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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 )
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    dave0110 (12-03-2010)

  • #5
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •