當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.getRootElement方法代碼示例

本文整理匯總了Java中org.jdom2.Document.getRootElement方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.getRootElement方法的具體用法?Java Document.getRootElement怎麽用?Java Document.getRootElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jdom2.Document的用法示例。


在下文中一共展示了Document.getRootElement方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseXml

import org.jdom2.Document; //導入方法依賴的package包/類
public void parseXml(String fileName){
	SAXBuilder builder = new SAXBuilder();
	File file = new File(fileName);
	try {
		Document document = (Document) builder.build(file);
		Element rootNode = document.getRootElement();
		List list = rootNode.getChildren("author");
		for (int i = 0; i < list.size(); i++) {
			Element node = (Element) list.get(i);
			System.out.println("First Name : " + node.getChildText("firstname"));
			System.out.println("Last Name : " + node.getChildText("lastname"));
		}
	} catch (IOException io) {
		System.out.println(io.getMessage());
	} catch (JDOMException jdomex) {
		System.out.println(jdomex.getMessage());
	}



}
 
開發者ID:PacktPublishing,項目名稱:Java-Data-Science-Cookbook,代碼行數:22,代碼來源:TestJdom.java

示例2: checkSolrSchemaName

import org.jdom2.Document; //導入方法依賴的package包/類
private static boolean checkSolrSchemaName(Document doc) {
    if (doc != null) {
        Element eleRoot = doc.getRootElement();
        if (eleRoot != null) {
            String schemaName = eleRoot.getAttributeValue("name");
            if (StringUtils.isNotEmpty(schemaName)) {
                try {
                    if (schemaName.length() > SCHEMA_VERSION_PREFIX.length() && Integer.parseInt(schemaName.substring(SCHEMA_VERSION_PREFIX
                            .length())) >= SolrIndexerDaemon.MIN_SCHEMA_VERSION) {
                        return true;
                    }
                } catch (NumberFormatException e) {
                    logger.error("Schema version must contain a number.");
                }
                logger.error("Solr schema is not up to date; required: {}{}, found: {}", SCHEMA_VERSION_PREFIX, MIN_SCHEMA_VERSION, schemaName);
            }
        }
    } else {
        logger.error("Could not read the Solr schema name.");
    }

    return false;
}
 
開發者ID:intranda,項目名稱:goobi-viewer-indexer,代碼行數:24,代碼來源:SolrIndexerDaemon.java

示例3: cargarXml

import org.jdom2.Document; //導入方法依賴的package包/類
private void cargarXml() {
	SAXBuilder builder = new SAXBuilder();
	File xmlFile = new File(xml);
	try {
		Document document = (Document) builder.build(xmlFile);
		Element rootNode = document.getRootElement();
		List list = rootNode.getChildren("pokemon");

		for (int i = 0; i < list.size(); i++) {
			Element tabla = (Element) list.get(i);
			List lista_campos = tabla.getChildren();
			String name = null;
			int height = 0;
			int weight = 0;
			int baseExperience = 0;
			for (int j = 1; j <= 5; j++) {
				Element campo = (Element) lista_campos.get(j);
				if (j == 1) {
					name = campo.getText();
				} else if (j == 3) {
					height = Integer.valueOf(campo.getValue());
				} else if (j == 4) {
					weight = Integer.valueOf(campo.getValue());
				} else if (j == 5) {
					baseExperience = Integer.valueOf(campo.getValue());
				}

			}

			pokemons.add(new Pokemon(name, height, weight, baseExperience));

		}
	} catch (IOException io) {
		System.out.println(io.getMessage());
	} catch (JDOMException jdomex) {
		System.out.println(jdomex.getMessage());
	}
}
 
開發者ID:mistermboy,項目名稱:PokemonXMLFilter,代碼行數:39,代碼來源:XMLReader.java

示例4: updateCitationCount

