org.jdom2.Element.getAttributeValue()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中org.jdom2.Element.getAttributeValue()方法的一些代码示例,展示了Element.getAttributeValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getAttributeValue()方法的具体详情如下:
包路径:org.jdom2.Element
类名称:Element
方法名:getAttributeValue

Element.getAttributeValue介绍

[英]This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
[中]这将返回具有给定名称且不在任何命名空间内的属性的属性值,如果没有此类属性,则返回null,如果属性值为空,则返回空字符串。

代码示例

代码示例来源:origin: gocd/gocd

private Modification parseLogEntry(Element logEntry, String path) throws ParseException {
  Element logEntryPaths = logEntry.getChild("paths");
  if (logEntryPaths == null) {
    /* Path-based access control forbids us from learning
     * details of this log entry, so skip it. */
    return null;
  }
  Date modifiedTime = convertDate(logEntry.getChildText("date"));
  String author = logEntry.getChildText("author");
  String comment = logEntry.getChildText("msg");
  String revision = logEntry.getAttributeValue("revision");
  Modification modification = new Modification(author, comment, null, modifiedTime, revision);
  List paths = logEntryPaths.getChildren("path");
  for (Iterator iterator = paths.iterator(); iterator.hasNext();) {
    Element node = (Element) iterator.next();
    if (underPath(path, node.getText())) {
      ModifiedAction action = convertAction(node.getAttributeValue("action"));
      modification.createModifiedFile(node.getText(), null, action);
    }
  }
  return modification;
}

代码示例来源:origin: gocd/gocd

public CommandSnippet parse(String xmlContent, String fileName, String relativeFilePath) {
  try {
    Document document = buildXmlDocument(xmlContent, CommandSnippet.class.getResource("command-snippet.xsd"));
    CommandSnippetComment comment = getComment(document);
    Element execTag = document.getRootElement();
    String commandName = execTag.getAttributeValue("command");
    List<String> arguments = new ArrayList<>();
    for (Object child : execTag.getChildren()) {
      Element element = (Element) child;
      arguments.add(element.getValue());
    }
    return new CommandSnippet(commandName, arguments, comment, fileName, relativeFilePath);
  } catch (Exception e) {
    String errorMessage = String.format("Reason: %s", e.getMessage());
    LOGGER.info("Could not load command '{}'. {}", fileName, errorMessage);
    return CommandSnippet.invalid(fileName, errorMessage, new EmptySnippetComment());
  }
}

代码示例来源:origin: geotools/geotools

public void assignTo(Element element) {
  if (!element.getName().equals(GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME)) {
    throw new IllegalArgumentException(
        "root not found: " + GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME);
  }
  final Element ifd1 = element.getChild(GeoTiffConstants.GEOTIFF_IFD_TAG);
  if (ifd1 == null) {
    throw new IllegalArgumentException(
        "Unable to find child " + GeoTiffConstants.GEOTIFF_IFD_TAG);
  }
  final Element ifd2 = createIFD();
  ifd1.setAttribute(
      GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME,
      ifd2.getAttributeValue(GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME));
  final Element[] childElems = (Element[]) ifd2.getChildren().toArray(new Element[0]);
  for (int i = 0; i < childElems.length; i++) {
    final Element child = childElems[i];
    ifd2.removeContent(child);
    ifd1.addContent(child);
  }
}

代码示例来源:origin: Unidata/thredds

protected Optional<Boolean> readSort(Element sorterElem) {
 Element lexSortElem = sorterElem.getChild("lexigraphicByName", Catalog.defNS);
 if (lexSortElem != null) {
  String increasingString = lexSortElem.getAttributeValue("increasing");
  if (increasingString != null) {
   if (increasingString.equalsIgnoreCase("true"))
    return Optional.of(true);
   else if (increasingString.equalsIgnoreCase("false"))
    return Optional.of(false);
  }
 }
 return Optional.empty();
}

代码示例来源:origin: jpos/jPOS-EE

/**
 * Parses a JDOM Element as defined in
 * <a href="http://jpos.org/minigl.dtd">minigl.dtd</a>
 */
