本文整理汇总了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());
}
}
示例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;
}
示例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());
}
}
示例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;
}
示例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();
}
示例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));
}
示例7: JDom2Reader
import org.jdom2.Document; //导入方法依赖的package包/类
/**
* @since 1.4.5
*/
public JDom2Reader(final Document document) {
super(document.getRootElement());
}
示例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;
}