import org.jdom2.Document; //導入方法依賴的package包/類
public Document updateCitationCount(Document doc) throws JDOMException, SAXException {
	Document newDoc = new Document();
	// extract DOI
	String doi = "";
	Element rootElement = doc.getRootElement();
	List<Element> children = rootElement.getChildren("identifier", MODS_NS);
	for (Element element : children) {
		List<Attribute> attributes = element.getAttributes();
		for (Attribute attribute : attributes) {
			if ("type".equals(attribute.getName()) && "doi".equals(attribute.getValue())) {
				doi = element.getValue();
			}
		}
	}
	// get Doc with new citation count
	try {
		newDoc = getPublicationByDOI(doi).asXML();
	} catch (IOException ex) {

	}

	// extract new citation count
	Element newRootElement = newDoc.getRootElement();
	Element newChild = newRootElement.getChild("extension", MODS_NS).getChild("sourcetext")
			.getChild("abstracts-retrieval-response", ELSEVIER_Namespace).getChild("coredata", ELSEVIER_Namespace)
			.getChild("citedby-count", ELSEVIER_Namespace);
	String newCitationCount = newChild.getValue();

	// replace old citation count
	Element child = rootElement.getChild("extension", MODS_NS).getChild("sourcetext")
			.getChild("abstracts-retrieval-response", ELSEVIER_Namespace).getChild("coredata", ELSEVIER_Namespace)
			.getChild("citedby-count", ELSEVIER_Namespace);
	child.setText(newCitationCount);

	return doc;

}
 
開發者ID:ETspielberg,項目名稱:bibliometrics,代碼行數:38,代碼來源:ScopusConnector.java

示例5: loadConfig

import org.jdom2.Document; //導入方法依賴的package包/類
/**
 * Load the configuration provided at <a href=
 * "https://github.com/mudrod/mudrod/blob/master/core/src/main/resources/config.xml">config.xml</a>.
 *
 * @return a populated {@link java.util.Properties} object.
 */
public Properties loadConfig() {
  SAXBuilder saxBuilder = new SAXBuilder();

  InputStream configStream = locateConfig();

  Document document;
  try {
    document = saxBuilder.build(configStream);
    Element rootNode = document.getRootElement();
    List<Element> paraList = rootNode.getChildren("para");

    for (int i = 0; i < paraList.size(); i++) {
      Element paraNode = paraList.get(i);
      String attributeName = paraNode.getAttributeValue("name");
      if (MudrodConstants.SVM_SGD_MODEL.equals(attributeName)) {
        props.put(attributeName, decompressSVMWithSGDModel(paraNode.getTextTrim()));
      } else {
        props.put(attributeName, paraNode.getTextTrim());
      }
    }
  } catch (JDOMException | IOException e) {
    LOG.error("Exception whilst retrieving or processing XML contained within 'config.xml'!", e);
  }
  return getConfig();

}
 
開發者ID:apache,項目名稱:incubator-sdap-mudrod,代碼行數:33,代碼來源:MudrodEngine.java

示例6: parse

