问题
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?
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>
回答1:
Short answer: No. The slash is not permitted.
Long answer:
Section 3.3.1 of the XSD specification defines that the name attribute is
An NCName as defined by [XML-Namespaces].
This references the specification for Namespaces in XML which defines an NCName under section 2. Declaring Namespaces.
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.
回答2:
You can check if it is possible or not with tools like Oxygen XML Editor or another similar, wich will tell you all the errors in your XML file.
来源:https://stackoverflow.com/questions/26356101/can-we-use-special-character-in-xml-schema-element-name