Hi, thanks (Dick Deneer too) for the answer, I finally solved the problem by adding the complete (not relative) XSD file URI in the XML file.
2007/2/22, Dick Deneer <[EMAIL PROTECTED]>:
Pau, When you are using the InputSoure, you have to set the SystemId on the inputSource which will be used hen resolving relative URI's. Since you are using a relative schemaLocation, hotelres.xsd. If you do not set the systemId, xerces will use the java workdir to resolve locations. I guess that in your working example, the xsd was in the same place as the xml instance. Hope this helps, Dick Deneer Op 22-feb-2007, om 10:55 heeft pau carre het volgende geschreven: > Hi, I am developing a WebServices server and I want to use Xerces to > validate XML instances that clients send me with SOAP messages. > > First, I tried a simple example to validate an XML instance contained > in a file and then validate it with an XSD Schema (i.e. using URIs), > and It worked perfectly. > Code: > parser.setFeature("http://xml.org/sax/features/validation", true); > parser.setFeature("http://apache.org/xml/features/validation/ > schema", true); > parser.setFeature( "http://apache.org/xml/features/validation/ > schema-full-checking",true); > parser.setProperty( "http://apache.org/xml/properties/schema/ > external-schemaLocation", SchemaURI); > parser.setFeature("http://apache.org/xml/features/nonvalidating/ > load-external-dtd",true); > Validator handler = new Validator(); > parser.setErrorHandler(handler); > parser.parse(XMLDocumentUri); > > The problem is that then I tried to validate an string containing an > XML document, which is the method I want to use, Xerces throws this > SAXParseException: cvc-elt.1: Cannot find the declaration of element > 'tns:contract'. > Code: > // the same configuration stuff above written changing the parse > call for: > parser.parse(new InputSource(new StringReader(StringXmlDocument))); > > Then I tried to write an empty XML file with the StringXmlDocument > content and validate it with its URI, and it worked! > > But, so as not to have problems with deployment I would like to parse > directly the string XML instance... > > I have used unsuccessfully two different versions of Xerces: 2.6.2 > and 2.9.0 > > The String XML declaration looks like: > String StringXmlDocument = > "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + > "<tns:contract currency=\"\" id=\"\" messageVersion=\"1.0\" > providerID=\"\" title=\"\" xmlns:tns=\"http://globalip:8080/hotelres\" > xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" > xsi:schemaLocation=\"http://globalip:8080/hotelres hotelres.xsd \">\n" > + "<tns:hotel id=\"\" name=\"\"/>\n" > + "<tns:roomtypes>\n" > + "<tns:roomtype code=\"\" maxpaxes=\"0\" > minChildren=\"0\" minadults=\"0\" minpaxes=\"0\"/>\n" > + "</tns:roomtypes>\n" > + "<tns:paxtypes>\n" > .... > > > > The XML instance used is the same as the string one. > > The XML Schema (XSD file) looks like: > <schema xmlns="http://www.w3.org/2001/XMLSchema" > targetNamespace="http://globalip:8080/hotelres" > xmlns:tns="http://globalip:8080/hotelres" > elementFormDefault="qualified"> > <element name="contract"> > <complexType> > <sequence> > <element name="hotel" type="tns:hotelType"> > <annotation> > <documentation> > Definición del hotel para el cual es el > contrato. > </documentation> > </annotation> > </element> > > .... > > > > Any idea? > Thanks in advance, > Pau > > --------------------------------------------------------------------- > 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]