Create XSD programmatically [message #509060] |
Thu, 21 January 2010 10:05 |
ronald Mising name Messages: 52 Registered: July 2009 |
Member |
|
|
Hi all,
I'm having serious trouble in creating an XSD in code. Here's what I think the output should be:
(File to create)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/case"
xmlns:import="http://www.example.com/import"
elementFormDefault="qualified" >
<xsd:import schemaLocation="import.xsd" namespace="http://www.example.com/import" />
<xsd:complexType name="A__Type">
<xsd:sequence>
<xsd:element name="amount" type="import:currency" />
<xsd:element name="file" type="B__Type" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="B_Type"> ..... </xsd:element>
</xsd:schema>
The import.xsd is an xsd with some default/standard types that may be used/referenced in the xsd above. It's not created programmatically and it already exists when creating the xsd above. It contains among others a currency type definion, as in
(File to import)
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/import"
elementFormDefault="qualified">
<xsd:complexType name="currency">
<xsd:simpleContent>
....
<xsd:simpleContent>
</xsd:schema>
The code I use to create the blank XSDSchema is
XSDFactory xsdFactory = XSDFactory.eINSTANCE;
XSDSchema blankSchema = XSDSchemaBuildingTools.getBlankSchema(xsdFactory, null, null, null, null);
blankSchema.getSchemaForSchema().setTargetNamespace("http://www.example.com/case");
XSDImport xsdImport = xsdFactory.createXSDImport();
xsdImport.setSchemaLocation("import.xsd");
xsdImport.setNamespace("http://www.example.com/import");
blankSchema.getContents().add(xsdImport);
return blankSchema;
I'm sure I'm missing a lot, but I've looked through a lot of posts and I'm getting nowhere. It should be possible to create an XSD from scratch, but while trying I got some Q1 and Q2 prefixes,
but I didn't find a way to name these prefixes myself...
Am I missing something? I'm using XSD 2.4.0.
Any ideas are more than welcome
Ronaldo
|
|
|
Re: Create XSD programmatically [message #509107 is a reply to message #509060] |
Thu, 21 January 2010 11:52 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
Ronald,
Comments below.
ronald wrote:
> Hi all,
>
> I'm having serious trouble in creating an XSD in code. Here's what I
> think the output should be:
>
> (File to create)
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.example.com/case"
> xmlns:import="http://www.example.com/import"
> elementFormDefault="qualified" >
> <xsd:import schemaLocation="import.xsd"
> namespace="http://www.example.com/import" />
> <xsd:complexType name="A__Type">
> <xsd:sequence>
> <xsd:element name="amount" type="import:currency" />
> <xsd:element name="file" type="B__Type" />
> </xsd:sequence>
> </xsd:complexType>
> <xsd:element name="B_Type"> ..... </xsd:element>
> </xsd:schema>
>
> The import.xsd is an xsd with some default/standard types that may be
> used/referenced in the xsd above. It's not created programmatically
> and it already exists when creating the xsd above. It contains among
> others a currency type definion, as in
>
> (File to import)
> <?xml version="1.0" encoding="utf-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.example.com/import"
> elementFormDefault="qualified">
>
> <xsd:complexType name="currency">
> <xsd:simpleContent>
> ....
> <xsd:simpleContent>
> </xsd:schema>
>
>
> The code I use to create the blank XSDSchema is
>
> XSDFactory xsdFactory = XSDFactory.eINSTANCE;
> XSDSchema blankSchema =
> XSDSchemaBuildingTools.getBlankSchema(xsdFactory, null, null, null,
> null);
> blankSchema.getSchemaForSchema().setTargetNamespace("http://www.example.com/case");
>
This can't be good. The schema for schemas shouldn't ever be modified.
I'm sure all hell will break loose. I assume you're trying to set the
target namespace of blankSchema itself.
>
> XSDImport xsdImport = xsdFactory.createXSDImport();
> xsdImport.setSchemaLocation("import.xsd");
> xsdImport.setNamespace("http://www.example.com/import");
> blankSchema.getContents().add(xsdImport);
>
> return blankSchema;
>
> I'm sure I'm missing a lot, but I've looked through a lot of posts and
> I'm getting nowhere. It should be possible to create an XSD from
> scratch, but while trying I got some Q1 and Q2 prefixes,
> but I didn't find a way to name these prefixes myself...
>
> Am I missing something? I'm using XSD 2.4.0.
Have a look at XSDPrototypicalSchema; it's got examples for how to
create pretty much anything.
>
> Any ideas are more than welcome :)
>
> Ronaldo
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03099 seconds