Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validating XML against an XSD string

Status
Not open for further replies.

varocho

Programmer
Dec 4, 2000
238
US
I'm not sure if I'm posting in the right forum, so if not, I apologize in advance.

I'm using the 'SAXParser' class to validate an XML file against an XSD file. To specify the full path and name of the XSD file, I use the 'setProperty()' method. What I need to find out is how to specify the XSD as an XML String (the String is generated at run-time, and I want to avoid creating a file on the server). Is this possible?
 
Here is an excerpt from the XML tutorials at java.sun.com which is where you should always look first for any information related to Java programming. This shows one way to associate a schema file with a validating parser.
Code:
static final String JAXP_SCHEMA_SOURCE =
    "[URL unfurl="true"]http://java.sun.com/xml/jaxp/properties/schemaSource";[/URL]

...
SAXParser saxParser = spf.newSAXParser();
...
saxParser.setProperty(JAXP_SCHEMA_SOURCE,
    new File(schemaSource));

Here is the link to the page:
-pete
 
Pete,

Thanks for responding, but I already how to specify an XSD file for validation. What I'd like to know is if it's possible to specify the XSD as an XML string; in other words, no actual XSD file exists, the XML file is validated against the string.
 
>> no actual XSD file exists

But the XML does exist? That's like putting the cart before the horse isn't it?

-pete
 
>But the XML does exist? That's like putting the cart before the horse isn't it?<

Lol...well, the XSD is being generated on-the-fly, from several database records. I'm just trying to avoid creating files on the server.
 
saxParser.setProperty(JAXP_SCHEMA_SOURCE,
new File(schemaSource));


Since the second parameter is an Object and even in the example from Sun they use a java.io.File object, isn't it possible to turn your String into an InputStream or StreamReader object and send that as the second parameter? Or perhapes even one of the SAX Input Stream objects? Maybe you already tried this and it doesn't work.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top