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:
DocumentBuilder Factory factory =
DocumentBuilder Factory.newInst ance();
factory.setVali dating(true);
DocumentBuilder builder = factory.newDocu mentBuilder();
// Create DTD definition
DOMImplementati on domImpl = builder.getDOMI mplementation() ;
DocumentType docType = domImpl.createD ocumentType("De viceQuery",
null, "dtd/ToolsDeviceQuer yInfo.dtd");
Document toolsDoc = domImpl.createD ocument(null, "DeviceQuer y",
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:noNamespace SchemaLocation= "DomainDeviceQu eryResult.xsd">
<RequesterInf o>
<DQKey>12345</DQKey>
<Server>localho st:7001</Server>
</RequesterInfo>
</DeviceQuery>
Any help would be much appreciated!
Ashish
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:
DocumentBuilder Factory factory =
DocumentBuilder Factory.newInst ance();
factory.setVali dating(true);
DocumentBuilder builder = factory.newDocu mentBuilder();
// Create DTD definition
DOMImplementati on domImpl = builder.getDOMI mplementation() ;
DocumentType docType = domImpl.createD ocumentType("De viceQuery",
null, "dtd/ToolsDeviceQuer yInfo.dtd");
Document toolsDoc = domImpl.createD ocument(null, "DeviceQuer y",
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:noNamespace SchemaLocation= "DomainDeviceQu eryResult.xsd">
<RequesterInf o>
<DQKey>12345</DQKey>
<Server>localho st:7001</Server>
</RequesterInfo>
</DeviceQuery>
Any help would be much appreciated!
Ashish
Comment