Java XML Element Get getElementLanguage(Element elemNode, String defaultLangCode)

Here you can find the source of getElementLanguage(Element elemNode, String defaultLangCode)

Description

Returns the language code associated with the specified element.

License

Open Source License

Parameter

Parameter Description
elemNode The whose language value is to be returned.
defaultLangCode The default language code to return if there is no explicit language code.

Declaration

public static String getElementLanguage(Element elemNode,
        String defaultLangCode) 

Method Source Code

//package com.java2s;
/*--------------------------------------------------------------------------------
 Copyright (C) 2002, 2004 ISOGEN International

 http://www.isogen.com/*from   www  . j a va  2  s .  co m*/

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU Lesser General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 --------------------------------------------------------------------------------*/

import org.w3c.dom.Element;

public class Main {
    static String langAttName = "language";

    /**
     * Returns the language code associated with the specified element.
     * 
     * @param elemNode The whose language value is to be returned.
     * @param defaultLangCode The default language code to return if
     * there is no explicit language code.
     */
    public static String getElementLanguage(Element elemNode,
            String defaultLangCode) {
        String langCode = defaultLangCode;
        if (elemNode.hasAttribute(langAttName)) {
            langCode = elemNode.getAttribute(langAttName);
        } else if (elemNode.hasAttributeNS("xml", "lang")) {
            langCode = elemNode.getAttributeNS("xml", "lang");
        }
        return langCode;
    }
}

Related

  1. getElementForLine(Document document, int line)
  2. getElementId(Element element)
  3. getElementIndex(Element ele)
  4. getElementIndex(Element element)
  5. getElementLanguage(Element elemNode, String defaultLangCode)
  6. getElementList(Document doc, String expression)
  7. getElementList(Element dataRoot, String name)
  8. getElementList(Element dataRoot, String name)
  9. getElementList(Element element)