• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

xml error while reading it

Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my schema
<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="contacts">
<xs:element ref="contact"/>

<xs:element name="contact">
<xs:element name="firstname" type="xs:NCName"/>
<xs:element name="lastname" type="xs:NCName"/>

my xml doc

<?xml version="1.1" encoding="UTF-8"?>

<contacts xsi:noNamespaceSchemaLocation="contacts.xsd"

my java dom program

* Generated/ at : 09-May-2006 20:45:32
* Copyright (c) 2005 - 2006, Edwin Dankert
* All rights reserved.

package com.edankert.dom;

import java.io.IOException;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.SchemaFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.edankert.SimpleErrorHandler;

public class ValidateExternalSchema {
static final String JAXP_SCHEMA_LANGUAGE =

static final String W3C_XML_SCHEMA =

public static void main(String[] args) {
try {
DocumentBuilderFactory lDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
// lDocumentBuilderFactory.setAttribute(JAXP_SCHEMA_LANGUAGE,W3C_XML_SCHEMA);

SchemaFactory lSchemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
lDocumentBuilderFactory.setSchema(lSchemaFactory.newSchema(new Source[] {new StreamSource("contacts.xsd")}));

DocumentBuilder lDocumentBuilder = lDocumentBuilderFactory.newDocumentBuilder();
lDocumentBuilder.setErrorHandler(new SimpleErrorHandler());
lDocumentBuilder.parse(new InputSource("contacts.xml"));

} catch (ParserConfigurationException e) {
} catch (SAXException e) {
} catch (IOException e) {
error iam getting

Document is invalid: no grammar found.
Document root element "contacts", must match DOCTYPE root "null

please any one help regarding that

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!