Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

xml schema validation (JAXP 1.3 JDK 1.4.2)

Thread view: 
tremalnaik@gmail.com - 28 Oct 2005 09:26 GMT
Hello,
I'm trying to validate the xml string which root follows:

<ScenarioResponse
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="Scenari
oResponse.xsd
">
..............
</ScenarioResponse>

with the schema file ScenarioResponse.xsd:

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"elementFormDefault="qualified">
.......
</xs:schema>

My code:

private void validate(String schemaPath, String xml) throws
SAXException,
           ParserConfigurationException, IOException
   {
       // parse document
       DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
       DocumentBuilder db = dbf.newDocumentBuilder();
       Document doc = db.parse(new InputSource(new
StringReader(xml)));
       // create schema
       SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
       sf.setErrorHandler(new myErrorHandler());
       InputStream iStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream(schemaPath);
       StreamSource ss = new StreamSource(iStream);
       Schema schema = sf.newSchema(ss);
       // validate
       Validator validator = schema.newValidator();
       validator.setErrorHandler(new myErrorHandler());
       validator.validate(source);
   }

executing the last instruction I get

org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute
'xsi:noNamespaceSchemaLocation' is not allowed to appear in element
'ScenarioResponse'.

I try to use another instance of the SchemaFactory so I try the
following:

SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);

the result is:

2005-10-27 16:17:17,932 [http-0.0.0.0-8080-1] ERROR [ROM] [THREAD: 1]
java.lang.IllegalArgumentException:
http://www.w3.org/2001/XMLSchema-instance
       at
javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:181)

so I suppose an instance for this schema is not implemented.

Can someone give me a direction, please?

TREMALNAIK
Roedy Green - 31 Oct 2005 10:58 GMT
>I'm trying to validate the xml string which root follows:

see http://mindprod.com/jgloss/xsd.html
for code to do that.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

tremalnaik@gmail.com - 31 Oct 2005 11:50 GMT
> see http://mindprod.com/jgloss/xsd.html
> for code to do that.

thanks Roedy, but now I have the proof that my code is correct
(probabily).

First, I upgraded to sdk 1.5.0 and the problem was still there.

But the same snipplet of code, if run from a raw console, behaves
properly. When I use it from inside a web application (deployed into
jboss) I get the exception.

So I think I have a classpath problem, with old classes hiding the new
shipped with the latest JAXP/JDK

I have to figure out this.

Thanks

TREMALNAIK
Roedy Green - 01 Nov 2005 08:17 GMT
>I have to figure out this.

Have a look it my little Where tool to find out where classes are
coming from.

See http://mindprod.com/jgloss/where.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

tremalnaik@gmail.com - 02 Nov 2005 10:32 GMT
> See http://mindprod.com/jgloss/where.html

thanks, Roedy. I tried the JVM -verbose option also. It prints out to
console the location of loaded classes.

cheers,
TREMALNAIK


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.