How can I guarantee that the url element starts with "http://"?
<xs:element name="url" type="xs:anyURI"/>
xs:anyURI — URI (Uniform Resource Identifier).
minExclusive. Specifies the lower bounds for numeric values (the value must be greater than this value) minInclusive. Specifies the lower bounds for numeric values (the value must be greater than or equal to this value) minLength.
A complex type is essentially a type definition for elements that may contain attributes and elements. An element can be declared with a type attribute that refers to a complexType element that defines the structure, content, and attributes of that element.
Description. The value space of xsd:double is double (64 bits) floating-point numbers as defined by the IEEE (Institute of Electrical and Electronic Engineers). The lexical space uses a decimal format with optional scientific notation.
You can add a xs:restriction
for a Regular Expression using xs:pattern
:
<xs:element name="url">
<xs:simpleType>
<xs:restriction base="xs:anyURI">
<xs:pattern value="http://.+" />
</xs:restriction>
</xs:simpleType>
</xs:element>
This will match to anything that starts with http://
. It will match:
http://www.stackoverflow.com
http://somethingsomethingsomething
http://123456789!!!!!
http://0
It will not match https
URLs:
https://github.com
If you want to match https
as well you can change the pattern to
https?://.+
which means that the s
is allowed and is optional.
If you want to match only valid URLs then you need to improve it to check for characters, followed by a dot, more characters, a valid domain suffix, etc. If you search for URL validation via regex you will find several examples. You can also try this resource. And to experiment with Regex, Regex 101 is a great resource.
Pattern matching in XSD has some restrictions. Check this SO question/answer which discusses that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With