You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Krishna Gopal Binyala <kg...@gmail.com> on 2009/01/06 09:41:01 UTC

Problem with schema validation with multiple xsds

Hello,

I am using xerces 2.9.1, for schema validation. I want to validate
multiple xsds for validation.
Actually if namespaces are same in xsds, it is taking only first xsd
from the array, if multiple xsds are existing with same namespace
in array.


I doubt on the the schema language is used here is creating problem.


here is my code... any clue how I can resolve this. ???

--- Parent XSD -- OutputMessage.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:bons0="http://VisualizationServicePublicLIB/bo"
targetNamespace="http://VisualizationServicePublicLIB/bo">

    <xsd:element name="out" type="bons0:OutputMessage" ></xsd:element>
         <xsd:complexType name="OutputMessage">
    <xsd:sequence>
      <xsd:element minOccurs="1" name="status" type="xsd:string"/>
      <xsd:element minOccurs="0" name="file" type="bons0:File"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>


--- Child XSD - File.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://VisualizationServicePublicLIB/bo">

  <xsd:complexType name="File">
    <xsd:sequence>
      <xsd:element minOccurs="1" name="type" type="xsd:string"/>
      <xsd:element minOccurs="1" name="content" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>


---xml file for validation  --- xmlFile.xml

<?xml version="1.0" encoding="UTF-8"?>
<bons0:out xmlns:bons0="http://VisualizationServicePublicLIB/bo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <status>status</status>
  <file>
    <type>type</type>
    <content>content</content>
  </file>

</bons0:out>



Code for validation --


public static void {

		try {
			SchemaFactory factory = SchemaFactory
					.newInstance("http://www.w3.org/2001/XMLSchema");
			Source[] xsdAray = new Source[2];		
			xsdAray[1]= new StreamSource("./File.xsd");
			xsdAray[0]= new StreamSource("./OutputMessage_new.xsd");
			
			
			Schema schema = factory.newSchema(xsdAray);
			
			
			Validator validator = schema.newValidator();
			
//this xml file contain valid xml source
			Source source = new StreamSource("./xmlFile.xml");
			
			validator.validate(source);

			System.out.println(" xml is valid.");
		} catch (SAXException ex) {

			System.out.println(" xml is not valid ");
			System.out.println(ex.getMessage());
			ex.printStackTrace();
		} catch (IOException e) {

			e.printStackTrace();
		} catch (Exception e1) {
			e1.printStackTrace();
		}
	
}

If i am giving <xsd:include schemaLocation="File.xsd" /> in Output.xsd then
its working fine



---Krishna binyala

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Problem with schema validation with multiple xsds

Posted by Krishna Gopal Binyala <kg...@gmail.com>.
Hello Mukul,

You are correct, if i will give one parent schema; it works.
But my requirement is such that i had to give Array of schemas and i
want to remove schemaLocation atttribute from the parent xsd file

Any clue for achieve this.... ???

Regards,
---Krishna


On Tue, Jan 6, 2009 at 2:34 PM, Mukul Gandhi <ga...@gmail.com> wrote:
> On Tue, Jan 6, 2009 at 2:11 PM, Krishna Gopal Binyala
> <kg...@gmail.com> wrote:
>> If i am giving <xsd:include schemaLocation="File.xsd" /> in Output.xsd then
>> its working fine
>
> I think this would be the correct solution. As one of your schema is
> using the type definitions defined in the other schema.
>
> Also, you don't need to create an array of Schema documents. Only one
> Schema will work fine in this case (which includes the child schema).
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Problem with schema validation with multiple xsds

Posted by Mukul Gandhi <ga...@gmail.com>.
On Tue, Jan 6, 2009 at 2:11 PM, Krishna Gopal Binyala
<kg...@gmail.com> wrote:
> If i am giving <xsd:include schemaLocation="File.xsd" /> in Output.xsd then
> its working fine

I think this would be the correct solution. As one of your schema is
using the type definitions defined in the other schema.

Also, you don't need to create an array of Schema documents. Only one
Schema will work fine in this case (which includes the child schema).


-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org