How to generate a 'HTML select' from XSD definition - xsd

I try to generate HTML code from XSD and plan to generate a selection with defined values.
I could use a restriction in XSD but I need the values of the options too.
<select name="Pizza" size="5">
<option value="P101">Pizza Napoli</option>
<option value="P102">Pizza Funghi</option>
</select>
What would be the proper XSD to define a HTML select with options and values?

A standard xs:restriction will allow you to mark up the values, but for the descriptions I'd just use a custom namespace on top of the schema. Something like this would do it:
<xs:element name="Pizza" xmlns:pizza="http://my.custom.namespace/pizza">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="P101" pizza:description="Pizza Napoli"/>
<xs:enumeration value="P102" pizza:description="Pizza Funghi"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XML is extensible and so therefore is XML schema.
This approach has the benefit that you can still validate data against the schema easily (a validator will simply ignore the custom namespace), but when converting to HTML, you can write out the options in the way you want.

Related

XSD Validation - Allow All Except String That Contains

Quite new at XSD validations.
Is there any way at all to validate string values - to allow all values a user may enter except certain values that contain a keyword.
For example, I have a system that users can submit their names.
I want to allow any name that comes through except for strings that contain 'Joh'
i.e. Allow Mary, Eric, Simon, etc and reject John, Johan, Bjohn, Benjoh, etc
So in my understanding (coming from PHP), 'Not Equal To' is '!=' but this wouldn't work here.
And wildcards wouldn't work as for any values that contain 'joh' as '%joh%'
<xs:element name="Names">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value!="%joh%"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Is there anyway around this?

SOAP UI - <xs:choice> and <xs:element> as siblings under <xs:sequence> not interpreted correctly

I am using SOAPUI for sending SOAP requests to my web service.
When I have <xs:choice> and <xs:element> as siblings under <xs:sequence>, the choice element does not appear as a combo box, instead appears as sequence of elements.
In this case, my SOAP request in SOAPUI shows all the elements ignoring <xs:choice>.
Please let me know if somebody ran into this problem and got any solution
What I understand you are looking for is numerated list
Like this
<xs:simpleType name="regularType">
<xs:restriction base="xs:token">
<xs:enumeration value="yes"/>
<xs:enumeration value="no"/>
</xs:restriction>
</xs:simpleType>
and add as many choices as you need.
Edit: I know it's 4 months old question, but I guess someone in the future might benefit from this.

writing pattern in xsd for <a attributes><img/></a>

I am trying to apply pattern for an element in xsd.
Element is of type XHTML.
I want to apply pattern like this.
<a attributes="some set of attributes"><img attributes="some set of attribtes"/></a>
Rules:
<a> tag with attributes followed by <img> with attributes.
Sample Valid Data:
<a xlink:href="some link" title="Image" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
<img alt="No Image" title="No Image" xlink:href="soem path for image" xlink:title="Image" xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" />
</a>
Invalid:
<a>data<img/></a>--Data Present, no attributes
<a><img>abcd</img></a>--data Present, No attributes
<a><img/></a>---No attributes
Can any one suggest how to write pattern for this.
<xsd:restriction base="xs:string">
<xs:pattern value="Need help"/>
</xsd:restriction>
Thank you.
The XSD pattern facet is used to constrain the 'lexical space' of a simple type (that is, the set of literal strings that denote instances of the type) using regular expressions. It won't help you to require that certain elements must have attributes.
If you want specific attributes to be present (e.g. title and xlink:href on the a element, title and alt on the img element), the simplest way to do so in a schema is by declaring those attributes as required. The schema for XHTML 1.0 strict, for example (at http://www.w3.org/TR/xhtml1-schema/#xhtml1-strict) declares both src and alt as being required on img:
<xs:element name="img">
<xs:complexType>
<xs:attributeGroup ref="attrs"/>
<xs:attribute name="src" use="required" type="URI"/>
<xs:attribute name="alt" use="required" type="Text"/>
...
</xs:complexType>
</xs:element>
If what you want is just to require that some attributes be used, but you don't care which, XSD doesn't make the task easy: in XSD 1.0 there is no convenient way to say "I don't care which attribute appears, but there has to be one". You can enforce such a constraint (even if some observers like me find it a bit odd) by using assertions in XSD 1.1, or by using a Schematron schema in addition to your XSD schema.

Is there a way to restrict a string to be ASCII only in XSD?

Although the XML file being described by the XSD Schema may contain any unicode characters in general, there are some fields where only ASCII is allowed. (As these strings are going to be passed to another system which only accepts ASCII.)
Is there a way to specify that in XSD?
A regexp with all possible ASCII characters would be a possibility I suppose, but I feel there must be a better way.
You can try that :
<xs:simpleType name="basicLatin">
<xs:restriction base="xs:string">
<xs:pattern value="\p{IsBasicLatin}*"/>
</xs:restriction>
</xs:simpleType>
Unfortunately, for your requirement there isn't a way to restrict without using patterns.

Help in defining conditional params in WSDL

I am working on defining WSDL and it has i/p param in the operation.
WSDL will be tested by SOATest.
Query:
I have a param which is conditional and need help in defining.
I want something like this..
if Name is selected then it should force user to select LastName, else both will be null
Dummy Ex:
<xs:simpleType name="FullName">
<xs:restriction base="xs:string">
<xs:enumeration value="Name" />
<xs:enumeration value="LastName" />
</xs:restriction>
</xs:simpleType>
There is no way to do this using WSDL or XSD (which WSDL depends on).
There are sometimes hacks you can use, but they're worse than the alternative. The alternative is to simply verify in code that if Name is selected then Lastname must be supplied.

Resources