在新的命名空间中定义简单类型,例如 xsd:string? [英] Define simple type such as xsd:string in a new namespace?
问题描述
这应该是直截了当的,但在我看来,它似乎只有关于复杂类型的信息.
This should be straight forward but everywhere I look it seems to have information only about complex types.
假设我已经定义了一个名称空间 xmlns:address="http://...."
.现在从我读过的内容来看,我可以执行以下操作:<xsd:element name="street" type="address:sAdd"/>
然后定义复杂类型
.
Let's say that I have defined a namespace xmlns:address="http://...."
. Now from what I have read it seams like I could do the following: <xsd:element name="street" type="address:sAdd"/>
and then define the complex type <xsd:complexType name="sAdd">
.
但是,我无法找到在像 xsd:string
这样的非复杂类型的情况下会发生什么.我的猜测是类似于 <xsd:element name="street" type="address:xsd:string"/>
.
However, I cannot find what happens in the case of a non complex type like a xsd:string
. My guess would be something like <xsd:element name="street" type="address:xsd:string"/>
.
你能验证我的回答或告诉我正确的方法吗?
Can you please verify my answer or let me know about the correct way of doing so?
推荐答案
不,命名空间前缀不能级联:address:xsd:string
不是一个格式良好的 QName.
No, namespace prefixes cannot be cascaded: address:xsd:string
is not a well-formed QName.
xsd:string
在所有命名空间中都是相同的.这是应该的.
An xsd:string
will be the same in all namespaces. This is as it should be.
如果您希望您的字符串与xsd:string
不同,请根据xsd:string
为您的字符串定义一个类型,然后放置根据您的设计偏好,它位于(或不在)命名空间中:
If you want your string to vary from xsd:string
, define a type for your string based on xsd:string
, and place it in a namespace (or not) per your design preferences:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mst="http://www.example.com/MyStringType"
targetNamespace="http://www.example.com/MyStringType">
<xs:element name="root" type="mst:MyStringType"/>
<xs:simpleType name="MyStringType">
<xs:restriction base="xs:string">
<xs:maxLength value="256" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
这篇关于在新的命名空间中定义简单类型,例如 xsd:string?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!