Hm. I have noticed something strange. When I am running the code with Sun JDK 1.5_6 everything works nicely. When switching to JDK 1.4.2_13 I am getting this error.
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'log'. at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source) at org.apache.xerces.jaxp.validation.DOMValidatorHelper.beginNode(Unknown Source) at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source) at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source) at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source) at javax.xml.validation.Validator.validate(Unknown Source) at XMLValidation.<init>(XMLValidation.java:52) at XMLValidation.main(XMLValidation.java:23) Exception in thread "main" In case of jdk 1.5 xerces is part of the jdk, right? So normally I should be able to just add xml-apis.jar and xercesImpl.jar to the classpath when using 1.4 and it should work, shouldn't it???? I am a bit confuesd.... Best reagards Bernd Kolb > -----Original Message----- > From: ddeneer [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 09, 2007 12:12 PM > To: j-users@xerces.apache.org > Subject: RE: Add schema to xmldocument > > > All your othe attrbutes enad elements will be still in the > nonamespace. Every element and attribute has also a namespace part. > > Bernd Kolb ([EMAIL PROTECTED]) wrote: > > > > > > Yes, that's true. > > > > Is it somehow possible to add > > > > xmlns="http://sample.com" > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > > > to an already parsed document? > > As I said, I tried to add these arguments to the documents root > > element, without success. > > > > Thanks again > > > > Regards > > > > Bernd Kolb > > > > > > > > > >> -----Original Message----- > >> From: Dick Deneer [mailto:[EMAIL PROTECTED] > >> Sent: Tuesday, January 09, 2007 8:19 AM > >> To: j-users@xerces.apache.org > >> Subject: Re: Add schema to xmldocument > >> > >> > >> Apparently your schema simple.xsd has a targetnamespace http:// > >> sample.com. > >> Your test.xml has no namespace decaration, so it is in the "null" > >> namespace and has to be validated against a schema thas als has a > >> "null" targetnamespace. > >> > >> Either you must remove the targetnamespace in your xsd or > you have to > >> add xmlns="http://sample.com" > >> xmlns:xsi="http://www.w3.org/2001/ > >> XMLSchema-instance" to your test.xml. > >> > >> > >> Regards > >> Dick Deneer > >> > >> > >> > >> Op 8-jan-2007, om 23:43 heeft Bernd Kolb (([EMAIL PROTECTED])) het volgende > >> geschreven: > >> > >> > Hi, > >> > > >> > I have a question: I am using xerces 2.9.0. > >> > > >> > I have a XML-Document witch was not created by me and I am > >> not able to > >> > load it from a file. I am getting the XML-Document Object. > >> > > >> > Now I want to validate this document against a schema. > >> > This schema might not be in the document. > >> > > >> > So I want to add the schema programmatically. > >> > > >> > How can I achieve this? > >> > > >> > > >> > Document doc = > >> > > DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new > >> > File("test.xml")); > >> > > >> > Schema schema = > >> > SchemaFactory.newInstance > >> > (XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new > >> > StreamSource("simpleSchema.xsd")); > >> > schema.newValidator().validate(new DOMSource(doc)); > >> > > >> > > >> > test.xml looks like this > >> > > >> > <?xml version="1.0" encoding="UTF-8"?> <persons age="0"> > >> > <name>name</name> > >> > <surname>surname</surname> > >> > </persons> > >> > > >> > But I'd like xerces to act as if it looked like the > following one: > >> > <?xml version="1.0" encoding="UTF-8"?> <persons age="0" > >> > xmlns="http://sample.com" > >> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > >> > xsi:schemaLocation="http://sample.com simpleSchema.xsd "> > >> > <name>name</name> > >> > <surname>surname</surname> > >> > </persons> > >> > > >> > I tried to add the xmlns, xmlns:xsi and xsi:schemaLocation > >> attributes > >> > to the root element by code, without success... > >> > > >> > > >> > Any idea? > >> > > >> > Thanks a lot! > >> > > >> > > >> > Best wishes > >> > > >> > Bernd Kolb > >> > > >> > > >> > > >> > --------------------------------------------------------------------- > >> > To unsubscribe, e-mail: [EMAIL PROTECTED] > >> > For additional commands, e-mail: [EMAIL PROTECTED] > >> > > >> > > >> > > >> > >> > >> > --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > >> For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > -- > View this message in context: > http://www.nabble.com/Add-schema-to-xmldocument-tf2942623.html #a8235691 > Sent from the Xerces - J - Users mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]