Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [xsd-dev] "xmlns" in the <schema> element

Pae,

This isn't a valid schema:

   <?xml version="1.0" encoding="UTF-8"?>
   <schema/>

You minimally need to choose the schema for schema namespace

   xmlSchema.getQNamePrefixToNamespaceMap().put(null,
   XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);

Which would give this minimally correct result:

   <?xml version="1.0" encoding="UTF-8"?>
   <schema xmlns="http://www.w3.org/2001/XMLSchema"/>

Such a schema will need to have a target namespace because the null target
namespace won't be accessible (because the null prefix is used up) so it's
usually best to choose a prefix for the schema for schema namespace:

   xmlSchema.setSchemaForSchemaQNamePrefix("xsd");
   xmlSchema.getQNamePrefixToNamespaceMap().put("xsd",
   XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);

Which would give this result:

   <?xml version="1.0" encoding="UTF-8"?>
   <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>

PS, these kinds of questions are better to be asked on the forum so that
new users will benefit from the answers.


Ed Merks/Toronto/IBM@IBMCA
mailto: merks@xxxxxxxxxx
905-413-3265  (t/l 969)




                                                                                                                                                  
                      "Pae Choi"                                                                                                                  
                      <paechoi@earthlin        To:       <xsd-dev@xxxxxxxxxxx>                                                                    
                      k.net>                   cc:                                                                                                
                      Sent by:                 Subject:  [xsd-dev] "xmlns" in the <schema> element                                                
                      xsd-dev-admin@ecl                                                                                                           
                      ipse.org                                                                                                                    
                                                                                                                                                  
                                                                                                                                                  
                      02/28/2003 07:04                                                                                                            
                      AM                                                                                                                          
                      Please respond to                                                                                                           
                      xsd-dev                                                                                                                     
                                                                                                                                                  
                                                                                                                                                  



When I tried to create a schema that contains only the <schema> element
without any
attribute, I don't see how to do it at this moment. The following code
snippet shows the
schema as follows:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns=""/>

In the XSDSchemaImpl class, there is a method called,
getQNamePrefixToNamespaceMap(),
which returns java.util.Map. But it returns 0 for its size. How should I or
make a workaround
to produce the output as:

<?xml version="1.0" encoding="UTF-8"?>
<schema/>

Any comments?


Pae


// ####################### CODE SNIPPET #########################
public class XMLSchemaDemo {

    /** Save the schema */
    private void saveXMLSchema(XSDSchema xmlSchema, String
xmlSchemaURIToSave) {
        try {
            ResourceSet resourceSet = new ResourceSetImpl();
            Resource resource = new
XSDResourceImpl(URI.createDeviceURI(xmlSchemaURIToSave));
            resource.getContents().add(xmlSchema);
            resourceSet.getResources().add(resource);
            resource.save(Collections.EMPTY_MAP);
        } catch (Exception ex) {
            System.out.println(ex.getLocalizedMessage());
            ex.printStackTrace();
        }
    }

    /** doIt -- the initial method */
    private void doIt() {
        XSDSchema xmlSchema = XSDFactory.eINSTANCE.createXSDSchema();
        System.out.println("XML Schema: [\n" + xmlSchema + "]");
        saveXMLSchema(xmlSchema, "./test-xsd.xsd");
    }

    /** main - the main entry */
    public static void main(String[] args) {
        XMLSchemaDemo app = new XMLSchemaDemo ();
        app.doIt();
    }
}




Back to the top