After 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
Thanks for sharing, whts your next tutorial series ?
Next I’ll cover OOP design, design patterns, software development and algorithms.
superb bro.
Thank you 🙂 Part 46 is going to be really good
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.
You’re very welcome and thank you for the input 🙂
Fantastic explanation of parsing xml file in JAVA with examples.
Appreciate your lecture whole-heartedly.
You’re very welcome 🙂
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
Here is the solution http://stackoverflow.com/questions/1866886/warning-validation-was-turned-on-but-an-org-xml-sax-errorhandler
I replaced the document src with a web address, but I always get a 403 error. How can I get past this?
Actually, never mind. I found out how. The videos are awesome!
Thank you 🙂
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…
Thank you very much 🙂 I’ll be getting into the web side of Java soon. May God bless you as well.
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…
Thank you 🙂 I’ll do my best to cover sax. I get into parsing options in my Android tutorials as well.
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.
Here is an explanation that may help
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
I cover that as the tutorial continues in depth.
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
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
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
Thank you 🙂 I’m very happy that you are enjoying them.