Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

from jaxp program how to get schema/dtd name present in xml

 
anish reddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am validating an xml according to schema present in it. i pass xml and schema to the


public boolean validation(String pFileXmlOne, String... pSchemaNames)throws SAXException,IOException ,Exception
{
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Source[] lStreamSources = null;
Schema schema = null;
Validator validator = null;
Source source = new StreamSource(pFileXmlOne);
try {
lStreamSources = getStreamSource(pSchemaNames);
schema = factory.newSchema(lStreamSources);
validator = schema.newValidator();
validator.validate(source);
} catch (SAXException e) {
throw new SAXException(e.getMessage());
} catch (IOException e) {
throw new IOException(e.getMessage());
} catch (Exception e) {
throw new Exception(e.getMessage());
}

return true;
}


i am able to validate xml according to schema i pass.

but when i pass xml and schema not in xml.still it is validating instead of exception that schema could not be found.

can any one give inputs/ideas to get schema/dtd name of an xml dynamically.so that i can compare with schema name i pass and do validation accordingly if matches.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic