• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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.
 
expectation is the root of all heartache - shakespeare. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic