org.jdom2.Attribute类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(169)

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

Attribute介绍

[英]An XML attribute. Methods allow the user to obtain the value of the attribute as well as namespace and type information.

JDOM 1.x Compatibility Note:
The Attribute class in JDOM 1.x had a number of int Constants declared to represent different Attribute Types. JDOM2 has introduced an AttributeType enumeration instead. To facilitate compatibility and to simplify JDOM 1.x migrations, the replacement AttributeType enums are referenced still using the JDOM 1.x constant names. In JDOM 1.x these names referenced constant int values. In JDOM2 these names reference Enum constants.
[中]XML属性。方法允许用户获取属性值以及名称空间和类型信息。
jdom1。x兼容性说明:
JDOM 1中的属性类。x声明了许多int常量来表示不同的属性类型。JDOM2引入了AttributeType枚举。为了促进兼容性和简化JDOM 1。在x迁移中,仍然使用JDOM 1引用替换的AttributeType枚举。x常量名称。在jdom1中。这些名称引用了常量int值。在JDOM2中,这些名称引用枚举常量。

代码示例

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

public void parse() {
  if (isImplicitCollection()) {
    Object val = GoConfigClassLoader.classParser(e, field.getType(), configCache, new GoCipher(), registry, configReferenceElements).parseImplicitCollection();
    setValue(val);
  } else if (isSubtag(field)) {
    Object val = subtagParser(e, field, configCache, registry, configReferenceElements).parse();
    setValue(val);
  } else if (isAttribute(field)) {
    Object val = attributeParser(e, field).parse(defaultValue());
    setValue(val);
  } else if (isConfigValue()) {
    Object val = e.getText();
    setValue(val);
  } else if (isAnnotationPresent(field, ConfigReferenceElement.class)) {
    ConfigReferenceElement referenceField = field.getAnnotation(ConfigReferenceElement.class);
    Attribute attribute = e.getAttribute(referenceField.referenceAttribute());
    if (attribute == null) {
      bomb(String.format("Expected attribute `%s` to be present for %s.", referenceField.referenceAttribute(), e.getName()));
    }
    String refId = attribute.getValue();
    Object referredObject = configReferenceElements.get(referenceField.referenceCollection(), refId);
    setValue(referredObject);
  }
}

代码示例来源:origin: simpligility/android-maven-plugin

@SuppressWarnings( "unchecked" )
private void appendElement( Element source, Element target )
{
  for ( Iterator<Attribute> itr = source.getAttributes().iterator(); itr.hasNext(); )
  {
    Attribute a = itr.next();
    itr.remove();
    Attribute mergedAtt = target.getAttribute( a.getName(), a.getNamespace() );
    if ( mergedAtt == null )
    {
      target.setAttribute( a );
    }
  }
  for ( Iterator<Element> itr = source.getChildren().iterator(); itr.hasNext(); )
  {
    Content n = itr.next();
    itr.remove();
    target.addContent( n );
  }
}

代码示例来源:origin: org.jdom/jdom

/**
 * <p>
 * This sets an attribute value for this element.  Any existing attribute
 * with the same name and namespace URI is removed.
 * </p>
 *
 * @param name name of the attribute to set
 * @param value value of the attribute to set
 * @return this element modified
 * @throws IllegalNameException if the given name is illegal as an
 *         attribute name.
 * @throws IllegalDataException if the given attribute value is
 *         illegal character data (as determined by
 *         {@link org.jdom2.Verifier#checkCharacterData}).
 */
public Element setAttribute(final String name, final String value) {
  final Attribute attribute = getAttribute(name);
  if (attribute == null) {
    final Attribute newAttribute = new Attribute(name, value);
    setAttribute(newAttribute);
  } else {
    attribute.setValue(value);
  }
  return this;
}

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

