如何使用 xsd 限制将 Xml 内容限制为特定长度?

发布于 2024-09-11 05:38:49 字数 466 浏览 1 评论 0原文

使用 XSD,是否可以限制 Node.js 中的总文本。 在下面的示例中,我希望将地址节点内容限制为 255 个字符。

<Address>
    <Line1>Text</Line1>
    <Line2>Text</Line2>
    <City></City>
    <Street></Street>
    <State></State>
    <Country></Country>
</Address>

因此,如果我的地址中只有 Line1 和 Line2,并且 City、Street、State 和 Country 为空,则 Line1 可能为 254 个字符,Line2 将为 1 个字符。

是否可以在 xsd 本身内设置此类约束/限制?

Using XSD, is it possible to constrain the total text within a Node.
In the example below, I want Address Node content to be restricted to 255 characters.

<Address>
    <Line1>Text</Line1>
    <Line2>Text</Line2>
    <City></City>
    <Street></Street>
    <State></State>
    <Country></Country>
</Address>

So, if I only had Line1 and Line2 in my address and City, Street, State and Country were empty, then Line1 could be 254 characters and Line2 will be 1 character.

Is it possible to set such constraints/restrictions within the xsd itself?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长途伴 2024-09-18 05:38:50

您可以将单个元素的文本限制为给定大小,即

            <xs:element name="Line1">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:maxLength value="255" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>

但您不能说 Line1 + line2 + City ... < 255.

You can constrain the text with a single element to be a given size i.e.

            <xs:element name="Line1">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:maxLength value="255" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>

But you can't say Line1 + line2 + City ... < 255.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文