OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] Associating an XML Schema with a XML Document

[ Lists Home | Date Index | Thread Index ]
  • To: "'List - XML-Dev'" <xml-dev@lists.xml.org>
  • Subject: Re: [xml-dev] Associating an XML Schema with a XML Document
  • From: Mike Rawlins <mcr@rawlinsecconsulting.com>
  • Date: Sat, 01 Nov 2003 17:44:21 -0600
  • In-reply-to: <00a201c3a021$d428bb70$6501a8c0@lotus.com>
  • References: <000901c39ea2$e9dd9790$6901a8c0@bedford.progress.com>


You'll need to set several options in your DocumentBuilderFactory class 
before you create your document.  Setting these will tell the parser to 
validate against the referenced schema when it loads and parses the 
instance document.

Here's how I typically do it, with comments:

         //  Set up DOM XML environment
         DocumentBuilderFactory Factory =

         //  Set the factory to create a Document Builder that
         //    is:
         //  Namespace aware - necessary for schema validation
         //  Ignores whitespace on Element only nodes
         //  Ignores comments
         //  Set the schema language - these attributes are
         //  specific to Xerces2
         //  Validating, if requested
         if (boValidate)

         //  Create the new document builder
         DocumentBuilder Builder = Factory.newDocumentBuilder();

The JAXP constants are set by:

import org.apache.xerces.jaxp.JAXPConstants;

(assuming, of course, that you're using Xerces).

Hope this helps,


At 09:42 PM 10/31/2003 -0500, Luciano Resende (Discussion List) wrote:
>Thank you all for all the help, looks like i got the xml working, at least 
>my xml editor recognize it as a valid xml :
><?xml version="1.0" encoding="UTF-8"?>
>I have a sample JAXP/DOM code working with the validation based on a DTD, 
>can somebody give any sample on how to use a parser to validate the xml 
>document using the XML Schema associated with it ?

Michael C. Rawlins, Rawlins EC Consulting
Using XML with Legacy Business Applications (Addison-Wesley, 2003)


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS