XML parsing (reformatted) - please any insight would help

Hey there,
Im having a problem, code compiles but doesnt work gives no output.
Please can someone help me with this.
This is the Code
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import java.io.*;
public class ReadLibrary extends DefaultHandler {
public static void main(String[] arguments) {
if (arguments.length > 0) {
// ReadLibrary read = new ReadLibrary("w:\\Collection.librml.xml");
} else {
System.out.println("Usage: java ReadLibrary filename");
ReadLibrary(String libFile) {
File input = new File(libFile);
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
try {
SAXParser sax = factory.newSAXParser();
sax.parse(input, new LibraryHandler() );
} catch (ParserConfigurationException pce) {
System.out.println("Could not create that parser.");
System.out.println(pce.getMessage());
} catch (SAXException se) {
System.out.println("Problem with the SAX parser.");
System.out.println(se.getMessage());
} catch (IOException ioe) {
System.out.println("Error reading file.");
System.out.println(ioe.getMessage());
class LibraryHandler extends DefaultHandler {
static int READING_TITLE = 1;
static int READING_AUTHOR = 2;
static int READING_PUBLISHER = 3;
static int READING_PUBLICATION_DATE = 4;
static int READING_SUBJECT = 5;
static int READING_REVIEW = 6;
static int READING_NOTHING = 0;
int currentActivity = READING_NOTHING;
Book libraryBook = new Book();
LibraryHandler() {
super();
public void startElement(String uri, String localName,
String qName, Attributes attributes) {
if (localName.equals("Title"))
currentActivity = READING_TITLE;
else if (localName.equals("Author"))
currentActivity = READING_AUTHOR;
else if (localName.equals("Publisher"))
currentActivity = READING_PUBLISHER;
else if (localName.equals("PublicationDate"))
currentActivity = READING_PUBLICATION_DATE;
else if (localName.equals("Subject"))
currentActivity = READING_SUBJECT;
else if (localName.equals("Review"))
currentActivity = READING_REVIEW;
if (currentActivity == READING_PUBLICATION_DATE) {
libraryBook.isbn = attributes.getValue("isbn");
libraryBook.edition = attributes.getValue("edition");
public void characters(char[] ch, int start, int length) {
String value = new String(ch, start, length);
if (currentActivity == READING_TITLE)
libraryBook.title = value;
if (currentActivity == READING_AUTHOR)
libraryBook.author = value;
if (currentActivity == READING_PUBLISHER)
libraryBook.publisher = value;
if (currentActivity == READING_PUBLICATION_DATE)
libraryBook.publicationDate = value;
if (currentActivity == READING_SUBJECT)
libraryBook.subject = value;
if (currentActivity == READING_REVIEW)
libraryBook.review = value;
public void endElement(String uri, String localName, String qName) {
if (localName.equals("Book")) {
System.out.println("\nTitle: " + libraryBook.title);
System.out.println("Author: " + libraryBook.author);
System.out.println("Publisher: " + libraryBook.publisher);
System.out.println("Publication Date: "
+ libraryBook.publicationDate);
System.out.println("Edition: " + libraryBook.edition);
System.out.println("ISBN: " + libraryBook.isbn);
System.out.println("Review: " + libraryBook.review);
libraryBook = new Book();
class Book {
String title;
String author;
String publisher;
String publicationDate;
String edition;
String isbn;
String subject;
String review;
}and This is the XML
<?xml version="1.0"?>
<!DOCTYPE Library SYSTEM "librml.dtd">
<Library>
<Book>
<Author>Joseph Heller</Author>
<Title>Catch-22</Title>
<PublicationDate edition="Trade" isbn="0684833395">09/1996</PublicationDate>
<Publisher>Simon and Schuster</Publisher>
<Subject>Fiction</Subject>
<Review>heller-catch22.html</Review>
</Book>
<Book>
<Author>Kurt Vonnegut</Author>
<Title>Slaughterhouse-Five</Title>
<PublicationDate edition="Paperback" isbn="0440180295">12/1991</PublicationDate>
<Publisher>Dell</Publisher>
<Subject>Fiction</Subject>
</Book>
</Library>

Sorry i am new to this XML stuff so i think im going to sound really dumb,
the code there comes from a Samms teach urself java in 21 days, shouldnt the println's in endElement be displayed? and regarding the LibraryBook = new LibraryBook() that was in the example code.
To see the tag data how would i display it ?

Similar Messages

  • I am having trouble getting a numbers spreadsheet to hold different formats in the same column.  A column with a date formatted heading will not convert to $ for the cells below.   Any suggestions would help.

    I am having trouble getting a numbers spreadsheet to hold different formats in the same column.  A column with a date formatted heading will not convert to $ for the cells below.   Any suggestions would help.

    Hi Wayne,
    Thank you for this response.  I have tried this but when I start enterring $ amounts some, such as $6.00, go in OK others such as $4.00 appear as a date ie 4 Oct 12.  
    Kind regards
    Paul

  • When priniting jewel case inserts, my song order is reversed. The numbering is correct, but the song titles are incorrect. This only happens on jewel case inserts. Any insight would be greatly appreciated.

    When priniting jewel case inserts, my song order is reversed. The numbering is correct, but the song titles are incorrect. This only happens on jewel case inserts. Any insight would be greatly appreciated.

    Hi,
    I have exactly, exactly!! thesame annoying problem you have or had. I don't know what to do and i am reallyfrustrated with the dumb limited inside the box solutions offered to me. It'slike if you have a problem with your ipod or iphone you can either restore it,uninstall/reinstall itunes and thats pretty much it. I am sorry but that isjust f***** up.
    anyway, regardless to all that,i was wondering if you had any success in solving this problem (something otherthan using a different computer which oddly enough seemed to work for somereason..?? why???, weird) since April.
    I am on the edge of givingup.
    thank you in advance.

  • Good day , please Any one can help me

    Recently I get an iPhone witch was used from many month , the problem is that I don't know the first user so I don't know the password of the existing Appel Id and I can't delete his Apple ID because i don't know it's password , I make my Owen Apple ID and I have changed many things but the problem still in the iCloud because I can't delete the existing id so all my data may go to another person so please advise 

    user12039624mhmads81 wrote:
    ... Please any one can help me to get a good document for upgrading database from Upgrade Database From 8i & 9i& 10g to 11g which include prerequisite and upgrade process and after upgrading process waiting for your response because it necessary neededI'm wondering how the previous answer is correct since it is the 10g upgrade guide whereas you're looking for a 11g upgrade.
    By the way which 11g release ?
    Once you choose your release target, got to the doc http://www.oracle.com/technology/documentation/index.html click on the link corresponding to your target version, there will be an upgrade guide with all the steps you need to know.
    Nicolas.

  • I have a macbook air and my camera has seemed to have disappeared.  I can't find iSight and am wondering what happened.  Any feedback would help.  Thanks.

    I have a macbook air and my camera has seemed to have disappeared.  I can't find iSight and am wondering what happened and how to fix it and/or reinstall the camera, I'm using mountain lion 10.8.  Any feedback would help.  Thanks.

    Reset SMC.     http://support.apple.com/kb/HT3964
    Choose the method for:
    "Resetting SMC on portables with a battery you should not remove on your own".
    http://support.apple.com/kb/HT2090
    Best.

  • Java and XML Parser. Please guide.

    Hello there,
    I need to pass an XML document using the SAX Parser.
    Please does any one have an XML Parser routine to parse
    the document or can some one guide me as to what to do?

    any sax parsers?What version of Java are you using? With Java 1.4 the XML parser is included in the SDK / JRE.
    If you're using an older version of Java, go to http://xml.apache.org and get the Xerces parser.

  • HT3910 am in tanzania. and am in need of a copy of CDdrive for a macbook pro. how can i get a copy, please any one to help

    am in tanzania.
    Am in need of a copy of DVDdrive for a macbook pro OS. how can i get a copy, please any one to help

    If you are referring to the original system reinstall discs that shipped with every Mac before Lion came out you'll need to contact Apple with the serial # of your Mac and order a replacement set of them.
    Or look on one of the Auction websites or places like iFixit.com for a replacement set.
    If your Mac came new with any of the Download Only versions of OS X, Lion, Mt Lion or Mavericks you don't need any discs to reinstall OS X. You use the Online Internet Recovery system or the built in Recovery HD partition inb the internal hard drive.
    For the built in Recovery HD hold down the Command + r keys at startup. For the Online system hold down the Command + Option/Alt + r keys and keep them held down until you see a globe on the screen.

  • Hello I am having problems viewing areas of a pdf...it's a form fillable pdf that someone else has completed and saved..I'm able to view all but the areas that have been filled in.. any info would help

    Hello I am having problems viewing areas of a pdf...it's a form fillable pdf that someone else has completed and saved..I'm able to view all but the areas that have been filled in.. any info would help

    Hi Bob, I just tried your suggestion, but the interactive PDF is in spreads by default, no way to change the setting. When I choose to view by single page in Acrobat, it displays a single spread.
    When I choose to view by spreads, it displays 4 pages, two spreads. That's the topic of this whole discussion, I believe. I do own CS 6 at home, however my employer supplied me with CS 5.5. And I have very little, if any, influence on purchasing.
    So, I have no good way to make an interactive PDF (with differing recto/verso headers and footers), that is accessible and shows the correct header/footer. It's either single pages (with one header/footer), or recto/verso headers/footers but PDF only as a spread, as well as I can tell.
    Unless you know something else I can do...
    Best, Marilyn

  • HT2693 my iphone has froze up and it will not do anything, i am getting a blank black screen and it will not turn off completely or turn on.  i dk what to do.  any information would help greatly.

    My daughter was playing a game on my husbands phone and it froze on her.  The screen displayed the turnoff slide bar or cancel, he tried to hit cancel and it did nothing, so he slid the slide to turn off.  when he did that he proceeded to turn off, but never completely shut off, and now the phone will do nothing!  I have tried restoring and also hooking up to itunes.  i do not know what to do in this situation.  any help would be greatly appreciated.  i dont know if there is a way to take the back off to remove the battery.  if you could give me some information that would be great.  thank you

    Try a reset by pressing and holding the Power and Home buttons for 15-20 seconds until the white Apple logo appears.
    Was the battery replaced by Apple or an authorized repair facility?  If not, and any warranty existed, that warranty is now void.

  • TS3274 I'm trying to buy a song on iTunes, it asked me 2 security questions that I can not answer correct. How do u get around this? I do not even remember answering them. Any info would help thank you

    I was trying to buy a song on iTunes, it asked me 2 security questions that I do not ever remember answering before. How do u get around these questions? Any help would be great. Very frustrating :(

    Call Apple to help reset your Security Question.
    http://support.apple.com/kb/HE57

  • Hello i am new on BB and having this problem please any one can help me out!

    Hi i am having a weird problem with my device bold 9780.
    Consider that i am using device with switching the mobile network off and not even taking BB services.. My browser works fine on wi-fi but appworld only works whenever the phone is restarted and it only works for a day after that it starts giving an error " we cant connect to BB app world. Please ensure that your device is connected to a wireless network and try again " it wont work again unless the phone is restarted.. i have tried reinstalling the appworld and even also wiping the phone but the problem remains same.
    Please please help me out with this problem. I'll be waiting!! 

    On your 9780, What is your Operating System loaded to your device? Look at Options > Device > About, third line down beginning with a "v.6.0.x.xxx", What is yours?
    At Options > Device > Applications, what is the version of Appworld installed?
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • HT201272 I downloaded sveral ringtones and they are not showing up in my purchased items.   I had to wipe out my phone so they are not on there anymore.  Please, any advice would be appreciated!

    I recently had to wipe out my phone and lost everything!  I have been able to recover all apps, pics, songs.  Lost alot of my contacts due to me not backing up my info to icloud more often.  (my mistake)  However, I cant find any of my purchased ringtones.  They are not showing up in my purchase history on itunes either.  I do have the receipts for all of them tho.
    Any advice or info would be greatly appreciated!

    Ringtones are currently a one-time only download, they won't appear under the Purchased tab nor in the cloud. Have you got copies of them in the Tones section of your computer's iTunes library or in the backup of your downloads that you can use to re-sync them to your phone ? If not, and they are still in the store, then you can try contacting iTunes support and see if they will grant you a re-download : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then try selecting Purchases, Billing & Redemption

  • I've having a problem with not being able to move the browser window around on my desktop. My last alternative is to uninstall Firefox and try a reinstall, but I'm afraid I'll loose all of my bookmarks. Any insight would be appreciated. Thanks--

    Vista Home Premium / Service Pack 2
    Intel Core 2 Quad CPU Q 9400 @ 2.66GHz
    3 GB Ram
    32-bit OS

    Did you check what I would consider the first place to look:
    * http://kb.mozillazine.org/Problematic_extensions
    If the site is still down (at least 12 hours) when you read this try [http://webcache.googleusercontent.com/search?q=cache:http%3A//kb.mozillazine.org/Problematic_extensions Google's cache]
    Link or url would make it easier to see which page you tried rather than "your online solution for ...".
    * http://kb.mozillazine.org/Firefox_hangs ([http://webcache.googleusercontent.com/search?q=cache:http%3A//kb.mozillazine.org/Firefox_hangs cached version])
    * http://kb.mozillazine.org/Firefox_crashes ([http://webcache.googleusercontent.com/search?q=cache:http%3A//kb.mozillazine.org/Firefox_crashes cached version])
    * [https://support.mozilla.com/kb/Firefox%20hangs#os=mac&amp;browser=fx4 Firefox hangs | Troubleshooting | Firefox Help]

  • Is it legal to use other peoples music in a Podcast that is for fee?? Im not sure how to go about this? I have DJ who will mix the music for me, but im not sure that it is legal?? Thanks any guidance would help

    Hi everyone
    I am wanting to create music playlists for free via itunes in the form of a podcast of gym sort of music that can be used by people to listen to whilst working out. Can someone tell me if this is legal to use other peoples music, or songs and change them slightly so they blend into a continuous podcast?? thanks

    To The Fit Guy,
    Absolutely - 100% - NO!!!!!
    You can not take any RIAA / big label music and use it in a podcast.
    A Podcast is a download and downloads are looked at legally as a mechanical copy.
    Just because you purchased a song - it does not give you any rights what so ever to use that in a podcast.
    On top of that - you can not even get licenses for Podcasts to use the music.  As the Soundexchange license used for streaming music does NOT cover downloads. 
    And even if you could get licenses - one of them is working with the Harry Fox agency - they cover mechanical copies - and it is $0.091 per download (copy) for each song.  So if you have a mix of 10 songs in an episode - you would need to pay Harry Fox agency $0.91 per download.
    The only music you can use in a podcast is music considered "Podsafe"
    http://en.wikipedia.org/wiki/Podsafe
    Regards,
    Rob W
    podCast411

  • Itunes does not recognize my iphone 4.  I am running Windows XP with IE.  Any suggestions would help.  Thanks.

    Itunes does not recognize my Iphone 4. I did a restore on my phone about four months ago..  Does anyone have any suggestions as to what I can try?

    try deleting these preference files
    •C:\Documents and Settings\Your Username Here\Application Data\Apple Computer\iTunes
    •C:\Documents and Settings\Your Username Here\Local Settings\Application Data\Apple Computer\iTunes
    •C:\Documents and Settings\All Users\Application Data\Apple Computer\iTunes\SC Info

Maybe you are looking for

  • Analog to digital, how does one actually pass through a TRV120 or TRV950E ?

    I would need some technical advice on how to connect a camera with pass-through feature in between a VCR and the computer. I am trying to copy VHS-C cassettes to the Mac via a Digital8 Sony TRV-120. I use A/V pin connector from the VCR, Firewire to t

  • How to resize all checkboxes in fillable PDF

    I am using Adobe Acrobat Standard 9 and have a fillable form with many checkboxes. Problem is they are of varying sizes. Does anyone know of a way that I can apply a change to uniformly apply to all of them? Thanks!

  • Error on the first step ./sapinst

    I got the following error when I issued ./sapinst command. How to solve it? OS: RHEL4 U5 32bit DB2 V8 FP9 COPY FROM MY SCREEN---- [root@EXXEPT01 IM_LINUX_I386]# ./sapinst [==============================] - extracting...  done! Starting GuiServer usin

  • MULTI entry of questions due to iOS safari reporting that the support was in maintenance

    I Had a need to use the the gps so I turned on the location services to do it and I noticed ( after returning the phone to normal ( no use of the gps apps) a few phone calls a day and a text or two a few calendar notifications etc that my 4s went fro

  • T030 for not valuated materials

    Hi gurus, I've created a material type with these attributes: Quantity updating --> In all valuation areas Value updating --> In no valuation area When I create a PO for this material system requires returns me (correctly) this message "Account assig