Meaningless Drivel is fun!*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Cannot find the declaration of element Watch "Cannot find the declaration of element New topic
Author

Cannot find the declaration of element 'tns:MetricConfiguration'

Kartik Patel
Ranch Hand

Joined: Sep 12, 2005
Posts: 73
Hi,
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

XSD
<?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
<?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">
<tns:Metrics>......


[ 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
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
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
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

I agree, so I will move this thread.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

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'
 
Similar Threads
Validating XML against Schema.
XML Schema validation from java using Xercer 1.4.4 and DOM
Problem with parsing xml against schema using SAX2Parser
New Fields in XML
SAX parse and validate with XSD