• 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 ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • 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:complexType>
<xs:sequence>
<xs:element ref="contact"/>
</xs:sequence>
</xs:complexType>
</xs:element>

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


my xml doc

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

<contacts xsi:noNamespaceSchemaLocation="contacts.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<contact>
<firstname>Edwin</firstname>
<lastname>Dankert</lastname>
</contact>
</contacts>

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 =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";

static final String W3C_XML_SCHEMA =
"http://www.w3.org/2001/XMLSchema";


public static void main(String[] args) {
try {
DocumentBuilderFactory lDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
// lDocumentBuilderFactory.setAttribute(JAXP_SCHEMA_LANGUAGE,W3C_XML_SCHEMA);
lDocumentBuilderFactory.setValidating(true);
lDocumentBuilderFactory.setNamespaceAware(true);
//lDocumentBuilderFactory.setFeature(XMLConstants.DEFAULT_NS_PREFIX,true);
//lDocumentBuilderFactory.setFeature(XMLConstants.RELAXNG_NS_URI,true);


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) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
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!