[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Associating an XML Schema with a XML Document

  • To: "'List - XML-Dev'" <xml-dev@l...>
  • Subject: Re: Associating an XML Schema with a XML Document
  • From: Mike Rawlins <mcr@r...>
  • Date: Sat, 01 Nov 2003 17:44:21 -0600
  • In-reply-to: <00a201c3a021$d428bb70$6501a8c0@l...>
  • References: <000901c39ea2$e9dd9790$6901a8c0@b...>

jaxp_schema_language
Luciano,

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 =
           DocumentBuilderFactory.newInstance();

         //  Set the factory to create a Document Builder that
         //    is:
         //  Namespace aware - necessary for schema validation
         Factory.setNamespaceAware(true);
         //  Ignores whitespace on Element only nodes
         Factory.setIgnoringElementContentWhitespace(true);
         //  Ignores comments
         Factory.setIgnoringComments(true);
         //  Set the schema language - these attributes are
         //  specific to Xerces2
         Factory.setAttribute(JAXPConstants.JAXP_SCHEMA_LANGUAGE,
           JAXPConstants.W3C_XML_SCHEMA);
         //  Validating, if requested
         if (boValidate)
         {
           Factory.setValidating(true);
         }

         //  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,

Mike

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"?>
>
><books 
>xsi:noNamespaceSchemaLocation="file:///d:/ibm/dev/workspaces/dominoportal/dominoadapter/booksextended.xsd"
>
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>
>.....
>
>
>
>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
www.rawlinsecconsulting.com
Using XML with Legacy Business Applications (Addison-Wesley, 2003)
www.awprofessional.com/titles/0321154940


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.