Associating Document with XML Schema

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Big Bad Munda

    #1

    Associating Document with XML Schema

    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
  • Big Bad Munda

    #2
    Re: Associating Document with XML Schema

    Martin Honnen <Martin.Honnen@ t-online.de> wrote in message news:<3f4cc5d9$ 1@olaf.komtel.n et>...[color=blue]
    > Big Bad Munda wrote:
    >[color=green]
    > > 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>[/color]
    >
    > Create the document and then add the attributes e.g
    > domDocument.get DocumentElement ().setAttribute ("xmlns:xsi" ,
    > "http://www.w3.org/2001/XMLSchema-instance");
    > domDocument.get DocumentElement .setAttributeNS (
    > "http://www.w3.org/2001/XMLSchema-instance",
    > "xsi:noNamespac eSchemaLocation ",
    > "DomainDeviceQu eryResult.xsd"
    > );[/color]



    That was the missing piece to my puzzle. Thanks!

    Comment

    Working...