I added a new attribute at the a section in the backoffice.
I added a date time attribute
<editorArea:attribute qualifier="DateCutOffTime" defaultEditor="com.hybris.cockpitng.editor.defaulttime">
<editorArea:editor-parameter>
<editorArea:name>timeFormat</editorArea:name>
<editorArea:value>short</editorArea:value>
</editorArea:editor-parameter>
<editorArea:editor-parameter>
<editorArea:name>timeZoneReadOnly</editorArea:name>
<editorArea:value>false</editorArea:value>
</editorArea:editor-parameter>
<editorArea:editor-parameter>
<editorArea:name>selectedTimeZone</editorArea:name>
<editorArea:value>GMT+01:00</editorArea:value>
</editorArea:editor-parameter>
<editorArea:editor-parameter>
<editorArea:name>displayedTimeZones</editorArea:name>
<editorArea:value>GMT-12:00,GMT-11:00,GMT-10:00,GMT-09:30,GMT-09:00,GMT-08:00,GMT-07:00,GMT-06:00,GMT-05:00,GMT-04:30,GMT-04:00,GMT-03:30,GMT-03:00,GMT-02:00,GMT-01:00,GMT+00:00,GMT+01:00,GMT+02:00,GMT+03:00,GMT+03:30,GMT+04:00,GMT+04:30,GMT+05:00,GMT+05:30,GMT+05:45,GMT+06:00,GMT+06:30,GMT+07:00,GMT+08:00,GMT+08:30,GMT+08:45,GMT+09:00,GMT+09:30,GMT+10:00,GMT+10:30,GMT+11:00,GMT+12:00,GMT+12:45,GMT+13:00,GMT+14:00</editorArea:value>
</editorArea:editor-parameter>
</editorArea:attribute>
But i have a display with a calendar
I want to display a component just with the time to choose and timezone or only show hours.
You seem to mix 2 different types of configuration
This line is wrong:
<editorArea:attribute qualifier="DateCutOffTime" defaultEditor="com.hybris.cockpitng.editor.defaulttime">
You want to use an editor for a specific property (qualifier). For that, you need to write the header with editor instead of defaultEditor. If you look at the correspondig xsd validation, you will notice that defaultEditor is not a valid config option. Change this to editor, and it should work. (assuming DateCutoffTime is a property and not a type on one of your objects, if it's a type, look at the 2nd part of the answer)
<editorArea:attribute qualifier="DateCutOffTime" editor="com.hybris.cockpitng.editor.defaulttime">
corresponding xsd:
<xs:complexType name="attribute">
<xs:complexContent>
<xs:extension base="abstractPositioned">
<xs:sequence>
<xs:element name="editor-parameter" type="parameter" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="qualifier" type="xs:string" use="required"/>
<xs:attribute name="label" type="xs:string" use="optional"/>
<xs:attribute name="visible" type="xs:boolean" use="optional" default="true"/>
<xs:attribute name="readonly" type="xs:boolean" use="optional" default="false"/>
<xs:attribute name="editor" type="xs:string" use="optional"/>
<xs:attribute name="merge-mode" type="xs:string" use="optional"/>
<xs:attribute name="description" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
(For completion)
As far as I'm aware, defaultEditor is only ever used to define a default editor for a type. Then you need to specify the type for which you want to create a default editor. This also needs to be placed in a .zul file, and not in the regular backoffice config files.
<editor id="textEditor" type="java.lang.String" defaultEditor="com.hybris.cockpitng.editor.defaulttext"/>
Related
I need to extend several xml elements of different XML Schema built-in types (e.g. xs:anyURI, xs:string...) with the same two attributes att1 and att2 over and over again.
Example xml to validate:
<extendedURI att1="abc" att2="def">my.uri</extendedURI>
I have tried defining a complex type parent:
<!-- The parent type defines the two attributes I'm interested in -->
<xs:complexType name="parentType">
<xs:attribute name="att1" type="xs:string" />
<xs:attribute name="att2" type="xs:string" />
</xs:complexType>
and then declaring the type of my elements as xs:anyURI and extending them, but this is not valid:
<!-- XXX: The following is not permitted: I cannot redefine the xs:anyURI type -->
<xs:element name="extendedURI" type="xs:anyURI">
<xs:complexType>
<xs:complexContent>
<xs:extension base="parentType" />
</xs:complexContent>
</xs:complexType>
</xs:element>
I have also tried to restrict the simpleContent to xs:anyURI and extended it with parentType, but I couldn't find how. Something like:
<xs:element name="extendedURI">
<xs:complexType>
<xs:simpleContent>
<!-- XXX: This is not permited: -->
<xs:restriction base="xs:anyURI">
</xs:restriction>
<xs:extension base="parentType">
</xs:extension>
<!-- 'xs:restriction' and 'xs:extension' are alternatives and
cannot be defined at the same time!
-->
<xs:simpleContent>
</xs:complexType>
</xs:element>
So how could I accomplish this? Is it possible to extend a built-in type with a complexType (or to restrict a complexType with the definition of a built-in type)?
It is possible to reuse the same set of attributes by using the xsd:attributeGroup:
<!-- several types will declare this set of attributes -->
<xs:attributeGroup name="extensible">
<xs:attribute name="att1" type="xs:string" />
<xs:attribute name="att2" type="xs:string" />
</xs:attributeGroup>
<!-- extending a simple content element with the two 'inherited' attributes -->
<xs:element name="extendedURI">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:attributeGroup ref="extensible"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
I have an existing type like this, which belongs to a library-level XSD:
<xs:complexType name="mybase">
<xs:attribute name="myattr" type="xs:string" default="123"/>
</xs:complexType>
And later this is extended by a number of more specific XSD's that implement application specific configuration requirements:
<xs:element name="appconfig">
<xs:complexType>
<xs:complexContent>
<xs:extension base="mybase">
<xs:attribute name="specific_attr" type="xs:string" use="required"/>
<!-- etc, more specific requirements -->
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
We use this all over the place, but have just run across a use case where for a specific application we want to use a different default value for "myattr". I've poked around various XSD documentation, but haven't found anything that seems to be able to do this, is it possible?
I have a rest/xml service that gives me the following...
<verse-unit unit-id="38009001">
<marker class="begin-verse" mid="v38009001"/>
<begin-chapter num="9"/><heading>Judgment on Israel's Enemies</heading>
<begin-block-indent/>
<begin-paragraph class="line-group"/>
<begin-line/><verse-num begin-chapter="9">1</verse-num>The burden of the word of the <span class="divine-name">Lord</span> is against the land of Hadrach<end-line class="br"/>
<begin-line class="indent"/>and Damascus is its resting place.<end-line class="br"/>
<begin-line/>For the <span class="divine-name">Lord</span> has an eye on mankind<end-line class="br"/>
<begin-line class="indent"/>and on all the tribes of Israel,<footnote id="f1">
A slight emendation yields <i>
For to the <span class="divine-name">Lord</span> belongs the capital of Syria and all the tribes of Israel
</i>
</footnote><end-line class="br"/>
</verse-unit>
I used visual studio to generate a schema from this and used XSD.EXE to generate classes that I can use to deserialize this mess into programmable stuff.
I got everything to work and it is deserialized perfectly (almost).
The problem I have is with the random text mixed throughout the child nodes. The generated verse-unit objects gives me a list of objects (begin-line, begin-block-indent, etc), and also another list of string objects that represent the bits of string throughout the xml.
Here is my schema
<xs:element maxOccurs="unbounded" name="verse-unit">
<xs:complexType mixed="true">
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="marker">
<xs:complexType>
<xs:attribute name="class" type="xs:string" use="required" />
<xs:attribute name="mid" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="begin-chapter">
<xs:complexType>
<xs:attribute name="num" type="xs:unsignedByte" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="heading">
<xs:complexType mixed="true">
<xs:sequence minOccurs="0">
<xs:element name="span">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="class" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="begin-block-indent" />
<xs:element name="begin-paragraph">
<xs:complexType>
<xs:attribute name="class" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="begin-line">
<xs:complexType>
<xs:attribute name="class" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
<xs:element name="verse-num">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:unsignedByte">
<xs:attribute name="begin-chapter" type="xs:unsignedByte" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="end-line">
<xs:complexType>
<xs:attribute name="class" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
<xs:element name="end-paragraph" />
<xs:element name="end-block-indent" />
<xs:element name="end-chapter" />
</xs:choice>
</xs:sequence>
<xs:attribute name="unit-id" type="xs:unsignedInt" use="required" />
</xs:complexType>
</xs:element>
WHAT I NEED IS THIS. I need the random text that is NOT surrounded by an xml node to be represented by an object so I know the order that everything is in.
I know this is complicated, so let me try to simplify it.
<field name="test_field_0">
Some text I'm sure you don't want.
<subfield>Some text.</subfield>
More text you don't want.
</field>
I need the xsd to generate a field object with items that can have either a text object, or a subfield object. I need to no where the random text is within the child nodes.
You can try Xml Schema Mixed Content, which is well explained here: http://www.w3schools.com/schema/schema_complex_mixed.asp
I don't know much about the .net side. But this somewhat older article says that mixed mode is basically supported by xsd.exe: http://msdn.microsoft.com/en-us/magazine/cc164135.aspx
Well your problem starts here:
<xs:element name="begin-line">
<xs:complexType>
<xs:attribute name="class" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
What this means is that a "begin line" type has an attribute called class (Which means the tag can have an attribute class like so: <begin-line class="lineclass">. However it is simply a type xs:string which means that all you get is a string.
I also don't know if this is an option, but if your XML could be made to have closing tags like this line for instance:
<begin-line class="indent"/>and Damascus is its resting place.<end-line class="br"/>
XML should be like this:
<begin-line class="indent"/>and Damascus is its resting place.</begin-line class="br">
I believe that if all the "line" tags were closed properly then the XSD generator might have a better time trying to derive what is inside the "begin-line" XML tag. Indeed if this is possible then you could rename begin-line to line and begin-chapter to chapter which should make your XML much more readable.
If it's not possible to update your code, then you are going to have to try your best with the string itself. I'm not sure if verses contain pure HTML, but if so you could parse the string inside the begin-line element as XML itself, using the library to jump between values and nodes (you might have to wrap a pair of tags around the string before trying to parse it though).
This is a part of my xml schema
<xs:complexType name="Friend">
<xs:all>
<xs:element name="name" type="xs:string" />
<xs:element name="phone" type="xs:string" />
<xs:element name="address" type="xs:string" />
</xs:all>
</xs:complexType>
<xs:complexType name="Coworker">
<xs:all>
<xs:element name="name" type="xs:string" />
<xs:element name="phone" type="xs:string" />
<xs:element name="office" type="xs:string" />
</xs:all>
</xs:complexType>
For better maintainability, I would like to have the shared attributes in an (abstract) super type or something like that. But more important, I want that all elements are unordered and also optional.
Is this possible, and what is the best way to do it?
You have to limit yourself a little bit, some of the things you are trying to do are not possible in XML Schema.
Suppose you introduce a complex type called Person to be a super-type of Friend and Coworker. Here are your options:
Replace xs:all with xs:sequence, remove name and phone from the sub-types, add to the super-type, and add inheritance. Your elements now have to be ordered, but you can make them individually optional. It is illegal to use xs:all in type hierarchies in XML Schema, because the processor cannot tell where the parent content model stops and the child content model starts.
Replace xs:all with <xs:choice maxOccurs="unbounded"> in both types, and add your inheritance. Then your elements become unordered again, but they may repeat.
So in conclusion: given your type names up there, I would guess that your requirements will not be exactly met. I would go for the first option: insisting on arbitrary element order is often not as useful as it seems.
One-and-half year after this question and the accepted answer were posted, XSD 1.1 was published. In this version it is possible to specify what the OP asked for because a number of restriction on xs:all were lifted. One of them is that it is now possible to extend an xs:all.
Using XSD 1.1 you can specify the following:
<xs:complexType name="Person" abstract="true">
<xs:all>
<xs:element name="name" type="xs:string" minOccurs="0" />
<xs:element name="phone" type="xs:string" minOccurs="0" />
</xs:all>
</xs:complexType>
<xs:complexType name="Friend">
<xs:complexContent>
<xs:extension base="Person">
<xs:all>
<xs:element name="address" type="xs:string" minOccurs="0" />
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Coworker">
<xs:complexContent>
<xs:extension base="Person">
<xs:all>
<xs:element name="office" type="xs:string" minOccurs="0" />
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>
This defines the following types:
Person: an abstract type with optional unordered name and phone elements;
Friend: extends Person adding an optional address element to the list of unordered elements;
Coworker: extends Coworker adding an optional office element to the list of unordered elements.
Note that this solution does not work for every XML processor: even though 8 years have passed since the publication of XSD 1.1, a lot of processors still only support XSD 1.0.
I'm trying to write a xml schema that will validate this piece of xml:
<date isodate="2007-03-14">14 march 2007</date>
The attribute isodate should have it's type set to xs:date and the content should be max 50 characters long.
I wonder if it's possible to write the xml schema definition in one block, something like this maybe:
<xs:element name="date" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="50"/>
</xs:restriction>
<xs:attribute name="isodate" type="xs:date" use="required"/>
</xs:simpleContent>
</xs:complexType>
</xs:element>
The code above doesn't work, and I can't really figure out why. Only workaround I have found is to break out the restriction part into a separate type, and link that like this:
<xs:simpleType name="reviewDate">
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="date" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="reviewDate">
<xs:attribute name="isodate" type="xs:date" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
The question I have is how to write the definition in one block so that the schema is a bit more readable, and doesn't reference types in other parts of the schema.
You cannot merge both a restriction and an extension into one block of XSD. The solution that you have with the "ReviewDate" simple type is the best solution I know of.
Marc
You can have a element with restriction and attribute(-s).
The key is to define custom type with it's restrictions and then using it add attributes to it.
Refer here: Content restriction and attribute validation on the same element in XSD