Associating Document with XML Schema

B

Big Bad Munda

Hello,

I am trying to create an XML document using JAXP. I want to associate
it with a *.xsd file. How do I do that? I know if I wanted to
specify a DTD I would do something like this:

DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setValidating(true);
DocumentBuilder builder = factory.newDocumentBuilder();

// Create DTD definition
DOMImplementation domImpl = builder.getDOMImplementation();
DocumentType docType = domImpl.createDocumentType("DeviceQuery",
null, "dtd/ToolsDeviceQueryInfo.dtd");
Document toolsDoc = domImpl.createDocument(null, "DeviceQuery",
docType);

But what is the corresponding code to associate it with an .xsd file.
I have been unable to find any documentation on this.

The following is what I want the end result to look like:

<?xml version="1.0" encoding="UTF-8" ?>
<DeviceQuery
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation="DomainDeviceQueryResult.xsd">
<RequesterInfo>
<DQKey>12345</DQKey>
<Server>localhost:7001</Server>
</RequesterInfo>
</DeviceQuery>

Any help would be much appreciated!

Ashish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top