[Xml-compile] Adding namespaced attributes to elements

Drew Taylor drew at drewtaylor.com
Mon Aug 18 12:45:04 BST 2008


On 18 Aug 2008, at 12:24, Mark Overmeer wrote:

> * Drew Taylor (drew at drewtaylor.com) [080818 11:16]:
>> This is an example of the element where I need a namedspaced  
>> attribute
>> added:
>> <Segment Apply="Included" ID="CELASSGS"  
>> xsi:type="SegmentInsuranceType">
>> <![CDATA[foo bar baz]]>
>> <Code Name="Code" Role="Reference" Value="xxx"/>
>> <Price Ref="PA" Value="100"/>
>> </Segment>
>>
>> In my case there are only a few elements which need the attribute, so
>> a hook would probably suffice. A nicer way would be useful of
>> course. :-)
>
> Can you tell me the reason for this xsi:type?  When it is within
> SOAP, then it is probably rpc-encoded... and there is a mechanism
> to do so.
>
> In your case, it may be in mixed elements... but how is your schema
> definition for this component?

Yes, it is within a mixed content schema. This is from the XFT schema.  
Please don't get me started on how incredibly complex this schema is.  
It's far more convoluted than the schema we adopted for our own SOAP  
API. I don't understand why they chose to go with types of the same  
element rather than creating a new element which referenced the  
appropriate complexType. You can imagine how I felt when I saw what I  
had to work with. :-(

Just for kicks I tried s/mixed="true"/mixed="false"/g since I can live  
without the text content, but (not surprisingly) that caused massive  
trouble in the form of deep recursion errors.

Here's the schema and all its parents for the <Segment> element.

<xs:schema xmlns:h="http://www.w3.org/1999/xhtml" xmlns="http://www.exchangefortravel.org/xft/current 
" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/2001/XInclude 
" targetNamespace="http://www.exchangefortravel.org/xft/current"  
elementFormDefault="qualified" attributeFormDefault="unqualified"  
version="1.0">
...
	<xs:element name="Segment" type="SegmentType">
		<xs:annotation>
			<xs:documentation>For trip description : A segment can be Vehicle,  
travel or stay, unique or
				composite (for vias, multiple rooms in a hotel, ...)</ 
xs:documentation>
		</xs:annotation>
	</xs:element>
	<xs:complexType name="SegmentInsuranceType" mixed="true">
		<xs:complexContent mixed="true">
			<xs:extension base="SegmentProductType">
				<xs:sequence minOccurs="0">
					<xs:group ref="InsuranceCoverageGroup"/>
				</xs:sequence>
				<xs:attribute name="Scope" type="InsuranceScopeCodeType"  
use="optional"/>
				<xs:attribute name="Type" type="InsuranceTypeCodeType"  
use="optional"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="SegmentType" abstract="false" mixed="true">
		<xs:complexContent mixed="true">
			<xs:extension base="TravelEntityType">
				<xs:sequence minOccurs="0">
					<xs:group ref="DateTimeRangeGroup" minOccurs="0"/>
					<xs:group ref="StockGroup" minOccurs="0"/>
					<xs:group ref="RuleGroup" minOccurs="0"/>
					<xs:group ref="KeywordGroup" minOccurs="0"/>
					<xs:group ref="BookingGroup" minOccurs="0"/>
					<xs:group ref="DocumentGroup" minOccurs="0"/>
					<xs:sequence minOccurs="0">
						<xs:group ref="CardGroup" minOccurs="0"/>
					</xs:sequence>
					<xs:group ref="CatalogueGroup" minOccurs="0"/>
					<xs:group ref="SellLocationGroup" minOccurs="0"/>
					<xs:element ref="Comment" minOccurs="0"/>
					<xs:element ref="Option" minOccurs="0"/>
					<xs:group ref="SSR_Group" minOccurs="0"/>
					<xs:group ref="StaffGroup" minOccurs="0"/>
				</xs:sequence>
				<xs:attributeGroup ref="ProductGroup"/>
				<xs:attribute name="Is" type="ProductNatureCodeType"  
use="optional"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="TravelEntityType" mixed="true">
		<xs:complexContent mixed="true">
			<xs:extension base="EntityQualifiedType">
				<xs:sequence minOccurs="0">
					<xs:group ref="ReferenceRangeGroup" minOccurs="0"/>
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="EntityQualifiedType" mixed="true">
		<xs:complexContent mixed="true">
			<xs:extension base="EntityType">
				<xs:sequence minOccurs="0">
					<xs:group ref="ValidityGroup" minOccurs="0"/>
					<xs:group ref="CodeGroup" minOccurs="0"/>
					<xs:group ref="TypeGroup" minOccurs="0"/>
					<xs:element ref="NameText" minOccurs="0"/>
					<xs:group ref="CustomFieldGroup" minOccurs="0"/>
					<xs:sequence minOccurs="0">
						<xs:element ref="Extension"/>
					</xs:sequence>
					<xs:group ref="DescriptionGroup" minOccurs="0"/>
					<xs:group ref="PriceGroup" minOccurs="0"/>
					<xs:sequence minOccurs="0">
						<xs:group ref="EntityGroup" minOccurs="0"/>
					</xs:sequence>
					<xs:group ref="TaskGroup" minOccurs="0">
					</xs:group>
					<xs:group ref="HistoryGroup" minOccurs="0">
					</xs:group>
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="EntityType" mixed="true">
		<xs:complexContent mixed="true">
			<xs:extension base="AtomType">
				<xs:sequence minOccurs="0">
					<xs:group ref="StyleRangeGroup" minOccurs="0"/>
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name="AtomType" abstract="true" mixed="true">
		<xs:sequence minOccurs="0">
			<xs:any namespace="##other" processContents="lax" minOccurs="0"  
maxOccurs="unbounded"/>
		</xs:sequence>
		<xs:attributeGroup ref="LinksAndReferencesGroup">
		</xs:attributeGroup>
		<xs:attributeGroup ref="NamesGroup">
		</xs:attributeGroup>
		<xs:attributeGroup ref="PositionGroup">
			<xs:annotation>
				<xs:documentation>Used to group and position within a list</ 
xs:documentation>
			</xs:annotation>
		</xs:attributeGroup>
		<xs:attributeGroup ref="MatchGroup"/>
		<xs:attributeGroup ref="MinMaxGroup"/>
		<xs:attributeGroup ref="StatusGroup"/>
		<xs:attributeGroup ref="VersionGroup"/>
	</xs:complexType>
...
</xs:schema>

Drew




More information about the Xml-compile mailing list