Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Problem with transferring a type definition between two schemas
Problem with transferring a type definition between two schemas [message #41498] Fri, 16 April 2004 11:11 Go to next message
Joachim Lusiardi is currently offline Joachim LusiardiFriend
Messages: 18
Registered: July 2009
Junior Member
Hi!
My problem is the following:
I have one larger XSD Schema looking like the following:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="Name" type="MyComplexType" />

<xs:complexType name="MyComplexType">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="vorname">
<xs:simpleType >
<xs:restriction base="xs:string">
<xs:minLength value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="nachname" type="xs:string" />
</xs:sequence>
<xs:attribute name="Geburtstag" type="xs:date" />
</xs:complexType>

</xs:schema>

and i want to transform it into something like this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="Name" type="MyComplexType" />

<xs:complexType name="MyComplexType">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="vorname">
<xs:simpleType >
<xs:restriction base="xs:string">
<xs:minLength value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="nachname" type="xs:string" />
</xs:sequence>
<xs:attribute name="Geburtstag" type="xs:date" />
</xs:complexType>

<xs:element name="NameTest">
<xs:simpleType >
<xs:restriction base="xs:string">
<xs:minLength value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>

this would enable me to create XML instance files with NameTest as root
element.

An now the big question:
Lets asume i have the XSDSimpleTypeDefiniton of the anonymous type
inside the embeded "vorname" element. How can a transfer this to an
newly created XSDELementDeclaration?

I tried the following code:

XSDSimpleTypeDefinition std = getSimpleTypeFromOldSchema();
XSDElementDeclaration elemDecl =
xsdFactory.createXSDElementDeclaration();
elemDecl.setName("NameTest");
newSchema.getContents().add(elemDecl);
elemDecl.setTypeDefinition(std);

this produces an element declaration in the new schema that looks like this:

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

So what can i do to achieve what i want to have?

thanks for your answers.
greets Joachim Lusiardi
Re: Problem with transferring a type definition between two schemas [message #41528 is a reply to message #41498] Fri, 16 April 2004 11:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

--------------65B7F0FFEBF87274A9D96A67
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Joachim,

For this particular scenario, the following should work:

elemDecl.setAnonymousTypeDefinition((XSDSimpleTypeDefinition )std.cloneConcreteComponent(true,
false));

Joachim Lusiardi wrote:

> Hi!
> My problem is the following:
> I have one larger XSD Schema looking like the following:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
> <xs:element name="Name" type="MyComplexType" />
>
> <xs:complexType name="MyComplexType">
> <xs:sequence minOccurs="1" maxOccurs="1">
> <xs:element name="vorname">
> <xs:simpleType >
> <xs:restriction base="xs:string">
> <xs:minLength value="4"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:element>
> <xs:element name="nachname" type="xs:string" />
> </xs:sequence>
> <xs:attribute name="Geburtstag" type="xs:date" />
> </xs:complexType>
>
> </xs:schema>
>
> and i want to transform it into something like this:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
> <xs:element name="Name" type="MyComplexType" />
>
> <xs:complexType name="MyComplexType">
> <xs:sequence minOccurs="1" maxOccurs="1">
> <xs:element name="vorname">
> <xs:simpleType >
> <xs:restriction base="xs:string">
> <xs:minLength value="4"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:element>
> <xs:element name="nachname" type="xs:string" />
> </xs:sequence>
> <xs:attribute name="Geburtstag" type="xs:date" />
> </xs:complexType>
>
> <xs:element name="NameTest">
> <xs:simpleType >
> <xs:restriction base="xs:string">
> <xs:minLength value="4"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:element>
> </xs:schema>
>
> this would enable me to create XML instance files with NameTest as root
> element.
>
> An now the big question:
> Lets asume i have the XSDSimpleTypeDefiniton of the anonymous type
> inside the embeded "vorname" element. How can a transfer this to an
> newly created XSDELementDeclaration?
>
> I tried the following code:
>
> XSDSimpleTypeDefinition std = getSimpleTypeFromOldSchema();
> XSDElementDeclaration elemDecl =
> xsdFactory.createXSDElementDeclaration();
> elemDecl.setName("NameTest");
> newSchema.getContents().add(elemDecl);
> elemDecl.setTypeDefinition(std);
>
> this produces an element declaration in the new schema that looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:element name="test1" type="vorname_._type"/>
> </xsd:schema>
>
> So what can i do to achieve what i want to have?
>
> thanks for your answers.
> greets Joachim Lusiardi

--------------65B7F0FFEBF87274A9D96A67
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Joachim,
<p>For this particular scenario, the following should work:
<blockquote> elemDecl.setAnonymousTypeDefinition((XSDSimpleTypeDefinition )std.cloneConcreteComponent(true,
false));</blockquote>

<p><br>Joachim Lusiardi wrote:
<blockquote TYPE=CITE>Hi!
<br>My problem is the following:
<br>I have one larger XSD Schema looking like the following:
<p>&lt;xs:schema xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>"
>
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element name="Name" type="MyComplexType"
/>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:complexType name="MyComplexType">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:sequence minOccurs="1"
maxOccurs="1">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element name="vorname">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;xs:simpleType >
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:restriction base="xs:string">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:minLength value="4"/>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:restriction>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;/xs:simpleType>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:element>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element name="nachname" type="xs:string" />
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xs:sequence>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:attribute name="Geburtstag"
type="xs:date" />
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:complexType>
<p>&lt;/xs:schema>
<p>and i want to transform it into something like this:
<p>&lt;xs:schema xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>"
>
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element name="Name" type="MyComplexType"
/>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:complexType name="MyComplexType">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:sequence minOccurs="1"
maxOccurs="1">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element name="vorname">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;xs:simpleType >
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:restriction base="xs:string">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:minLength value="4"/>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:restriction>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;/xs:simpleType>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:element>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element name="nachname" type="xs:string" />
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xs:sequence>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:attribute name="Geburtstag"
type="xs:date" />
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:complexType>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element name="NameTest">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:simpleType >
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:restriction
base="xs:string">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;xs:minLength value="4"/>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:restriction>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xs:simpleType>
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:element>
<br>&lt;/xs:schema>
<p>this would enable me to create XML instance files with NameTest as root
<br>element.
<p>An now the big question:
<br>Lets asume i have the XSDSimpleTypeDefiniton of the anonymous type
<br>inside the embeded "vorname" element. How can a transfer this to an
<br>newly created XSDELementDeclaration?
<p>I tried the following code:
<p>XSDSimpleTypeDefinition std = getSimpleTypeFromOldSchema();
<br>XSDElementDeclaration elemDecl =
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
xsdFactory.createXSDElementDeclaration();
<br>elemDecl.setName("NameTest");
<br>newSchema.getContents().add(elemDecl);
<br>elemDecl.setTypeDefinition(std);
<p>this produces an element declaration in the new schema that looks like
this:
<p>&lt;?xml version="1.0" encoding="UTF-8"?>
<br>&lt;xsd:schema xmlns:xsd="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>">
<br>&lt;xsd:element name="test1" type="vorname_._type"/>
<br>&lt;/xsd:schema>
<p>So what can i do to achieve what i want to have?
<p>thanks for your answers.
<br>greets Joachim Lusiardi</blockquote>
</html>

--------------65B7F0FFEBF87274A9D96A67--
Re: Problem with transferring a type definition between two schemas [message #41552 is a reply to message #41528] Fri, 16 April 2004 11:55 Go to previous message
Joachim Lusiardi is currently offline Joachim LusiardiFriend
Messages: 18
Registered: July 2009
Junior Member
Hi,
Thanks for your quick answer. Your code works perfectly. You saved me a
lot of time.
greets
Joachim Lusiardi

Ed Merks wrote:
> Joachim,
>
> For this particular scenario, the following should work:
>
> elemDecl.setAnonymousTypeDefinition((XSDSimpleTypeDefinition )std.cloneConcreteComponent(true,
> false));
>
>
> Joachim Lusiardi wrote:
>
>> Hi!
>> My problem is the following:
>> I have one larger XSD Schema looking like the following:
>>
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
>> <xs:element name="Name" type="MyComplexType" />
>>
>> <xs:complexType name="MyComplexType">
>> <xs:sequence minOccurs="1" maxOccurs="1">
>> <xs:element name="vorname">
>> <xs:simpleType >
>> <xs:restriction base="xs:string">
>> <xs:minLength value="4"/>
>> </xs:restriction>
>> </xs:simpleType>
>> </xs:element>
>> <xs:element name="nachname" type="xs:string" />
>> </xs:sequence>
>> <xs:attribute name="Geburtstag" type="xs:date" />
>> </xs:complexType>
>>
>> </xs:schema>
>>
>> and i want to transform it into something like this:
>>
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
>> <xs:element name="Name" type="MyComplexType" />
>>
>> <xs:complexType name="MyComplexType">
>> <xs:sequence minOccurs="1" maxOccurs="1">
>> <xs:element name="vorname">
>> <xs:simpleType >
>> <xs:restriction base="xs:string">
>> <xs:minLength value="4"/>
>> </xs:restriction>
>> </xs:simpleType>
>> </xs:element>
>> <xs:element name="nachname" type="xs:string" />
>> </xs:sequence>
>> <xs:attribute name="Geburtstag" type="xs:date" />
>> </xs:complexType>
>>
>> <xs:element name="NameTest">
>> <xs:simpleType >
>> <xs:restriction base="xs:string">
>> <xs:minLength value="4"/>
>> </xs:restriction>
>> </xs:simpleType>
>> </xs:element>
>> </xs:schema>
>>
>> this would enable me to create XML instance files with NameTest as root
>> element.
>>
>> An now the big question:
>> Lets asume i have the XSDSimpleTypeDefiniton of the anonymous type
>> inside the embeded "vorname" element. How can a transfer this to an
>> newly created XSDELementDeclaration?
>>
>> I tried the following code:
>>
>> XSDSimpleTypeDefinition std = getSimpleTypeFromOldSchema();
>> XSDElementDeclaration elemDecl =
>> xsdFactory.createXSDElementDeclaration();
>> elemDecl.setName("NameTest");
>> newSchema.getContents().add(elemDecl);
>> elemDecl.setTypeDefinition(std);
>>
>> this produces an element declaration in the new schema that looks like
>> this:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>> <xsd:element name="test1" type="vorname_._type"/>
>> </xsd:schema>
>>
>> So what can i do to achieve what i want to have?
>>
>> thanks for your answers.
>> greets Joachim Lusiardi
>>
Re: Problem with transferring a type definition between two schemas [message #585662 is a reply to message #41498] Fri, 16 April 2004 11:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31557
Registered: July 2009
Senior Member
--------------65B7F0FFEBF87274A9D96A67
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Joachim,

For this particular scenario, the following should work:

elemDecl.setAnonymousTypeDefinition((XSDSimpleTypeDefinition )std.cloneConcreteComponent(true,
false));

Joachim Lusiardi wrote:

> Hi!
> My problem is the following:
> I have one larger XSD Schema looking like the following:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
> <xs:element name="Name" type="MyComplexType" />
>
> <xs:complexType name="MyComplexType">
> <xs:sequence minOccurs="1" maxOccurs="1">
> <xs:element name="vorname">
> <xs:simpleType >
> <xs:restriction base="xs:string">
> <xs:minLength value="4"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:element>
> <xs:element name="nachname" type="xs:string" />
> </xs:sequence>
> <xs:attribute name="Geburtstag" type="xs:date" />
> </xs:complexType>
>
> </xs:schema>
>
> and i want to transform it into something like this:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
> <xs:element name="Name" type="MyComplexType" />
>
> <xs:complexType name="MyComplexType">
> <xs:sequence minOccurs="1" maxOccurs="1">
> <xs:element name="vorname">
> <xs:simpleType >
> <xs:restriction base="xs:string">
> <xs:minLength value="4"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:element>
> <xs:element name="nachname" type="xs:string" />
> </xs:sequence>
> <xs:attribute name="Geburtstag" type="xs:date" />
> </xs:complexType>
>
> <xs:element name="NameTest">
> <xs:simpleType >
> <xs:restriction base="xs:string">
> <xs:minLength value="4"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:element>
> </xs:schema>
>
> this would enable me to create XML instance files with NameTest as root
> element.
>
> An now the big question:
> Lets asume i have the XSDSimpleTypeDefiniton of the anonymous type
> inside the embeded "vorname" element. How can a transfer this to an
> newly created XSDELementDeclaration?
>
> I tried the following code:
>
> XSDSimpleTypeDefinition std = getSimpleTypeFromOldSchema();
> XSDElementDeclaration elemDecl =
> xsdFactory.createXSDElementDeclaration();
> elemDecl.setName("NameTest");
> newSchema.getContents().add(elemDecl);
> elemDecl.setTypeDefinition(std);
>
> this produces an element declaration in the new schema that looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:element name="test1" type="vorname_._type"/>
> </xsd:schema>
>
> So what can i do to achieve what i want to have?
>
> thanks for your answers.
> greets Joachim Lusiardi

--------------65B7F0FFEBF87274A9D96A67
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Joachim,
<p>For this particular scenario, the following should work:
<blockquote> elemDecl.setAnonymousTypeDefinition((XSDSimpleTypeDefinition )std.cloneConcreteComponent(true,
false));</blockquote>

<p><br>Joachim Lusiardi wrote:
<blockquote TYPE=CITE>Hi!
<br>My problem is the following:
<br>I have one larger XSD Schema looking like the following:
<p>&lt;xs:schema xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>"
>
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element name="Name" type="MyComplexType"
/>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:complexType name="MyComplexType">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:sequence minOccurs="1"
maxOccurs="1">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element name="vorname">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;xs:simpleType >
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:restriction base="xs:string">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:minLength value="4"/>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:restriction>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;/xs:simpleType>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:element>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element name="nachname" type="xs:string" />
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xs:sequence>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:attribute name="Geburtstag"
type="xs:date" />
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:complexType>
<p>&lt;/xs:schema>
<p>and i want to transform it into something like this:
<p>&lt;xs:schema xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>"
>
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element name="Name" type="MyComplexType"
/>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:complexType name="MyComplexType">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:sequence minOccurs="1"
maxOccurs="1">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element name="vorname">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;xs:simpleType >
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:restriction base="xs:string">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:minLength value="4"/>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:restriction>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;/xs:simpleType>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xs:element>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xs:element name="nachname" type="xs:string" />
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xs:sequence>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:attribute name="Geburtstag"
type="xs:date" />
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:complexType>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element name="NameTest">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:simpleType >
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:restriction
base="xs:string">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;xs:minLength value="4"/>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:restriction>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xs:simpleType>
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:element>
<br>&lt;/xs:schema>
<p>this would enable me to create XML instance files with NameTest as root
<br>element.
<p>An now the big question:
<br>Lets asume i have the XSDSimpleTypeDefiniton of the anonymous type
<br>inside the embeded "vorname" element. How can a transfer this to an
<br>newly created XSDELementDeclaration?
<p>I tried the following code:
<p>XSDSimpleTypeDefinition std = getSimpleTypeFromOldSchema();
<br>XSDElementDeclaration elemDecl =
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
xsdFactory.createXSDElementDeclaration();
<br>elemDecl.setName("NameTest");
<br>newSchema.getContents().add(elemDecl);
<br>elemDecl.setTypeDefinition(std);
<p>this produces an element declaration in the new schema that looks like
this:
<p>&lt;?xml version="1.0" encoding="UTF-8"?>
<br>&lt;xsd:schema xmlns:xsd="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>">
<br>&lt;xsd:element name="test1" type="vorname_._type"/>
<br>&lt;/xsd:schema>
<p>So what can i do to achieve what i want to have?
<p>thanks for your answers.
<br>greets Joachim Lusiardi</blockquote>
</html>

--------------65B7F0FFEBF87274A9D96A67--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem with transferring a type definition between two schemas [message #585676 is a reply to message #41528] Fri, 16 April 2004 11:55 Go to previous message
Joachim Lusiardi is currently offline Joachim LusiardiFriend
Messages: 18
Registered: July 2009
Junior Member
Hi,
Thanks for your quick answer. Your code works perfectly. You saved me a
lot of time.
greets
Joachim Lusiardi

Ed Merks wrote:
> Joachim,
>
> For this particular scenario, the following should work:
>
> elemDecl.setAnonymousTypeDefinition((XSDSimpleTypeDefinition )std.cloneConcreteComponent(true,
> false));
>
>
> Joachim Lusiardi wrote:
>
>> Hi!
>> My problem is the following:
>> I have one larger XSD Schema looking like the following:
>>
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
>> <xs:element name="Name" type="MyComplexType" />
>>
>> <xs:complexType name="MyComplexType">
>> <xs:sequence minOccurs="1" maxOccurs="1">
>> <xs:element name="vorname">
>> <xs:simpleType >
>> <xs:restriction base="xs:string">
>> <xs:minLength value="4"/>
>> </xs:restriction>
>> </xs:simpleType>
>> </xs:element>
>> <xs:element name="nachname" type="xs:string" />
>> </xs:sequence>
>> <xs:attribute name="Geburtstag" type="xs:date" />
>> </xs:complexType>
>>
>> </xs:schema>
>>
>> and i want to transform it into something like this:
>>
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
>> <xs:element name="Name" type="MyComplexType" />
>>
>> <xs:complexType name="MyComplexType">
>> <xs:sequence minOccurs="1" maxOccurs="1">
>> <xs:element name="vorname">
>> <xs:simpleType >
>> <xs:restriction base="xs:string">
>> <xs:minLength value="4"/>
>> </xs:restriction>
>> </xs:simpleType>
>> </xs:element>
>> <xs:element name="nachname" type="xs:string" />
>> </xs:sequence>
>> <xs:attribute name="Geburtstag" type="xs:date" />
>> </xs:complexType>
>>
>> <xs:element name="NameTest">
>> <xs:simpleType >
>> <xs:restriction base="xs:string">
>> <xs:minLength value="4"/>
>> </xs:restriction>
>> </xs:simpleType>
>> </xs:element>
>> </xs:schema>
>>
>> this would enable me to create XML instance files with NameTest as root
>> element.
>>
>> An now the big question:
>> Lets asume i have the XSDSimpleTypeDefiniton of the anonymous type
>> inside the embeded "vorname" element. How can a transfer this to an
>> newly created XSDELementDeclaration?
>>
>> I tried the following code:
>>
>> XSDSimpleTypeDefinition std = getSimpleTypeFromOldSchema();
>> XSDElementDeclaration elemDecl =
>> xsdFactory.createXSDElementDeclaration();
>> elemDecl.setName("NameTest");
>> newSchema.getContents().add(elemDecl);
>> elemDecl.setTypeDefinition(std);
>>
>> this produces an element declaration in the new schema that looks like
>> this:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>> <xsd:element name="test1" type="vorname_._type"/>
>> </xsd:schema>
>>
>> So what can i do to achieve what i want to have?
>>
>> thanks for your answers.
>> greets Joachim Lusiardi
>>
Previous Topic:Problem with transferring a type definition between two schemas
Next Topic:Getting elements II
Goto Forum:
  


Current Time: Thu Oct 29 03:27:31 GMT 2020

Powered by FUDForum. Page generated in 0.02288 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top