Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

xml error while reading it  RSS feed

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

<xs:schema xmlns:xs="">
<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 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.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("");
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

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!