XML
  Home arrow XML arrow Page 5 - Java and XML Basics, Part 3
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Java and XML Basics, Part 3
By: Liviu Tudor
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 22
    2004-04-20

    Table of Contents:
  • Java and XML Basics, Part 3
  • Which One is the Better One to Use?
  • Running the Parser
  • Problems with Big XML Files
  • Validating Parsers - DOM
  • Where do We Get a Validating Parser?
  • ErrorHandler
  • Validating Parsers - SAX
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Java and XML Basics, Part 3 - Validating Parsers - DOM


    (Page 5 of 9 )

    Now let's go back to our "performant" parsing applications and try something different: so far we have fed our parsers well-formed XML documents; we have seen in the past that trying to feed it some badly formed XML would throw an exception, but what would happen if we supply a well-formed XML file which is not valid?

    For this we will evolve a bit the "employee" example we have presented briefly in the article XML: An Introduction (employee.xml) and run it against SimpleDOMParser.java. Based on the original well-formed and valid XML file, we will change it so it becomes invalid (but still well-formed!):


    <?xml version="1.0" encoding="UTF-8"? >
    <!DOCTYPE Employees [
    <!ELEMENT Employees (Employee)*>
    <!ELEMENT Employee EMPTY>
    <!ATTLIST Employee
      name  CDATA 
    #REQUIRED
      surname CDATA #REQUIRED
      dob  CDATA #IMPLIED
      email  CDATA #IMPLIED
      phone  CDATA #IMPLIED
      address CDATA #IMPLIED>
    ]>
    <Employees>
     <Employee surname="Tudor" dob="14/02/1975" email="user@domain.com" address="Coocooland"/>
     <Employee name="Janet" surname="Jackson" dob="unpolite to reveal" email="janet@rhythmnation.com" address="Really really secret ;-)"/>
    </Employees>

    As you can see, the name attribute is missing for the first element. The result:

    java -classpath "%CLASSPATH%;." SimpleDOMParser employee.xml
    Parsing successful!

    Wow! That I bet you didn't expect that after the whole discussion in this series of articles about valid XML! It looks like our parser is actually considering the XML document as being valid -- even though it's not! So where's the error?

    Well, there is no error! The answer is quite simple: parsing an XML document doesn't necessarily means validating it as well! Therefore some parsers will do on-the-fly validation of the XML parsed; others will just assume that the contents is valid and provide no validation at all. A validating parser will complain about such an invalid XML as the one we have just supplied, while a non-validating parser won't "notice" the "invalidity" of the XML.

    This means that the parser used in our case is a non-validating one! Ouch! Potentially a big problem. Where do we get a validating parser from then? 

    More XML Articles
    More By Liviu Tudor


     

    XML ARTICLES

    - Datatypes and More in RELAX NG
    - Providing Options in RELAX NG
    - An Introduction to RELAX NG
    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT