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(); } }
|