public void fromXML (Element elem) throws ParseException {
  setDetail (elem.getChildTextTrim ("detail"));
  setTags   (new Tags(elem.getChildTextTrim ("tags")));
  setCredit ("credit".equals (elem.getAttributeValue("type")));
  setLayer(toShort(elem.getAttributeValue("layer")));
  setAmount(new BigDecimal (elem.getChild ("amount").getText()));
}
/**

代码示例来源:origin: net.preibisch/multiview-reconstruction

public PointSpreadFunctions fromXml( final Element allPSFs, final File basePath ) throws SpimDataException
{
  final PointSpreadFunctions pointSpreadFunctions = super.fromXml( allPSFs );
  for ( final Element psfElement : allPSFs.getChildren( PSF_TAG ) )
  {
    final int tpId = Integer.parseInt( psfElement.getAttributeValue( PSF_TIMEPOINT_ATTRIBUTE_NAME ) );
    final int vsId = Integer.parseInt( psfElement.getAttributeValue( PSF_SETUP_ATTRIBUTE_NAME ) );
    final String file = psfElement.getChildText( PSF_FILE_TAG );
    pointSpreadFunctions.addPSF( new ViewId( tpId, vsId ), new PointSpreadFunction( basePath, file ) );
  }
  return pointSpreadFunctions;
}

代码示例来源:origin: jwpttcg66/NettyGameServer

public MessageObject(Element element){
  this.comment = element.getAttributeValue("comment");
  this.namespace = element.getAttributeValue("javaPackage");
  this.className = element.getAttributeValue("name");
  this.importPackage = element.getAttributeValue("importPackage");
  this.cmdType = element.getAttributeValue("cmdType");
  this.vm = element.getAttributeValue("vm");
  for(Element child : element.getChildren()){
    fieldList.add(new FieldObject(child));
  }
}

代码示例来源:origin: Transitime/core

private static GtfsRoute getGtfsRoute(Document doc) {
  // Get the params from the XML doc
  Element rootNode = doc.getRootElement();
  Element route = rootNode.getChild("route");
  String routeId = route.getAttributeValue("tag");
  String title = route.getAttributeValue("title");
  String color = route.getAttributeValue("color");
  String oppositeColor = route.getAttributeValue("oppositeColor");
  
  // Create and return the GtfsRoute
  GtfsRoute gtfsRoute = new GtfsRoute(routeId, 
      agencyId.getValue(), null, title, 
      gtfsRouteType.getValue(), color, oppositeColor);
  return gtfsRoute;
}

代码示例来源:origin: edu.ucar/netcdf

void check(Element e, Indent indent) {
 String name = e.getName();
 if (name.equals("beanObject")) {
  String key = e.getAttributeValue("key");
  Element obj = e.getChild("object");
  assert obj != null;
  String c = obj.getAttributeValue("class");
  System.out.printf("%s%s key=%s class=%s%n", indent, name, key, c);
 }
  for (Object co : e.getChildren())
   check((Element)co,indent);
}

代码示例来源:origin: org.mycore/mycore-orcid

/** Sets the work's properties from the pre-processed, transformed works XML */
private void setFromWorkXML(MCRWork work, Element workXML) {
  Element mods = workXML.getChild("mods", MCRConstants.MODS_NAMESPACE).detach();
  String bibTeX = workXML.getChildTextTrim("bibTeX");
  Optional<Element> modsFromBibTeX = bibTeX2MODS(bibTeX);
  modsFromBibTeX.ifPresent(m -> MCRMergeTool.merge(mods, m));
  work.setMODS(mods);
  String sourceID = workXML.getAttributeValue("source");
  work.setSource(MCRWorkSource.getInstance(sourceID));
  if (work.getSource().isThisApplication()) {
    String oid = workXML.getAttributeValue("oid");
    work.setObjectID(MCRObjectID.getInstance(oid));
  }
}

代码示例来源:origin: jwpttcg66/NettyGameServer

public MacroObject(Element element){
  this.className = element.getAttributeValue("name");
  this.namespace = element.getAttributeValue("javaPackage");
  this.comment = element.getAttributeValue("comment");
  this.vm = element.getAttributeValue("vm");
  for(Element child : element.getChildren()){
    fieldList.add(new FieldObject(child));
  }
  
  allMacros.put(this.className, this);
}

代码示例来源:origin: rometools/rome

/**
 * @param e element to parse
 * @param md metadata to fill in
 */
private void parseRights(final Element e, final Metadata md) {
  final Element rightsElement = e.getChild("rights", getNS());
  if (rightsElement != null && rightsElement.getAttributeValue("status") != null) {
    md.setRights(RightsStatus.valueOf(rightsElement.getAttributeValue("status")));
  }
}

代码示例来源:origin: Renanse/Ardor3D

public void unbindMaterials(final Element bindMaterial) {
  if (bindMaterial == null || bindMaterial.getChildren().isEmpty()) {
    return;
  }
  for (final Element instance : bindMaterial.getChild("technique_common").getChildren("instance_material")) {
    _dataCache.unbindMaterial(instance.getAttributeValue("symbol"));
  }
}

