Hi Oleg,
Well, you are validating the document against the schema. As your
document is not valid you get an error message.
To have the document valid against the schema you must at least set the
correct namespace for the root element, so add
xmlns="http://mynamespace" to the root element.
You should also enable the namespaces feature I think.
Hope that helps,
George
--
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Oleg Lebedev wrote:
Sorry, I accidentally sent incomplete email. Here is a full version:
Greetings.
I've been struggling with this problem for the last two days. I am
trying to validate an xml document, which does not have any xmlns
namespaces set. Here is an example:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<report end-date="11/22/2005" name="My Report" start-date="12/31/1969"/>
<totals class-avg="0.0" stud-avg="94.0"/>
</data>
I have an XSD schema to which this document should conform to. I am
using sax parser to validate the document as follows:
<BEGIN CODE>
String ns = "http://mynamespace";
String xsdUrl = "MySchema.xsd";
SAXParserFactory spfactory = SAXParserFactory.newInstance();
spfactory.setNamespaceAware(true);
spfactory.setValidating(true);
SAXParser parser = spfactory.newSAXParser();
XMLReader xmlReader = parser.getXMLReader();
// Features
xmlReader.setFeature("http://xml.org/sax/features/namespaces", false);
xmlReader.setFeature("http://xml.org/sax/features/validation", true);
xmlReader.setFeature("http://apache.org/xml/features/validation/schema",
true);
xmlReader.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
true);
xmlReader.setFeature("http://apache.org/xml/features/validation/schema",
true);
xmlReader.setFeature("http://xml.org/sax/features/xmlns-uris", true);
// Properties
xmlReader.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
ns + " " + xsdUrl );
...
xmlReader.parse(xmlDocUrl);
<END CODE>
Note that MySchema.xsd file contains the schema with default namespace
"http://mynamespace" against which I am trying to validate the document.
The last line in the code above always throws an exception:
"org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration
of element 'data'."
Could anybody tell me how to validate XML documents with no namespaces
specified against XSD schemas?
Thanks.
------------------------------------------------------------------------
*From:* Oleg Lebedev [mailto:[EMAIL PROTECTED]
*Sent:* Tuesday, November 22, 2005 10:49 AM
*To:* [email protected]
*Subject:* validating XML with no xmlns
Greetings.
I've been struggling with this problem for the last two days. I am
trying to validate an xml document, which does not have any xmlns
namespaces set. Here is an example:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<report end-date="11/22/2005" name="My Report" start-date="12/31/1969"/>
<totals class-avg="0.0" stud-avg="94.0"/>
</data>
I have an XSD schema to which this document should conform to. I am
using sax parser to validate the document as follows:
--
This message has been scanned for viruses and
dangerous content by *MailScanner* <http://www.mailscanner.info/>, and is
believed to be clean.
If you have questions about this email,
Please contact the IT Help Desk.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]