Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: NewBie Question

From: George Cristian Bina <george@---------.--->
To: =?ISO-8859-1?Q?H=E4mmer_Wolfgang?= <Wolfgang.Haemmer@---.--->
Date: 6/23/2005 2:57:00 PM
Hi Wolf,

Then you can do that with substitution groups. You can define an 
abstract element of the expected type, make the type final and then in 
the instance there will be accepted only elements of that type that can 
substitute the abstract element.
Here it is an example:

sample.xsd schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xs:element name="root">
         <xs:complexType>
             <xs:choice maxOccurs="unbounded">
                 <xs:element ref="common"/>
             </xs:choice>
         </xs:complexType>
     </xs:element>

     <xs:element name="common" abstract="true" type="CommonType"/>

     <xs:complexType name="CommonType" mixed="true" final="#all">
         <xs:sequence>
             <xs:element name="LocalVariables" minOccurs="1" maxOccur=
s="1">
                 <xs:complexType>
                     <xs:choice>
                         <xs:sequence>
                             <xs:element name="l_start" minOccurs="1"=
 
maxOccurs="1"/>
                             <xs:element name="l_end" minOccurs="1" 
maxOccurs="1"/>
                         </xs:sequence>
                         <xs:sequence>
                             <xs:element name="l_first" minOccurs="1"=
 
maxOccurs="1"/>
                             <xs:element name="l_second" minOccurs="1=
" 
maxOccurs="1"/>
                             <xs:element name="l_third" minOccurs="1"=
 
maxOccurs="1"/>
                         </xs:sequence>
                     </xs:choice>
                 </xs:complexType>
             </xs:element>
         </xs:sequence>
     </xs:complexType>
     <xs:element name="TableDrop" type="CommonType" 
substitutionGroup="common"/>
     <xs:element name="Sizes" type="CommonType" substitutionGroup="=
common"/>
</xs:schema>

valid instance:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="sample.xsd">

     <TableDrop>
         public string code (string l_p) {
         return l_first + l_p + l_second + l_p + l_third;
         }=09
         <LocalVariables>
             <l_first>
                 aString =  _T(&quot;drop table </l_first>
             <l_second>
                 &quot;); hr = Oc.Execute( aString );
                 if ( FAILED(hr) ) _tprintf(_T(&quot;Oc.Execute drop 
table failed with EBSc_TAB_</l_second>
             <l_third>
                 &quot;));
             </l_third>
         </LocalVariables>
     </TableDrop>
     <Sizes>
         public string code (string l_p) { return l_start + l_p + l_end;}
         <LocalVariables>
             <l_start>//TYPEDEF[attribute::name=</l_start>
             <l_end>]/attribute::size</l_end>
         </LocalVariables>
     </Sizes>
</root>

Hope that helps,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
www.---.com


H=E4mmer Wolfgang wrote:
> Salut George,
> 
> Thank you for your help!
> 
> The problem with this solution is that I do not know in advance what th=
e name of the element will be. I would like ot be able to write ...
> 
> Expect an element x of type CommonType of unknown name.
> 
> Best regards, Wolf
> 
> -----Original Message-----
> From: George Cristian Bina [mailto:george@o...]
> Sent: Donnerstag, 23. Juni 2005 10:06
> To: H=E4mmer Wolfgang
> Cc: xmlschema-dev@w...
> Subject: Re: NewBie Question
> 
> 
> Hi Wolf,
> 
> You can reuse a type in XML schema if you define that is a global type 
> definition and then set that type to the elements that you want to have=
 
> the same content. Something like below:
> 
> <xs:complexType name="CommonType" mixed="true">
>      <xs:sequence>
>          <xs:element name="LocalVariables" minOccurs="1" maxOccurs==
"1">
>              <xs:complexType>
>                  <xs:choice>
>                      <xs:sequence>
>                          <xs:element name="l_start" minOccurs="1" 
> maxOccurs="1"/>
>                          <xs:element name="l_end" minOccurs="1" 
> maxOccurs="1"/>
>                      </xs:sequence>
>                      <xs:sequence>
>                          <xs:element name="l_first" minOccurs="1" 
> maxOccurs="1"/>
>                          <xs:element name="l_second" minOccurs="1" 
> maxOccurs="1"/>
>                          <xs:element name="l_third" minOccurs="1" 
> maxOccurs="1"/>
>                      </xs:sequence>
>                  </xs:choice>
>              </xs:complexType>
>          </xs:element>
>      </xs:sequence>
> </xs:complexType>
> <xs:element name="TableDrop" type="CommonType"/>
> <xs:element name="Sizes" type="CommonType"/>
> 
> Best Regards,
> George
> ---------------------------------------------------------------------
> George Cristian Bina
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> www.---.com
> 
> 
> H=E4mmer Wolfgang wrote:
> 
>>Hello,
>>
>>this is something I wanted to ask for a long time ....
>>
>>
>>Is there a way using a xml schema to describe an element which name cha=
nges as in ...
>>
>>			<TableDrop>
>>				public string code (string l_p) { 
>>					return l_first + l_p + l_second + l_p + l_third;
>>				}=09
>>				<LocalVariables>
>>					<l_first>
>>   						 aString =  _T(&quot;drop table </l_first>
>>					<l_second>
>>						&quot;); hr = Oc.Execute( aString );
>>   						 if ( FAILED(hr) ) _tprintf(_T(&quot;Oc.Execute drop table fai=
led with EBSc_TAB_</l_second>
>>					<l_third>
>>						&quot;));
>>					</l_third>
>>				</LocalVariables>
>>			</TableDrop>
>>			<Sizes>
>>				public string code (string l_p) { return l_start + l_p + l_end;}
>>				<LocalVariables>
>>					<l_start>//TYPEDEF[attribute::name=</l_start>
>>					<l_end>]/attribute::size</l_end>
>>				</LocalVariables>
>>			</Sizes>
>>
>>The elements TableDrop and Sizes have the same structure but bear diffe=
rent names.
>>
>>I would like to write something like ....
>>
>>	<xs:element name='.*'>
>>     	<xs:complexType>
>>               <xs:sequence>
>>          		<xs:element name="LocalVariables" minOccurs="1" maxOccu=
rs="1">
>>			     	<xs:complexType>
>>               			<xs:sequence>
>>          					<xs:element name="l_start" minOccurs="1" maxOccurs==
"1">
>>          					<xs:element name="l_end" minOccurs="1" maxOccurs="=
1">
>>			               <xs:sequence>
>>					</xs:complexType>
>>				</xs:element>
>>               <xs:sequence>
>>		</xs:complexType>
>>	</xs:element>
>>
>>Thanks for your help!
>>
>>Kind regards, Wolf
>> 
>> 
>>This message is for the named person's use only. It may contain confide=
ntial, proprietary or legally privileged information. No confidentiality =
or privilege is waived or lost by any mistransmission. If you receive thi=
s message in error, please notify the sender urgently and then immediatel=
y delete the message and any copies of it from your system. Please also i=
mmediately destroy any hardcopies of the message. You must not, directly =
or indirectly, use, disclose, distribute, print, or copy any part of this=
 message if you are not the intended recipient. The sender's company rese=
rves the right to monitor all e-mail communications through their network=
s. Any views expressed in this message are those of the individual sender=
, except where the message states otherwise and the sender is authorised =
to state them to be the views of the sender's company.
>>
>>

From Wolfgang.Haemme


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent