You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Christian Nelson <cn...@slac.com> on 2003/04/18 04:11:43 UTC

Assigning a schema to an in-memory DOM Document

Xercesites,

I've written a Java application that uses XML as a load/save format. To do
this, I create a DOM in memory and serialize it out to a file.  This works
great.  Now, what I'd like to do is specify what schema it's supposed to
adhere to.  Basically, I want to get this line to happen:

<manufacturer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.some.biz/schemas/manufacturer.xsd">

Instead of this:

<manufacturer>

What API call(s) need(s) to be made to make this happen, and at what point
in the process of building the Document should I associate it with the
schema (before I start added nodes, after it's all assembled)?

NOTE: I can get what seems the desired effect by making these calls:

doc.getDocumentElement().setAttribute(
    "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");

doc.getDocumentElement().setAttribute(
    "xsi:noNamespaceSchemaLocation",
    "http://www.some.biz/schemas/manufacturer.xsd");

But is that the best way?  I guess I'm asking: is there a way to have
the Document know what schema it's supposed to adhere to and make sure
you're building a document that complies?

Thanks again!
Christian

---------------------------------------------------------------------------
 Christian 'xian' Nelson                                  cnelson@slac.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "Don't ask yourself what the world needs.  Ask yourself what makes
  you come alive, and go do that, because what the world needs is people
                  who have come alive." -- Howard Thurman
---------------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org