org.xml.sax.AttributeList类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(133)

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

AttributeList介绍

[英]Interface for an element's attribute specifications. This module, both source code and documentation, is in the Public Domain, and comes with NO WARRANTY. See http://www.saxproject.org for further information.

This is the original SAX1 interface for reporting an element's attributes. Unlike the new org.xml.sax.Attributesinterface, it does not support Namespace-related information.

When an attribute list is supplied as part of a org.xml.sax.DocumentHandler#startElementevent, the list will return valid results only during the scope of the event; once the event handler returns control to the parser, the attribute list is invalid. To save a persistent copy of the attribute list, use the SAX1 org.xml.sax.helpers.AttributeListImplhelper class.

An attribute list includes only attributes that have been specified or defaulted: #IMPLIED attributes will not be included.

There are two ways for the SAX application to obtain information from the AttributeList. First, it can iterate through the entire list:

public void startElement (String name, AttributeList atts) { 
for (int i = 0; i < atts.getLength(); i++) { 
String name = atts.getName(i); 
String type = atts.getType(i); 
String value = atts.getValue(i); 
[...] 
} 
}

(Note that the result of getLength() will be zero if there are no attributes.)

As an alternative, the application can request the value or type of specific attributes:

public void startElement (String name, AttributeList atts) { 
String identifier = atts.getValue("id"); 
String label = atts.getValue("label"); 
[...] 
}

[中]元素属性规范的接口*此模块(包括源代码和文档)属于公共领域,不提供任何保修。*详见http://www.saxproject.org
这是用于报告元素属性的原始SAX1接口。与新组织不同。xml。萨克斯。Attributesinterface,它不支持与命名空间相关的信息。
当属性列表作为组织的一部分提供时。xml。萨克斯。DocumentHandler#startElementevent,列表仅在事件范围内返回有效结果;一旦事件处理程序将控制权返回给解析器,属性列表就无效。要保存属性列表的持久副本,请使用SAX1组织。xml。萨克斯。帮手。AttributeListImplhelper类。
属性列表仅包括已指定或默认的属性:#将不包括隐含属性。
SAX应用程序有两种从AttributeList获取信息的方法。首先,它可以遍历整个列表:

public void startElement (String name, AttributeList atts) { 
for (int i = 0; i < atts.getLength(); i++) { 
String name = atts.getName(i); 
String type = atts.getType(i); 
String value = atts.getValue(i); 
[...] 
} 
}

(请注意,如果没有属性,getLength()的结果将为零。)
或者,应用程序可以请求特定属性的值或类型:

public void startElement (String name, AttributeList atts) { 
String identifier = atts.getValue("id"); 
String label = atts.getValue("label"); 
[...] 
}

代码示例

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

/**
 * Set the attribute list, discarding previous contents.
 *
 * <p>This method allows an application writer to reuse an
 * attribute list easily.</p>
 *
 * @param atts The attribute list to copy.
 */
