Java Video Tutorial 44

Parse XML JavaAfter I made my XML Video Tutorial, you asked me to show you how to parse XML with Java. So, that is what I’m doing in this tutorial.

I wasn’t sure how much to cover, because I could literally create a 5 part series on this topic. I decided to cover the basics in the video and provide another example in the code below.

If you want to see more, tell me and I’ll cover more on parsing XML with Java.

If you like videos like this, please tell Google [googleplusone]

Sharing is always appreciated [nttfblike]

Code from the Video

JAVALESSON44.JAVA

XML File I Use

25 thoughts on “Java Video Tutorial 44”

      1. I appreciate the video very much. As a Noob, I spent several hours trying to determine why I was getting a “document not properly formed error”. Turns out that the DTD file is not listed along with the code. I only learned this after a considerable amount of internet research and going to your XML 4 tutorial. Please help Noobs by keeping all the associated code together for each video. But, I also learned more about XML in general during my research on StackOverflow, so its good & bad.

  1. Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
    set, which is probably not what is desired. Parser will use a default
    ErrorHandler to print the first 10 errors. Please call
    the ‘setErrorHandler’ method to fix this.
    Error: URI=file:///home/niraj/webcode/Lesson44/src/tvshow.xml Line=4: Element type “tvshow” must be declared.
    Error: URI=file:///home/niraj/webcode/Lesson44/src/tvshow.xml Line=5: Element type “show” must be declared.
    Error: URI=file:///home/niraj/webcode/Lesson44/src/tvshow.xml Line=6: Element type “name” must be declared.
    Error: URI=file:///home/niraj/webcode/Lesson44/src/tvshow.xml Line=7: Element type “release” must be declared.
    Error: URI=file:///home/niraj/webcode/Lesson44/src/tvshow.xml Line=8: Element type “network” must be declared.
    Error: URI=file:///home/niraj/webcode/Lesson44/src/tvshow.xml Line=9: Element type “description” must be declared.
    Error: URI=file:///home/niraj/webcode/Lesson44/src/tvshow.xml Line=10: Element type “actors” must be declared.
    Error: URI=file:///home/niraj/webcode/Lesson44/src/tvshow.xml Line=11: Element type “actor” must be declared.
    Error: URI=file:///home/niraj/webcode/Lesson44/src/tvshow.xml Line=12: Element type “real_name” must be declared.
    Error: URI=file:///home/niraj/webcode/Lesson44/src/tvshow.xml Line=13: Element type “character” must be declared.
    Root element is tvshow
    Number of shows 4
    network : ABC has attribute US
    network : BBC has attribute UK
    network : ABC has attribute US
    network : ABC has attribute US

  2. I replaced the document src with a web address, but I always get a 403 error. How can I get past this?

  3. You are Awesome !!!….. thanks a ton for all your tutorials…..
    please let me know if you have some online tutorials (advanced Java )… to handle very large xml files (somewhere between 1- 5 GB)…
    god bless you….
    take care…. coz you are very important…

  4. hi i like your tutorials, they are very helpfull for me!
    thank you!
    if you can, it will be great to have one tutorial about xml SAX
    parser. they are common as well..

    take care…

  5. Doesn’t like this line:

    Element showElement = (Element)theRoot.getFirstChild();

    Exception in thread “main” java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredTextImpl cannot be cast to org.w3c.dom.Element
    at readingXMLTest.Lesson44.main(Lesson44.java:53)

    Casting error. New to this, so a little unsure on what the particulars are between Elements & Nodes… ugh, going to take some reading.

  6. Very interesting tutorial.

    I have a general question tho.

    What would you recommend to use to update the xml element content . Basically , what is the best way to copy one node content to another node?

    ex : Just to make it more clear. what would you recommend to copy “Copy me” and replace “text”…hope that makes sense…

    Copy me

    text

  7. Hi,

    Thanks a lot for your great tutorial
    Is there a way to dl the code ? I can not copy paste the code , it takes some other things with it

    1. You’re very welcome 🙂 If you put your mouse over the top right corner of the code, 3 icons pop up. Click on the one named view source and you’ll get the code without line numbers. Sorry about that

  8. Hi Derek,

    Your tutorials are amazing, I am following those since few months, I liked it very very much!Kudos to you for providing such wonderful tutorials that to free! and your efforts for creating those! Lots of blessings to you!
    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *