我们可以在XML模式元素名称中使用特殊字符吗? [英] Can we use special character in XML schema element name?

查看:236
本文介绍了我们可以在XML模式元素名称中使用特殊字符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在XML模式中执行此操作?

Is it possible to do this in XML schema?

<xs:element name="A/B" type="xs:string"/> 

看起来我们无法在架构元素名称中使用特殊的字符 /。特殊字符 /引发错误。
还有其他方法可以实现吗?

Looks like we are not able to use special char "/" in schema element name. The special char "/" is throwing an error. Is there any other way we can achieve this?

下面的示例代码可用于重现错误。当另存为Test.xsd,然后在Jdeveloper中打开时,将产生错误消息属性名称的值不属于NCName类型。

The sample code below can be used to reproduce the error. When saved as Test.xsd and then opened in Jdeveloper, this will produce the error message "Value of attribute name not of NCName type".

<?xml version="1.0" encoding="windows-1252" ?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="http://www.example.org"
           targetNamespace="http://www.example.org" 
           elementFormDefault="qualified"> 
    <xs:element name="exampleElement"> 
        <xs:complexType> 
            <xs:sequence> 
                <xs:element name="A/B" type="xs:string"/> 
            </xs:sequence> 
        </xs:complexType> 
    </xs:element> 
</xs:schema>


推荐答案

简短答案: 否。不允许使用斜线。

长答案:

XSD规范的第3.3.1节定义了 name 属性是


[XML名称空间]

这引用了命名空间中的规范XML ,它在NCName /#ns-decl rel = nofollow> 2。声明命名空间。

This references the specification for Namespaces in XML which defines an NCName under section 2. Declaring Namespaces.

您的名称属性的第一个字符 A / B A )在 Letter 类中,所以没关系。但是,第二个字符( / )不在 NCNameChar 类中。跟随组成 NCNameChar 类的类的链接,您将找不到斜杠的代码点 U + 002F 都包含在其中。

The first character of your name attribute A/B (the A) is in the Letter class, so that's okay. However, the second character (the /) is not in the NCNameChar class. Follow the links to the classes that make up the NCNameChar class and you won't find the slash's code point U+002F included in any of them.

重复该过程,系统地找出架构中任何位置允许或不允许的值。

Repeat the process to methodically find out what values are or aren't permitted anywhere in your Schema.

这篇关于我们可以在XML模式元素名称中使用特殊字符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