public void setAttributeList (AttributeList atts)
{
int count = atts.getLength();
clear();
for (int i = 0; i < count; i++) {
  addAttribute(atts.getName(i), atts.getType(i), atts.getValue(i));
}
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Sets the attributes for the wrapped element.
 *
 * @param attributes List of attributes defined in the XML for this
 *                   element. May be <code>null</code>.
 * @deprecated since 1.6.x.
 */
@Deprecated
public synchronized void setAttributes(AttributeList attributes) {
  this.attributes = new AttributeListImpl(attributes);
  for (int i = 0; i < attributes.getLength(); i++) {
    setAttribute(attributes.getName(i), attributes.getValue(i));
  }
}

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

/**
 * Return the value of the specified attribute.
 *
 * @param The attribute's index.
 * @return The attribute's value.
 */
public String getValue (int i)
{
  return qAtts.getValue(i);
}

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

/**
 * Return the qualified (prefixed) name of the specified attribute.
 *
 * @param The attribute's index.
 * @return The attribute's qualified name, internalized.
 */
public String getQName (int i)
{
  return qAtts.getName(i).intern();
}

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

/**
 * Return the length of the attribute list.
 *
 * @return The number of attributes in the list.
 * @see org.xml.sax.Attributes#getLength
 */
public int getLength ()
{
  return qAtts.getLength();
}

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

/**
 * Return the type of the specified attribute.
 *
 * @param The attribute's index.
 * @return The attribute's type as an internalized string.
 */
public String getType (int i)
{
  return qAtts.getType(i).intern();
}

代码示例来源:origin: org.apache.ant/ant

for (int i = 0, length = attrs.getLength(); i < length; i++) {
  String value = replaceProperties(project, attrs.getValue(i), project.getProperties());
  try {
    ih.setAttribute(project, target, attrs.getName(i).toLowerCase(Locale.ENGLISH), value);
  } catch (BuildException be) {
    if (!attrs.getName(i).equals("id")) {
      throw be;

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

/**
 * Look up the value of an attribute by qualified (prefixed) name.
 *
 * @param qName The qualified name.
 * @return The attribute's value.
 */
public String getValue (String qName)
{
  return qAtts.getValue(qName);
}

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

/**
 * Look up an attribute index by qualified (prefixed) name.
 *
 * @param qName The qualified name.
 * @return The attributes index, or -1 if none was found.
 * @see org.xml.sax.Attributes#getIndex(java.lang.String)
 */
public int getIndex (String qName)
{
  int max = atts.getLength();
  for (int i = 0; i < max; i++) {
  if (qAtts.getName(i).equals(qName)) {
    return i;
  }
  }
  return -1;
}

代码示例来源:origin: ibinti/bugvm

/**
 * Return the length of the attribute list.
 *
 * @return The number of attributes in the list.
 * @see org.xml.sax.Attributes#getLength
 */
public int getLength ()
{
  return qAtts.getLength();
}

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

/**
 * Look up the type of an attribute by qualified (prefixed) name.
 *
 * @param qName The qualified name.
 * @return The attribute's type as an internalized string.
 */
public String getType (String qName)
{
  return qAtts.getType(qName).intern();
}

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

int length = qAtts.getLength();
  String attQName = qAtts.getName(i);
  prefix = attQName.substring(n+1);
  String value = qAtts.getValue(i);
  if (!nsSupport.declarePrefix(prefix, value)) {
  reportError("Illegal Namespace prefix: " + prefix);
  String attQName = qAtts.getName(i);
  String type = qAtts.getType(i);
  String value = qAtts.getValue(i);

代码示例来源:origin: org.apache.ant/ant

String description = null;
for (int i = 0; i < attrs.getLength(); i++) {
  String key = attrs.getName(i);
  String value = attrs.getValue(i);
  switch (key) {
    case "name":

代码示例来源:origin: org.apache.ant/ant

/**
   * Scans an attribute list for the <code>id</code> attribute and
   * stores a reference to the target object in the project if an
   * id is found.
   * <p>
   * This method was moved out of the configure method to allow
   * it to be executed at parse time.
   *
   * @see #configure(Object,AttributeList,Project)
   */
  private void configureId(Object target, AttributeList attr) {
    String id = attr.getValue("id");
    if (id != null) {
      project.addReference(id, target);
    }
  }
}

代码示例来源:origin: MobiVM/robovm

/**
 * Return the qualified (prefixed) name of the specified attribute.
 *
 * @param The attribute's index.
 * @return The attribute's qualified name, internalized.
 */
public String getQName (int i)
{
  return qAtts.getName(i).intern();
}

代码示例来源:origin: MobiVM/robovm

/**
 * Return the length of the attribute list.
 *
 * @return The number of attributes in the list.
 * @see org.xml.sax.Attributes#getLength
 */
public int getLength ()
{
  return qAtts.getLength();
}

代码示例来源:origin: MobiVM/robovm

/**
 * Return the type of the specified attribute.
 *
 * @param The attribute's index.
 * @return The attribute's type as an internalized string.
 */
public String getType (int i)
{
  return qAtts.getType(i).intern();
}

代码示例来源:origin: uk.org.ponder.rsf/rsf-core-ponderutilcore

SAXAttributeHash(AttributeList attrs) {
 for (int i = 0; i < attrs.getLength(); ++ i) {
  put(attrs.getName(i), attrs.getType(i), attrs.getValue(i));
  }
 }
public SAXAttributeHash() {}

代码示例来源:origin: org.apache.ant/ant

String baseDir = null;
for (int i = 0; i < attrs.getLength(); i++) {
  String key = attrs.getName(i);
  String value = attrs.getValue(i);
  switch (key) {
    case "default":

代码示例来源:origin: MobiVM/robovm

/**
 * Return the value of the specified attribute.
 *
 * @param The attribute's index.
 * @return The attribute's value.
 */
public String getValue (int i)
{
  return qAtts.getValue(i);
}

相关文章

微信公众号

最新文章

更多