List<Element> encryptedPasswordElements = xpathExpression.evaluate(document);
for (Element element : encryptedPasswordElements) {
  Attribute encryptedPassword = element.getAttribute(attributeName);
  encryptedPassword.setValue(reEncryptUsingNewKey(decodeHex(oldCipher), decodeHex(newCipher), encryptedPassword.getValue()));
  LOGGER.debug("Replaced encrypted value at {}", element.toString());
List<Element> encryptedNode = xpathExpression.evaluate(document);
for (Element element : encryptedNode) {
  element.setText(reEncryptUsingNewKey(decodeHex(oldCipher), decodeHex(newCipher), element.getValue()));
  LOGGER.debug("Replaced encrypted value at {}", element.toString());

代码示例来源:origin: org.jdom/jdom

@Override
public final String getAttributeQName(Object att) {
  Attribute attribute = (Attribute)att;
  if (attribute.getNamespacePrefix().length() == 0) {
    return attribute.getName();
  }
  return attribute.getNamespacePrefix() + ":" + attribute.getName();
}

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

@Override
public boolean isMyType(final Document document) {
  final Element rssRoot = document.getRootElement();
  final Attribute version = rssRoot.getAttribute("version");
  return rssRoot.getName().equals("rss") && version != null && version.getValue().equals(getRSSVersion());
}

代码示例来源:origin: ch.epfl.bbp.nlp/bluima_xml

Element rootNode = doc.getRootElement();
Iterator<Element> cs = rootNode.getChildren().iterator();
while (cs.hasNext()) {
  Element concept = cs.next();
  String id = concept.getAttributeValue("brainInfoID");
  String canonical = concept.getAttributeValue("standardName");
  canonical = canonical.replaceAll("\\(.*\\)$", "").trim();
  List<Element> variants = concept.getChild("synonyms").getChildren();
  for (Element variant : variants) {
    if (variant.getAttribute("synonymLanguage").getValue()
        .matches("Latin|English")) {

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

protected Element generateSourceElement(final Source source) {
  final Element sourceElement = new Element("source", getFeedNamespace());
  final String url = source.getUrl();
  if (url != null) {
    sourceElement.setAttribute(new Attribute("url", url));
  }
  sourceElement.addContent(source.getValue());
  return sourceElement;
}

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

final Attribute typeAttribute = new Attribute("type", type);
contentElement.setAttribute(typeAttribute);
final Attribute modeAttribute = new Attribute("mode", mode);
contentElement.setAttribute(modeAttribute);
  contentElement.addContent(value);
  final List<org.jdom2.Content> children = tmpDoc.getRootElement().removeContent();
  contentElement.addContent(children);

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

static public FeatureDataset factory(FeatureType wantFeatureType, String endpoint) throws IOException {
 if (endpoint.startsWith(SCHEME))
  endpoint = endpoint.substring(SCHEME.length());
 Document doc = getCapabilities(endpoint);
 Element root = doc.getRootElement();
 Element elem = root.getChild("featureDataset");
 String fType = elem.getAttribute("type").getValue();  // LOOK, may be multiple types
 String uri = elem.getAttribute("url").getValue();
 if (debug) System.out.printf("CdmrFeatureDataset endpoint %s%n ftype= %s url=%s%n", endpoint, fType, uri);
 FeatureType ft = FeatureType.getType(fType);
 if (ft == null || ft == FeatureType.NONE || ft == FeatureType.GRID) {
  CdmRemote ncremote = new CdmRemote(uri);
  NetcdfDataset ncd = new NetcdfDataset(ncremote, null);
  return new GridDataset(ncd);
 } else {
  List<VariableSimpleIF> dataVars = FeatureDatasetPointXML.getDataVariables(doc);
  LatLonRect bb = FeatureDatasetPointXML.getSpatialExtent(doc);
  CalendarDateRange dr = FeatureDatasetPointXML.getTimeSpan(doc);
  return new PointDatasetRemote(ft, uri, dataVars, bb, dr);
 }
}

代码示例来源:origin: pwm-project/pwm

for ( final Element propertyElement : propertyElements )
  propertyElement.detach();
final Element propertyElement = new Element( XML_ELEMENT_PROPERTY );
propertyElement.setAttribute( new Attribute( XML_ATTRIBUTE_KEY, propertyName.getKey() ) );
propertyElement.setContent( new Text( value ) );
  final Element configProperties = new Element( XML_ELEMENT_PROPERTIES );
  configProperties.setAttribute( new Attribute( XML_ATTRIBUTE_TYPE, XML_ATTRIBUTE_VALUE_CONFIG ) );
  document.getRootElement().addContent( configProperties );

代码示例来源:origin: pwm-project/pwm

final Element rootElement = doc.getRootElement();
for ( final Element hrElement : rootElement.getChildren( XML_NODE_RECORD ) )
  final long timeStamp = hrElement.getAttribute( XML_ATTR_TIMESTAMP ).getLongValue();
  final String transactionCode = hrElement.getAttribute( XML_ATTR_TRANSACTION ).getValue();
  final AuditEvent eventCode = AuditEvent.forKey( transactionCode );
  final String srcAddr = hrElement.getAttribute( XML_ATTR_SRC_IP ) != null ? hrElement.getAttribute( XML_ATTR_SRC_IP ).getValue() : "";
  final String srcHost = hrElement.getAttribute( XML_ATTR_SRC_HOST ) != null ? hrElement.getAttribute( XML_ATTR_SRC_HOST ).getValue() : "";
  final String message = hrElement.getText();
  final StoredEvent storedEvent = new StoredEvent( eventCode, timeStamp, message, srcAddr, srcHost );

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

@Override
protected Element createRootElement(final Channel channel) {
  final Element root = new Element("rss", getFeedNamespace());
  final Attribute version = new Attribute("version", getVersion());
  root.setAttribute(version);
  root.addNamespaceDeclaration(getContentNamespace());
  generateModuleNamespaceDefs(root);
  return root;
}

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

/** Deserialize a Atom workspace XML element into an object */
protected void parseWorkspaceElement(final Element element, final String baseURI) throws ProponoException {
  final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT);
  setTitle(titleElem.getText());
  if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) {
    setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue());
  }
  final List<Element> collections = element.getChildren("collection", AtomService.ATOM_PROTOCOL);
  for (final Element e : collections) {
    addCollection(new ClientCollection(e, this, baseURI));
  }
}

代码示例来源:origin: com.github.marcosemiao.tomcat.maven.plugin/tomcat-manager-core

final SAXBuilder sxb = new SAXBuilder();
  document = sxb.build(fichierContext);
  context = document.getRootElement();
} else {
  LOG.debug("Le fichier context n'existe pas dans la webapps : {}.", fichierContext.getAbsolutePath());
  context = new Element("Context");
  document = new Document(context);
final Attribute docBase = new Attribute("docBase", webappDirectory.getAbsolutePath());
final Attribute workDir = new Attribute("workDir", webappDirectory.getAbsolutePath() + "-workDir");
context.setAttribute(docBase);
context.setAttribute(workDir);

代码示例来源:origin: vasl-developers/vasl

for(Element e: element.getChildren()) {
  if(e.getName().equals(colorElement)){
    String name = e.getAttributeValue(colorNameAttribute);
    String terrain = e.getAttributeValue(colorTerrainAttribute);
    String elevation = e.getAttributeValue(colorElevationAttribute);
        e.getAttribute(colorRedAttribute).getIntValue(),
        e.getAttribute(colorGreenAttribute).getIntValue(),
        e.getAttribute(colorBlueAttribute).getIntValue()
    );

代码示例来源:origin: org.jdom/jdom

if (element.hasAttributes()) {
  for (Attribute a : element.getAttributes()) {
    if (!a.isSpecified() && fstack.isSpecifiedAttributesOnly()) {
      continue;
    atts.addAttribute(a.getNamespaceURI(), a.getName(),
        a.getQualifiedName(),
        getAttributeTypeName(a.getAttributeType()),
        a.getValue());
ch.startElement(element.getNamespaceURI(), element.getName(),
    element.getQualifiedName(), atts);

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

private boolean versionMatches(final Document document) {
  final Attribute version = document.getRootElement().getAttribute("version");
  return (version != null)
      && version.getValue().trim().startsWith(getRSSVersion());
}

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

/**
 * A convienience function used for displaying information in _Debug mode.
 * Prints an XML element's name, content (if any) and Attributes to
 * System.out
 */
private void showXMLElement(Element e, String indent) {
  System.out.print(parseLevel + indent + "Element: " + e.getName() + "  ");
  String text = e.getTextNormalize();
  if (!text.equals(""))
    System.out.print(" = " + text + "   ");
  //System.out.println("");
 for (Attribute att : e.getAttributes()) {
  //System.out.print(parseLevel + indent + "    ");
  System.out.print(att.getName() + ": " + att.getValue() + "  ");
 }
  System.out.println("");
 for (Element kid : e.getChildren()) {
  showXMLElement(kid, indent + "    ");
 }
}

代码示例来源:origin: org.openfuxml/ofx-util

private Element loadElement(String resourceName) throws OfxAuthoringException
{
  try
  {
    InputStream is = mrl.searchIs(resourceName);
    org.jdom2.Document doc = JDomUtil.load(is);
    Element root = doc.getRootElement();
    
    List<Element> list = build().evaluate(root);
    logger.debug("Now processing childs: "+list.size());
    for(Element childElement : list)
    {
      String source = childElement.getAttribute("include").getValue();
      String resourceChild = FilenameUtils.getFullPath(resourceName)+source;
      logger.debug("Found external in "+resourceChild);
      
      ExternalContentEagerLoader em = new ExternalContentEagerLoader();
      Element eExternal = em.loadElement(resourceChild);
      eExternal.detach();
      
      int index = childElement.getParentElement().indexOf(childElement);
      childElement.getParentElement().setContent(index, eExternal);
      childElement.detach();
    }
    root.detach();
    return root;
  }
  catch (FileNotFoundException e) {throw new OfxAuthoringException(e.getMessage());}
}

相关文章