Results 1 to 7 of 7
  1. #1
    enne87 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default Write XML-Code to console with SAX

    Hi guys!

    I'd like to open an XML-File with SAX and write it to the console. The output should look like the text in the XML-file.

    Can someone please tell me how to do that?

    Thanks,

    enne

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by enne87 View Post
    Hi guys!

    I'd like to open an XML-File with SAX and write it to the console. The output should look like the text in the XML-file.

    Can someone please tell me how to do that?

    Thanks,

    enne

    Surely you don't mean for us to re-write tutorials that are already written and of far better quality than we can do, right? Please Google the tutorials and then feel free to come back if you have a specific answerable question. Much luck.
    Last edited by Fubarable; 11-21-2010 at 12:07 AM.

  3. #3
    enne87 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    Hey Fubarable!

    I've read a lot of tutorials, but but I can't find one that describes how to exactly write a XML-file to the console. It is simple with DOM, there you can use the given document but I have no idea how to do that with SAX.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    While with DOM you can wait until you've finished parsing to display it, with SAX I believe that you'd have to write it out as you parse through it.

  5. #5
    enne87 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    You're right, so do you think that I should use this methods in the ContentHandler and append "<" and ">" to create my nodes?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The other big difference as far as I understand it is that the DOM has a built-in mechanism for outputting an XML String based on its model while SAX does not. So yep, I think that you're going to have to write your own code to take the data extracted in the ContentHandler and output pretty well-formatted Strings. Another alternative is to use StAX which like DOM has the intrinsic ability to write out XML, but has lower memory overhead than DOM.

  7. #7
    enne87 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    Ok, thanks Fubarable for your help.
    I'll try to parse the XML-Code and write it out.

    Cheers,

    enne

Similar Threads

  1. What are you using to write your code?
    By CaptainMorgan in forum New To Java
    Replies: 997
    Last Post: 11-04-2014, 06:46 PM
  2. how do i write this code?
    By Libertyman in forum New To Java
    Replies: 23
    Last Post: 06-22-2010, 01:43 PM
  3. How To Write Unmaintainable Code
    By tim in forum Forum Lobby
    Replies: 2
    Last Post: 02-07-2010, 10:19 PM
  4. Can I write code in 2 different files ?
    By fartek in forum New To Java
    Replies: 2
    Last Post: 02-14-2009, 04:48 PM
  5. Replies: 1
    Last Post: 07-24-2007, 03:02 AM

Posting Permissions

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