• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic