Here you can find the source of getRootElement(Document d)
Parameter | Description |
---|---|
d | a parameter |
public static Element getRootElement(Document d)
//package com.java2s; /**//from ww w . j av a 2 s .c om * * This file is part of SavoyCraft. * * SavoyCraft 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, either version 3 of the License, or (at your * option) any later version. * * SavoyCraft 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 Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with SavoyCraft. If not, see <http://www.gnu.org/licenses/>. * */ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * If first node found is not an element, returns null. * @param d * @return the root element, or null if d is null or a root element is not * found */ public static Element getRootElement(Document d) { if (d == null) { return null; } NodeList list = d.getChildNodes(); if (list.getLength() <= 0) { return null; } else { Node n = list.item(0); if (n instanceof Element) { return (Element) n; } else { return null; } } } }