Validation XML agaist XSD

This should cover W3C XML Schema, Relax NG and DTD related problems.
Posts: 1
Joined: Wed Mar 01, 2006 3:42 am

Validation XML agaist XSD

Post by rajraj » Wed Mar 01, 2006 3:44 am

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns=" ... cation.xsd" xmlns:mh=" ... Header.xsd" xmlns:sn=" ... cation.xsd" xmlns:xsd="" targetNamespace=" ... cation.xsd" elementFormDefault="qualified" version="4.0.00">
<xsd:import namespace=" ... Header.xsd" schemaLocation="../../Container/Public/MessageHeader.xsd"/>
<xsd:import namespace=" ... cation.xsd" schemaLocation="../../Container/Public/Notification.xsd"/>
<!-- Schema structure -->
<xsd:element name="Notification" type="Notification"/>
<xsd:complexType name="Notification">
<xsd:element ref="mh:MessageHeader"/>
<xsd:element ref="sn:Notification"/>

I have the above XSD ( which imports 2 XSD's )

I am validating the XML against the XSD.. and the XML looks like

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













I am getting the following error


<?xml version='1.0' encoding='UTF-8'?>
** Parsing error SAXParseException, line 8, uri null
src-resolve: Cannot resolve the name 'mh:MessageHeader' to a(n) elment declar
ation component.
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'mh:MessageH
eader' to a(n) elment declaration component.
at weblogic.apache.xerces.parsers.AbstractSAXParser.parse(Lorg/xml/sax/I
at weblogic.xml.jaxp.WebLogicXMLReader.parse(Lorg/xml/sax/InputSource;)V
at weblogic.xml.jaxp.RegistryXMLReader.parse(Lorg/xml/sax/InputSource;)V
at javax.xml.parsers.SAXParser.parse(Lorg/xml/sax/InputSource;Lorg/xml/s
at XMLBean.onMessage(Ljava/lang/String;)V(
at XMLBean.main([Ljava/lang/String;)V(

This is the Validation Code i have

static final String W3C_XML_SCHEMA = "";
static final String JAXP_SCHEMA_SOURCE = "";

RequestHandler rh = new RequestHandler();

try {

String txt = uri;

SAXParserFactory fact = SAXParserFactory.newInstance();

fact.setFeature("", true);
fact.setFeature(" ... l-checking", true);

SAXParser sp = fact.newSAXParser();

sp.setProperty(JAXP_SCHEMA_SOURCE,new File(SchemaUrl));

InputSource inSource = new InputSource(new FileInputStream(txt));
sp.parse(inSource, rh);


Why i am getting the error ? Any idea ?

I do not have the access to .. is that a problem ?

Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung » Mon Mar 06, 2006 10:50 pm

You need to declare your namespaces in your xml file
the xml has no idea what mh: represents.
same with sn:

eg you have in your schema file.
xmlns:mh=" ... Header.xsd" xmlns:sn=" ... cation.xsd"
Last edited by jkmyoung on Wed Mar 08, 2006 5:50 pm, edited 1 time in total.

Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Wed Mar 08, 2006 12:31 pm

And you need to declare namespaces for those prefixes also in the schema file:

<xsd:element ref="mh:MessageHeader"/>
<xsd:element ref="sn:Notification"/>

Best Regards,

Post Reply