wood burning stoves 2.0
The moose likes XML and Related Technologies and the fly likes Cannot find the declaration of element 'tns:MetricConfiguration' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Cannot find the declaration of element Watch "Cannot find the declaration of element New topic

Cannot find the declaration of element 'tns:MetricConfiguration'

Kartik Patel
Ranch Hand

Joined: Sep 12, 2005
Posts: 73
I am new to XML world. I am trying to validate one xml using xsd. xml and xsd both are in seperate jars but in classpath

Here is the snippet of the xsd,xml and code

<?xml version="1.0" encoding="UTF-8" ?>
- <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.metrics.org/MetricsConfiguration" targetNamespace="http://www.metrics.org/MetricsConfiguration" elementFormDefault="qualified">

<?xml version="1.0" encoding="UTF-8"?>
<tns:MetricConfiguration xmlns:tns="http://www.metrics.org/MetricsConfiguration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.metrics.org/MetricsConfiguration config/schema/MetricsConfiguration.xsd">

[ December 11, 2008: Message edited by: Martijn Verburg ]

Chop your own wood, and it will warm you twice. - Henry Ford
Kartik Patel
Ranch Hand

Joined: Sep 12, 2005
Posts: 73
request to please respond to this
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
Originally posted by Kartik Patel:
request to please respond to this

Read this FAQ, please.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I think you'd get a lot better response, if you posted your question in "XML and Related Technologies"
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

I agree, so I will move this thread.

How To Ask Questions How To Answer Questions
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

If I'm not mistaken, this part of the schema declaration in your XML document:

says the schema will be found in the root of the file system where the XML document is located. If you gave the parser something with a URL, then it would be able to look there. But if you gave the parser an InputStream, it wouldn't know where to look for the schema.

However it appears the schema isn't in the "root" of the jar file where the XML document is, but it's in some other jar file. So you need to attach an EntityResolver to the parser which provides the schema as a Source (probably a StreamSource) when the parser tries to resolve its URL.
I agree. Here's the link: http://aspose.com/file-tools
subject: Cannot find the declaration of element 'tns:MetricConfiguration'
It's not a secret anymore!