import org.jdom2.Document; //導入方法依賴的package包/類
@Override
public InfoModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException {
    Element root = doc.getRootElement();

    String name = Node.fromRequiredChildOrAttr(root, "name").getValueNormalize();
    SemanticVersion version = XMLUtils.parseSemanticVersion(Node.fromRequiredChildOrAttr(root, "version"));
    MapDoc.Phase phase = XMLUtils.parseEnum(Node.fromLastChildOrAttr(root, "phase"), MapDoc.Phase.class, "phase", MapDoc.Phase.PRODUCTION);
    MapDoc.Edition edition = XMLUtils.parseEnum(Node.fromLastChildOrAttr(root, "edition"), MapDoc.Edition.class, "edition", MapDoc.Edition.STANDARD);

    // Allow multiple <objective> elements, so include files can provide defaults
    final BaseComponent objective = XMLUtils.parseLocalizedText(Node.fromRequiredLastChildOrAttr(root, "objective"));

    String slug = root.getChildTextNormalize("slug");
    BaseComponent game = XMLUtils.parseFormattedText(root, "game");

    MapDoc.Genre genre = XMLUtils.parseEnum(Node.fromNullable(root.getChild("genre")), MapDoc.Genre.class, "genre", MapDoc.Genre.OTHER);

    final TreeSet<MapDoc.Gamemode> gamemodes = new TreeSet<>();
    for(Element elGamemode : root.getChildren("gamemode")) {
        gamemodes.add(XMLUtils.parseEnum(elGamemode, MapDoc.Gamemode.class));
    }

    List<Contributor> authors = readContributorList(root, "authors", "author");

    if(game == null) {
        Element blitz = root.getChild("blitz");
        if(blitz != null) {
            Element title = blitz.getChild("title");
            if(title != null) {
                if(context.getProto().isNoOlderThan(ProtoVersions.REMOVE_BLITZ_TITLE)) {
                    throw new InvalidXMLException("<title> inside <blitz> is no longer supported, use <map game=\"...\">", title);
                }
                game = new Component(title.getTextNormalize());
            }
        }
    }

    List<Contributor> contributors = readContributorList(root, "contributors", "contributor");

    List<String> rules = new ArrayList<String>();
    for(Element parent : root.getChildren("rules")) {
        for(Element rule : parent.getChildren("rule")) {
            rules.add(rule.getTextNormalize());
        }
    }

    Difficulty difficulty = XMLUtils.parseEnum(Node.fromLastChildOrAttr(root, "difficulty"), Difficulty.class, "difficulty");

    Environment dimension = XMLUtils.parseEnum(Node.fromLastChildOrAttr(root, "dimension"), Environment.class, "dimension", Environment.NORMAL);

    boolean friendlyFire = XMLUtils.parseBoolean(Node.fromLastChildOrAttr(root, "friendly-fire", "friendlyfire"), false);

    return new InfoModule(new MapInfo(context.getProto(), slug, name, version, edition, phase, game, genre, ImmutableSet.copyOf(gamemodes), objective, authors, contributors, rules, difficulty, dimension, friendlyFire));
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:55,代碼來源:InfoModule.java

示例7: JDom2Reader

import org.jdom2.Document; //導入方法依賴的package包/類
/**
 * @since 1.4.5
 */
public JDom2Reader(final Document document) {
    super(document.getRootElement());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:7,代碼來源:JDom2Reader.java

示例8: parseTrafficMatrixSequence

import org.jdom2.Document; //導入方法依賴的package包/類
/**
 * Parse a traffic matrix file containing a sequence of traffic matrices
 *
 * @param trafficMatrixFile The name of the traffic matrix file
 * @return A <code>TrafficMatrixSequence</code>  object containing a
 * sequence of <code>TrafficMatrix</code> objects
 * @throws JDOMException If the XML file is badly formatted
 * @throws IOException If an error occurs while trying to read the file
 */
@SuppressWarnings("unused")
public static TrafficMatrixSequence parseTrafficMatrixSequence(
		String trafficMatrixFile) throws JDOMException, IOException {
	TrafficMatrixSequence trafficMatrixSequence = null;
	String timeUnit = null;
	int interval = -1;
	
	String name = null;
	String type = null;
	String value = null;

	SAXBuilder builder = new SAXBuilder();
	Document document = (Document) builder.build(trafficMatrixFile);
	Element rootNode = document.getRootElement();

	List<Element> properties = rootNode.getChildren("property");
	for (Element propertyElement: properties) {
		name = propertyElement.getAttributeValue("name");
		type = propertyElement.getAttributeValue("type");
		value = propertyElement.getTextTrim();
		if (name.equals("t_unit")) {
			timeUnit = value;
		} else if (name.equals("interval")) {
			interval = Integer.parseInt(value);
		} else {
			// If format is extended and new properties are added
			// put here the code to handle them
			continue;
		}
	}
	if (interval > 0 && timeUnit != null) {
		trafficMatrixSequence = new TrafficMatrixSequence(
				interval, timeUnit);
	} else {
		trafficMatrixSequence = new TrafficMatrixSequence();
	}
	List<Element> trafficMatrices = rootNode.getChildren("time");
	for (Element tmElement: trafficMatrices) {
		String volumeUnit = null;
		List<Element> tmProperties = tmElement.getChildren("property");
		for (Element tmPropertyElement: tmProperties) {
			name = tmPropertyElement.getAttributeValue("name");
			type = tmPropertyElement.getAttributeValue("type");
			value = tmPropertyElement.getTextTrim();
			if (name.equals("volume_unit")) {
				volumeUnit = value;
			} else {
				// If format is extended and new properties are added
				// put here the code to handle them
				continue;
			}
		}
		if(volumeUnit == null) {
			throw new JDOMException("The traffic matrix does not have " +
									 "a volume_unit attribute");
		}
		TrafficMatrix trafficMatrix = new TrafficMatrix(volumeUnit);
		List<Element> origins = tmElement.getChildren("origin");
		for (Element originElement: origins) {
			String o = originElement.getAttributeValue("id");
			List<Element> destinations = originElement.getChildren("destination");
			for (Element destinationElement: destinations) {
				String d = destinationElement.getAttributeValue("id");
				float load = Float.parseFloat(destinationElement.getValue());
				trafficMatrix.addFlow(o, d, load);
			}
		}
		trafficMatrixSequence.addMatrix(trafficMatrix);
	}
	return trafficMatrixSequence;
}
 
開發者ID:fnss,項目名稱:fnss-java,代碼行數:81,代碼來源:Parser.java


注:本文中的org.jdom2.Document.getRootElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。