What does this XSD restriction mean. Derived type with restriction just an attribute of the base type - xsd

There is a base type "Objectnummering-e" and a derived type "ObjectNummering-geoBAG".
The restriction on "ObjectNummering-geoBAG" mentions an attribute of the base type.
It is unclear to me what this does. To me the two types are identical. But are they?
<complexType name="ObjectNummering-geoBAG">
<simpleContent>
<restriction base="BG:ObjectNummering-e">
<attribute ref="StUF:noValue"/>
</restriction>
</simpleContent>
</complexType>
<complexType name="ObjectNummering-e">
<simpleContent>
<extension base="BG:ObjectNummering">
<attributeGroup ref="StUF:element"/>
</extension>
</simpleContent>
</complexType>
<simpleType name="ObjectNummering">
<restriction base="string">
<length value="16"/>
</restriction>
</simpleType>
<attributeGroup name="element">
<attribute ref="StUF:noValue"/>
<attribute ref="StUF:exact"/>
</attributeGroup>

As always, the only reliable way to answer a question like this is to go to the W3C specification. Your complex type is a 'complex type with simple content' so the relevant section is:
https://www.w3.org/TR/xmlschema-1/#declare-type, sub-section Complex Type Definition with simple content Schema Component
3 if the type definition ·resolved· to by the ·actual value· of the base [attribute] is a complex type definition, the {attribute uses} of that type definition, unless the alternative is chosen, in which case some members of that type definition's {attribute uses} may not be included, namely those whose {attribute declaration}'s {name} and {target namespace} are the same as one of the following:
3.1 the {name} and {target namespace} of the {attribute declaration} of an attribute use in the set per clause 1 or clause 2 above;
3.2 what would have been the {name} and {target namespace} of the {attribute declaration} of an attribute use in the set per clause 1 above but for the ·actual value· of the use [attribute] of the relevant among the [children] of being prohibited.
In plain English, it means that a complex type restriction must re-declare any attributes that it wants to retain - they are not automatically inherited. So derived type "ObjectNummering-geoBAG" only has 1 attribute, not 2.

Related

Why by enumtype dynamic="false" is set to false?

