wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes from jaxp program how to get schema/dtd name present in xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "from jaxp program how to get schema/dtd name present in xml" Watch "from jaxp program how to get schema/dtd name present in xml" New topic
Author

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

anish reddy
Ranch Hand

Joined: Apr 19, 2008
Posts: 74
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

Joined: Sep 29, 2008
Posts: 12617

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.
 
 
subject: from jaxp program how to get schema/dtd name present in xml
 
Similar Threads
help "Error parsing XML document: null"
multiple validation errors in xml for given xsd with java
'reading' an xml document - what am i doing wrong?
reg xml validation when i pass xml and the schema that is not used in xml
package problem