How to allow xml:lang attribute in XMLSchema?

限于喜欢 提交于 2019-12-23 17:46:38

问题


I want to allow the use of xml:lang attributes in some of my element of my XMLSchema. But i can't find anything which describes how to to it. Yeah, my question is simple as that.


回答1:


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.




回答2:


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="http://www.w3.org/2001/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>


来源:https://stackoverflow.com/questions/7502382/how-to-allow-xmllang-attribute-in-xmlschema

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