[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.m2m] QVT XSD

Hi,

1. QVT -

Executing the following .qvto :

   modeltype INTEROP uses "http://ms.com/interop";;
   modeltype XSD uses "http://www.eclipse.org/xsd/2002/XSD";;

transformation interop2xsd(in interop: INTEROP , out XSD);

main(in interopModel: INTEROP::InteropSchema, out xsd: XSD::XSDSchema) {
xsd:= interopModel.map interop2Xsd();
}


   mapping INTEROP::InteropSchema::interop2Xsd() : XSD::XSDSchema {
	targetNamespace := 'DUMMY';
   }

with OUT target file specifies as <something>.xsd, produces:

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

which does not look like a valid xsd schema root element.

2. Java-

On the other hand, running the following Java code:

   class Schema {

private XSDFactory _xsdFactory;
private XSDSchema _schema;
private ByteArrayOutputStream _outputStream = new ByteArrayOutputStream();

private Schema() {
_xsdFactory = XSDFactory.eINSTANCE;
initSchema();
}
private void initSchema() {
_schema = _xsdFactory.createXSDSchema();
_schema.setTargetNamespace("DUMMY");

_schema.setSchemaForSchemaQNamePrefix("xsd");
Map<String, String> qNamePrefixToNamespaceMap =_schema.getQNamePrefixToNamespaceMap();
qNamePrefixToNamespaceMap.put("tns", _schema.getTargetNamespace());
qNamePrefixToNamespaceMap.put(_schema.getSchemaForSchemaQNamePrefix(), XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);

_schema.updateElement();

}
private String serialize() {
XSDResourceImpl.serialize(_outputStream, _schema.getDocument());
return _outputStream.toString();
}

public static void main(String [ ] args) {
Schema schema = new Schema();
System.out.println(schema.serialize());
}
}


produces, in stdout:

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


which looks like a valid xsd schema document root.


3. Question: how would one achieve the equivalence of 2. above,
with a QVT transform? I.e., how would one re-write the .qvto in 1. to get the output produced in 2. ?



Thanks.

-Min