How to allow xml:lang attribute in XMLSchema?
I want to allow the use of xml:lang attributes in some of my element of my XMLSchema. But i can't find a开发者_StackOverflow中文版nything which describes how to to it.
You have to do a bit of hunting to piece this together from the standards. Here's the magic sauce you need in order to allow xml:lang
attributes on your XML elements.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Import xml: namespace -->
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="https://www.w3.org/2009/01/xml.xsd" />
<!-- ... --->
<xs:complexType name="myLanguagedElement">
<!-- ... -->
<!-- use ref="" instead of name="", here in your attribute -->
<xs:attribute ref="xml:lang" use="optional" /><!-- or "required" if you like -->
</xs:complexType>
</xs:schema>
Edit: The new schemaLocation changed to https://www.w3.org/2009/01/xml.xsd
You can either create your own attribute with xmlschema type language, or reference xml:lang attribute as in the example Import another XML schema. I hope this will help.
精彩评论