- From: <w3t-archive+esw-wiki@w3.org>
- Date: Tue, 12 Jul 2005 17:08:03 -0000
- To: w3t-archive+esw-wiki@w3.org
Dear Wiki user, You have subscribed to a wiki page or wiki category on "ESW Wiki" for change notification. The following page has been changed by 12.173.168.199: http://esw.w3.org/topic/geoFAQxmllang ------------------------------------------------------------------------------ = xml:lang in XML document schemas = - When should I use xml:lang in an XML document schema (DTD) and when should I define my own element or attribute for passing language values? + When should I use ''xml:lang'' and when should I define my own element or attribute for passing language values in an XML document schema (DTD)? == Answer == - XML 1.0 defines a common attribute ''xml:lang'' which indicates the natural language of the content of an element. That is, the best application of xml:lang should be to identify the language of text or other content (including embedded objects such as an image or sound file) contained by the element. The xml:lang value applies to any sub-elements contained by the element. Attribute values associated with the element and its descendant elements also are associated with the xml:lang (though using natural language in attributes is '''not''' best practice). + Sometimes documents contain or reference different types of natural language content. Other times they need to describe natural language as a value in a data structure. Because there are different ways of referencing natural languages in XML documents, users are sometimes confused whether they should use ''xml:lang'' or define their own language-related element or attribute. - Sometimes you need to convey a language as an information item of its own. For example, if you created an XML document describing your DVD collection, you might want an element to indicate what languages are available on the soundtrack portion of each item. In this case you want to have an element or attribute whose ''value'' is a language. You still want to use RFC 3066 (or its successor) to form the value, but you should define an element or attribute of your own with a different name and not use the xml:lang attribute. + === When to use ''xml:lang'' === + XML 1.0 defines a common attribute ''xml:lang'' which indicates the natural language of the content of an element using the language tags defined by RFC 3066 or its successor. That is, the ''xml:lang'' identifies the language of text or other content (including embedded objects such as an image or sound file) contained by the element. The ''xml:lang'' value applies to any sub-elements contained by the element. Attribute values associated with the element and its descendant elements also are associated with the ''xml:lang'' (though using natural language in attributes is '''not''' best practice). Thus ''xml:lang'' is used to indicate the language of some content in or referenced by an XML document. + - For example, in XHTML 1.0, there is an hreflang attribute in the <a> element and also an xml:lang (or lang attribute, in the case of HTML) for the content of the <a> element: + For example, in XHTML 1.0, there is an ''hreflang'' attribute in the <a> element and also an ''xml:lang'' (or ''lang'' attribute, in the case of HTML) for the content of the <a> element: {{{<a xml:lang="en" href="xyz" hreflang="de"> Click for German </a>}}} - A different example from XHTML 1.0 shows how ''xml:lang'' applies to an attribute: + In this example, the text inside the <a> element is identified as being in English (xml:lang="en"). A different example from XHTML 1.0 shows how ''xml:lang'' applies to an attribute: {{{<abbr title="radio detection and ranging" xml:lang="en"> RADAR </abbr>}}} - This is a good example of why applying ''xml:lang'' to an attribute is not desirable: there is no way to supply more than one language of the {{{title}}} attribute. + This is a good example of why applying ''xml:lang'' to an attribute is not desirable: there is no way to supply more than one language of the {{{title}}} attribute! + === When to use your own element or attribute === + + Sometimes you need to convey a language as an information item of its own. For example, if you created an XML document describing your DVD collection, you might want an element to indicate what languages are available on the soundtrack portion of each disc. Or if you were creating a customer database, you might have a field for the customer's language preference. In these cases you want to store the language ''value'' as an element or attribute. You still want to use RFC 3066 (or its successor) to form the value, but you should define an element or attribute of your own with a different name and not use the ''xml:lang'' attribute. This is because the item you are describing is not a piece of content in or referenced directly by the XML document. Instead it is data or meta-data related to that item. + - For example, your XML might look like: + For example, an XML document might look like this: {{{<item> <title xml:lang="en">Casablanca</title> <!-- indicates the language of of the text 'Casablanca' --> @@ -45, +51 @@ <subtitles track="1" language="zh-Hant" /> <subtitles track="2" language="zh-Hans" /> </item>}}} + + In this example, the ''xml:lang'' attribute conveys information about the natural language of text appearing in this document. The ''language'' attribute is defined in the XML document schema for the elements <dialogue> and <subtitles> and conveys a natural language ''value'' associated with these elements. For example, it conveys the information that the subtitles on Track #1 are written or displayed in Traditional Chinese ("zh-Hant"). In addition, while it is possible to define your own formats for all the various values that you need, it is sometimes helps interoperability to define formats using a shared vocabulary, such as XML Schema. XML Schema provides a type for language values (xsi:language) which is defined using RFC 3066.
Received on Tuesday, 12 July 2005 19:33:46 UTC