代码示例来源:origin: com.theoryinpractise/halbuilder-xml

private void readLinks(Representation resource, Element element) {
  List<Element> links = element.getChildren("link");
  for (Element link : links) {
    String rel = link.getAttributeValue(REL);
    String href = link.getAttributeValue(HREF);
    String name = link.getAttributeValue(NAME);
    String title = link.getAttributeValue(TITLE);
    String hreflang = link.getAttributeValue(HREFLANG);
    String profile = link.getAttributeValue(PROFILE);
    resource.withLink(rel, href, name, title, hreflang, profile);
  }
}

代码示例来源:origin: rometools/rome

@Override
  public Module parse(final Element element, final Locale locale) {
    final ThreadingModule tm = new ThreadingModuleImpl();
    Element inReplyTo = element.getChild("in-reply-to", ThreadingModuleParser.NS);

    if (inReplyTo != null) {
      tm.setHref(inReplyTo.getAttributeValue("href"));
      tm.setRef(inReplyTo.getAttributeValue("ref"));
      tm.setSource(inReplyTo.getAttributeValue("source"));
      tm.setType(inReplyTo.getAttributeValue("type"));
      return tm;
    }

    return null;
  }
}

代码示例来源:origin: Renanse/Ardor3D

public void bindMaterials(final Element bindMaterial) {
  if (bindMaterial == null || bindMaterial.getChildren().isEmpty()) {
    return;
  }
  for (final Element instance : bindMaterial.getChild("technique_common").getChildren("instance_material")) {
    final Element matNode = _colladaDOMUtil.findTargetWithId(instance.getAttributeValue("target"));
    if (matNode != null && "material".equals(matNode.getName())) {
      _dataCache.bindMaterial(instance.getAttributeValue("symbol"), matNode);
    } else {
      logger.warning("instance material target not found: " + instance.getAttributeValue("target"));
    }
    // TODO: need to store bound vert data as local data. (also unstore on unbind.)
  }
}

代码示例来源:origin: jpos/jPOS

private Map loadProperties(Element elem) {
  Map props = new HashMap ();
  for (Element prop : elem.getChildren ("property")) {
    String name = prop.getAttributeValue ("name");
    String value = prop.getAttributeValue ("value");
    props.put (name, value);
  }
  return props;
}

代码示例来源:origin: edu.ucar/cdm

private void readSelector(Element elem, Selector s) {
 s.setTitle(elem.getAttributeValue("title"));
 s.setId(elem.getAttributeValue("id"));
 s.setTemplate(elem.getAttributeValue("template"));
 s.setRequired(elem.getAttributeValue("required"));
 s.setMultiple(elem.getAttributeValue("multiple"));
 Element descElem = elem.getChild("description", defNS);
 if (descElem != null)
  s.setDescription(readDocumentation(descElem));
}

代码示例来源:origin: Unidata/thredds

protected ThreddsMetadata.GeospatialCoverage readGeospatialCoverage(Element gcElem) {
 if (gcElem == null) return null;
 String zpositive = gcElem.getAttributeValue("zpositive");
 ThreddsMetadata.Range northsouth = readGeospatialRange(gcElem.getChild("northsouth", defNS), CDM.LAT_UNITS);
 ThreddsMetadata.Range eastwest = readGeospatialRange(gcElem.getChild("eastwest", defNS), CDM.LON_UNITS);
 ThreddsMetadata.Range updown = readGeospatialRange(gcElem.getChild("updown", defNS), "m");
 // look for names
 List<ThreddsMetadata.Vocab> names = new ArrayList<>();
 java.util.List<Element> list = gcElem.getChildren("name", defNS);
 for (Element e : list) {
  ThreddsMetadata.Vocab name = readControlledVocabulary(e);
  names.add(name);
 }
 return new ThreddsMetadata.GeospatialCoverage(eastwest, northsouth, updown, names, zpositive);
}

代码示例来源:origin: com.cerner.ccl.whitenoise/whitenoise-rules-core

private String constructName(final Element headOrFoot) {
  if (headOrFoot.getName().equalsIgnoreCase("NAME")) {
    return headOrFoot.getAttributeValue("text");
  }
  String name = "";
  for (final Element nameElement : headOrFoot.getChildren()) {
    if (name.equalsIgnoreCase(""))
      name = nameElement.getAttributeValue("text");
    else
      name = name + "." + nameElement.getAttributeValue("text");
  }
  return name;
}

相关文章

微信公众号

最新文章

更多