Thanks for the responses. Some clarification about my problem. I have the schema, but no instance documents, and hence no worries about the fluid nature of prefixes between schema and instance documents. My current task is to generate a "starter" document from the schema. What I would like to do is use the prefix values from the schema in my instance document, under the assumption that the person that wrote the schema found the prefix to be a good mnemonic, and hence it would serve the same purpose in the instance document. If I had the prefix, it appears that I could then use
Element elem = CoreDocumentImpl.createElementNS(namespace, name); elem.setPrefix(prefix); to create the element in the given namespace and set the prefix to be associated with that namespace (for that element). Doing this, I hope to generate an instance document that has <s1:elementOne xmlns:s2="http://www.foo.com/SchemaTwo" ...> <s2:elementTwo ... /> instead of having elementTwo defined with <elementTwo xmlns="http://www.foo.com/SchemaTwo" ... /> From what Michael says, it appears I can't get the prefix information from XSModel. From his phrase "not sure what it would mean to return such a list", it seems I am missing something fundamental about why this wouldn't be considered useful information. The list would simply be a default association of prefix with namespace. It would be useful for my purpose, but useless for processing any existing document. Is there some reason that what I want to do is a bad idea? Thanks - Mark On Oct 21, 2010, at 12:30 PM, Michael Glavassevich wrote: > Hi Mark, > > Mark Brucks <bru...@charter.net> wrote on 10/21/2010 03:17:47 PM: > > > Here is the beginning of my schema file: > > > > <xs:schema targetNamespace="http://www.foo.com/SchemaOne" > > xmlns:s1="http://www.foo.com/SchemaOne" > > xmlns:s2="http://www.foo.com/SchemaTwo" > > xmlns:s3="http://www.foo.com/SchemaThree" > > ...> > > > > Using the XML Schema API, I parse the schema and have access to the > > resulting XSModel instance. Using the method getNamespaceItems() I > > can get a list of XSNamespaceItem and using the getSchemaNamespace() > > method I can get all the namespaces. > > You're getting the list of all the target namespaces for the schema > components in the XSModel. This has nothing to do with the namespace > declarations which may have been in the schema documents. > > > How do I get the associated prefix for each prefix? > > You can't and not sure what it would mean to return such a list. The XSModel > is a schema component view. There is no way to access the schema documents > which composed it. > > > Thanks - Mark > > Thanks. > > Michael Glavassevich > XML Parser Development > IBM Toronto Lab > E-mail: mrgla...@ca.ibm.com > E-mail: mrgla...@apache.org >