Why by enumtype dynamic="false" is set to false? And when should I set it to "true"?
<enumtype code="MyEnumType" generate="true" autocreate="true" dynamic="false">
<value code="NONE" />
<value code="ONE" />
</enumtype>
With the hybris enumtype, you have the option to define a static enum or a dynamic enum. Static (dynamic="false") means, that the enumeration only contains the defined elements. During runtime you will never be able to add elements to the enum. This is different when you use a dynamic enum (dynamic="true"). With dynamic enumerations you can add values during runtime. So if you want your enum to be static, use dynamic="false". If you want to add values during runtime, use dynamic="true".
I think i found the answer on a hard way:
INSERT_UPDATE ManufacturerName;code[unique=true];name[lang=de];name[lang=en]
,,,,Exception : line 9: cannot create ManufacturerName with values ItemAttributeMap[ registry: null, type: <null>, data: {code=00000023344, name={8796093054536->de=3D , 8796093054536->en=3D }} ] due to [de.hybris.platform.servicelayer.interceptor.impl.EnumerationValidator#197d511d]:Enum type ManufacturerName is not dynamic - can not create new enum value 00000023344. If you want to add a new value to this type you have to define the enum type as non dynamic at items.xml (needs system update afterwards).
In simple words, I can say static enum(dynamic="false", default value) is generated as the Java enum. In which list of values can only be changed during compilation time by changing the items.xml. In case of the dynamic enum(dynamic="true") we can change(add/remove) its values at runtime using hmc or Impex.
Static Enum:
<enumtype code="FixedValueType" autocreate="true" generate="true">
<value code="value1"/>
<value code="value2"/>
</enumtype>
Dynamic Enum:
<enumtype code="OrderStatus" autocreate="true" generate="true" dynamic="true">
<value code="CREATED"/>
<value code="ON_VALIDATION"/>
<value code="COMPLETED"/>
<value code="CANCELLED"/>
</enumtype>
more about hybris enum
If dynamic ="false", it means it acts as java_Enum (it cannot be modified).
If dynamic ="true", it acts as hybris_Enum (i.e, you will able to add the additional Enumeration value Types at runtime through hac).

XSD keyref or number literal

Is it possible to define a type which can be either a keyref or a number literal? Just like in any typed programming language you can assign either a number literal OR the name of another variable to a numeric variable. I'm making a schema to define drawing api elements (for another programming language) and would like to define a color type that can either be a hexadecimal literal (such as 0xFF0000 for bright red) OR be a reference to a color defined elsewhere. So you could do (in a XML document):
<color key="dialogBorder1">0x222222</color>
<color key="dialogFill1">0xCCCCCC</color>
<!-- later... -->
<windowTheme name="warningWindow">
<border>
<color>0xFF0000</color> <!-- defined literally -->
</border>
<fill>
<solid>
<color>dialogFill1</color> <!-- defined by keyref -->
</solid>
</fill>
</windowTheme>
If it were possible to impose a choice restriction on attributes I could do something like the following, but I am under the impression this is not possible with current (1.0) version of XSD spec.
<!-- I wish: -->
<xs:complexType name="colorType" >
<xs:attrchoice>
<xs:attribute name="value" type="HexLiteral" /> <!-- literal -->
<xs:attribute name="ref" type="xs:string" /> <!-- keyref (defined elsewhere) -->
</xs:attrchoice>
</xs:complexType>
Which would allow either lieral value or keyref ref:
<color value="0xFF0000" /> <!-- OK -->
<color ref="dialogBorder1" /> <!-- OK -->
But not both:
<color value="0xFF0000" ref="colorXYZ" /> <!-- NOT OK -->
The post is somewhat inconsistent in what's describing. The first XML shows color used without attributes, then the xsd for colorType goes off with some attributes. I assume the XML is what you wanted.
So the following works for:
To define a color type that can either be a hexadecimal literal (such as 0xFF0000 for bright red) OR be a reference to a color defined elsewhere
<xsd:simpleType name="ColorHex">
<xsd:union memberTypes="xsd:string">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="0x[0-9a-fA-F]{6}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:union>
</xsd:simpleType>
The above uses the same pattern as the Color type in XHTML (I am showing this to give you sources of inspiration):
<!-- sixteen color names or RGB color expression-->
<xsd:simpleType name="Color">
<xsd:union memberTypes="xsd:NMTOKEN">
<xsd:simpleType>
<xsd:restriction base="xsd:token">
<xsd:pattern value="#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:union>
</xsd:simpleType>
The idea here is to use a union. The downside may be that since all that's not matching the HEX pattern will be matched by the string, invalid HEX syntax (e.g. missing digits) will pass through as references.
Other downsides may be in how well is xsd:union supported by the programming languages that you're targeting.

How to define a 'literal' in XSD

I'm a newbie with XSD and pretty much at wits end.
What I need to do is somehow define a 'literal' element within an XSD file so that users can use it in an XML document.
For example:
In the XML document, I want to let a user be able to add an element like this:
<WordBoundary/>
but let the XSD file define not only the name 'WordBoundary' but also a list of Elements within which are of types defined elsewhere within the XSD.
Is this possible?
Updated to provide more information:
I am trying to write an XSD (or set of XSDs) which provide a library of pre-defined elements for an end-user to use.
The elements will ultimately be used to generate a Regular Expression but I want to hide the complexities of regular expressions from users as far as possible.
The XSD will use .NETs XSD.Exe to generate C# classes.
Currently I have defined elements like and and etc. which work fine but rely on their ultimate regex pattern being defined in code. Some of the elements have a Pattern attribute to allow fine tuning but this clutters up the XML document for users somewhat.
Examples of the built-up existing C# definitions:
const string BidMatch = #"(?<" + BidGroupName + ">" + DecimalNumberFragment + ")";
const string OfferMatch = #"(?<" + OfferGroupName + ">" + DecimalNumberFragment + ")";
const string BidOfferSpreadMatch = BidMatch + OptionalGap + RangeSeparatorFragment + OptionalGap + OfferMatch;
I therefore wanted to be able to refactor this so that all the regex patterns are moved from code into XSD definitions to form a library (or if it turns out not to be possible an XML file looked up by name) whereby there are primitives such as and and commonly-used but more complex structures such as etc.
So the use can use predefined elements like directly within their XML document but also be able to build up their own like this:
<Group captureName="MyCustomMatch">
<WordBoundary/>
<Digit/>
<Literal pattern="[xyz]" />
<AnyOf/>
<AnyOfChoice>
<DecimalNumber />
<Gap />
<DecimalNumber />
</AnyOfChoice>
<AnyOfChoice>
<LiteralText text="(" />
<DecimalNumber />
<LiteralText text=")" />
</AnyOfChoice>
<WordBoundary/>
</Group>
(In fact the prefined elements in the library would be build up the same way)
From the code point of view, I currently have AnyOf/Group etc. working by looking at the element type and calling a method to generate the pattern. For this to work, all these new Elements need to have a common ancestor, e.g. RegexLiteral, from which I can just read the Pattern attribute or whatever and add it into the full pattern.
I have tried extending a common type and trying to override its Pattern attribute to use a fixed attribute but XSD does not apparently allow this.
I am hoping this is just a limitation of my XSD knowledge rather than of XSD itself and hoping you clever guys know a way of achieving this.
Update2:
Thought I had it with this XSD fragment
<xs:complexType name="LiteralFragment" abstract="true">
<xs:attribute name="Pattern" type="xs:string" />
</xs:complexType>
<xs:complexType name="Fred">
<xs:complexContent >
<xs:extension base="LiteralFragment" >
<xs:attribute name="Pattern" type="xs:string" fixed="BBB" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
but XSD (and Xsd2Code for that matter) generate this rubbish code:
public partial class Fred : LiteralFragment
{
private string pattern1Field;
public Fred()
{
this.pattern1Field = "BBB";
}
[System.Xml.Serialization.XmlAttributeAttribute("Pattern")]
public string Pattern1
{
get { return this.pattern1Field; }
set { this.pattern1Field = value; }
}
}
which bombs because there are two XmlAttributeAttribute with "Pattern" being used.
What I need is an XSD generator that is intelligent enough to realise this and generate this code instead:
public partial class Fred : LiteralFragment
{
public Fred()
{
Pattern = "BBB";
}
}
Try this....
The XSD:
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root" type="TRoot"/>
<xsd:element name="WordBoundary">
<xsd:complexType/>
</xsd:element>
<xsd:element name="SomethingElse">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="TRoot">
<xsd:sequence>
<xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
And this XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SomethingElse>Text <WordBoundary/> another <WordBoundary/>...</SomethingElse>
</root>
Is this what you had in mind?

Enum values in Composite Component attribute

My issue is quite simple : I want to create a composite component with a String attribute, Type.
<cc:attribute name="type" />
This attribute will have 3 acceptable values, [TYPE1, TYPE2, TYPE3]
Is it possible to say my component will accept only these values ?
Unfortunately no, you cannot put a compile/buildtime restriction on a composite component attribute value in the cc interface. You can however put a runtime restriction by checking the value in the cc implementation.
<ui:param name="type" value="#{cc.attrs.type}" />
<ui:fragment rendered="#{type == 'TYPE1' or type == 'TYPE2' or type == 'TYPE3'}">
<p>The type is TYPE1, TYPE2 or TYPE3.</p>
<p>Write your component's body here.</p>
</ui:fragment>
That'll be your best bet.

How to create an array of records in BizTalk

I have an xsd type which consists of some elements. One of the elements is defined like
<xs:element name="Parameters" type="ParametersType" /> where ParametersType is
<xs:complexType name="ParametersType">
<xs:sequence>
<xs:element name="Parameter"
type="ParameterType"
minOccurs="0"
maxOccurs="unbounded" />
<xs:element name="UserDefinedParameter"
type="xs:base64Binary"
minOccurs="0"
maxOccurs="1">
</xs:element>
</xs:sequence>
</xs:complexType>
That is, I have an array of Parameter type records. So I have 2 questions so far:
Ноw to initialize such array and how to work with it in Expression block;
How to tune mapping from incoming message of the same type to my message?
When we talk about arrays here we are really talking about nested, repeatable nodes within your message.
One solution is to decompose your array inside a loop in your orchestration.
This is not simple, but here is an example:
The code inside the various expression shapes:
Inside "Count array items"
intCountArrayItems = xpath(MyMessage, "count(XpathToParameterNodeInYourMessage)");
Inside "foreach array item"
intLoopIndex < intCountArrayItems
Inside "Use array item"
strXPathToArrayItem = System.String.Format("XpathToParameterNodeInYourMessage[{0}]", intLoopIndex + 1);
MyXmlDocument = xpath(MyMessage, strXPathToArrayItem);
// Now you can do what you want with the xml document.
Inside "Increment loop index"
intLoopIndex = intLoopIndex + 1;
The above gives you a way to decompose an array inside your orchestration and access each of your "Paramter" types as an xml document (which you can then do stuff with).
Hope this helps.

Resources