Define simple type such as xsd:string in a new namespace?

本秂侑毒 提交于 2020-01-15 04:51:07

问题


This should be straight forward but everywhere I look it seems to have information only about complex types.

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">.

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?


回答1:


No, namespace prefixes cannot be cascaded: address:xsd:string is not a well-formed QName.

An xsd:string will be the same in all namespaces. This is as it should be.

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>


来源:https://stackoverflow.com/questions/34568794/define-simple-type-such-as-xsdstring-in-a-new-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!