org.xml.sax.Attributes.getLocalName()方法的使用及代码示例

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

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

Attributes.getLocalName介绍

[英]Look up an attribute's local name by index.
[中]按索引查找属性的本地名称。

代码示例

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

private final void writeAttributes(final Attributes atts) throws IOException {
 StringBuilder sb = new StringBuilder();
 int len = atts.getLength();
 for (int i = 0; i < len; i++) {
  sb.append(' ')
    .append(atts.getLocalName(i))
    .append("=\"")
    .append(esc(atts.getValue(i)))
    .append('\"');
 }
 w.write(sb.toString());
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

/**
 * Copy an entire Attributes object.
 *
 * <p>It may be more efficient to reuse an existing object
 * rather than constantly allocating new ones.</p>
 * 
 * @param atts The attributes to copy.
 */
public void setAttributes (Attributes atts)
{
  clear();
  length = atts.getLength();
  if (length > 0) {
    data = new String[length*5];
    for (int i = 0; i < length; i++) {
      data[i*5] = atts.getURI(i);
      data[i*5+1] = atts.getLocalName(i);
      data[i*5+2] = atts.getQName(i);
      data[i*5+3] = atts.getType(i);
      data[i*5+4] = atts.getValue(i);
    }
}
}

代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl

public String getName(int i)
{
  String n = mAttrs.getQName(i);
  return (n == null) ? mAttrs.getLocalName(i) : n;
}

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

/**
 * Add the given attributes to the currently collected ones. These
 * attributes are always added, regardless of whether on not an element
 * is currently open.
 * @param atts List of attributes to add to this list
 */
public void addAttributes(Attributes atts) throws SAXException
{
  int nAtts = atts.getLength();
  for (int i = 0; i < nAtts; i++)
  {
    String uri = atts.getURI(i);
    if (null == uri)
      uri = "";
    addAttributeAlways(
      uri,
      atts.getLocalName(i),
      atts.getQName(i),
      atts.getType(i),
      atts.getValue(i),
      false);
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
  if (localName.equalsIgnoreCase(SHEET)) {
    String name = null;
    String id = null;
    for (int i = 0; i < attrs.getLength(); i++) {
      final String attrName = attrs.getLocalName(i);
      if (attrName.equalsIgnoreCase(NAME)) {
        name = attrs.getValue(i);
      } else if (attrName.equalsIgnoreCase(ID)) {
        id = attrs.getValue(i);
      }
      if (name != null && id != null) {
        sheetRefs.add(new XSSFSheetRef(id, name));
        break;
      }
    }
  }
}

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

/**
 * Copy an entire Attributes object.
 *
 * <p>It may be more efficient to reuse an existing object
 * rather than constantly allocating new ones.</p>
 *
 * @param atts The attributes to copy.
 */
public void setAttributes (Attributes atts)
{
  clear();
  length = atts.getLength();
  if (length > 0) {
    data = new String[length*5];
    for (int i = 0; i < length; i++) {
      data[i*5] = atts.getURI(i);
      data[i*5+1] = atts.getLocalName(i);
      data[i*5+2] = atts.getQName(i);
      data[i*5+3] = atts.getType(i);
      data[i*5+4] = atts.getValue(i);
    }
}
}

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

for (int i = 0, n = atts.getLength(); i < n; i++) {
  if (atts.getLocalName(i).equals("service")) {
    this.service = atts.getValue(i);

代码示例来源:origin: plutext/docx4j

/**
 * Add the given attributes to the currently collected ones. These
 * attributes are always added, regardless of whether on not an element
 * is currently open.
 * @param atts List of attributes to add to this list
 */
public void addAttributes(Attributes atts) throws SAXException
{
  int nAtts = atts.getLength();
  for (int i = 0; i < nAtts; i++)
  {
    String uri = atts.getURI(i);
    if (null == uri)
      uri = "";
    addAttributeAlways(
      uri,
      atts.getLocalName(i),
      atts.getQName(i),
      atts.getType(i),
      atts.getValue(i),
      false);
  }
}

代码示例来源:origin: LitePalFramework/LitePal

throws SAXException {
if (LitePalParser.NODE_DB_NAME.equalsIgnoreCase(localName)) {
  for (int i = 0; i < attributes.getLength(); i++) {
    if (LitePalParser.ATTR_VALUE.equalsIgnoreCase(attributes.getLocalName(i))) {
      litePalAttr.setDbName(attributes.getValue(i).trim());
  for (int i = 0; i < attributes.getLength(); i++) {
    if (LitePalParser.ATTR_VALUE.equalsIgnoreCase(attributes.getLocalName(i))) {
      litePalAttr.setVersion(Integer.parseInt(attributes.getValue(i).trim()));
  for (int i = 0; i < attributes.getLength(); i++) {
    if (LitePalParser.ATTR_CLASS.equalsIgnoreCase(attributes.getLocalName(i))) {
      litePalAttr.addClassName(attributes.getValue(i).trim());
  for (int i = 0; i < attributes.getLength(); i++) {
    if (LitePalParser.ATTR_VALUE.equalsIgnoreCase(attributes.getLocalName(i))) {
      litePalAttr.setCases(attributes.getValue(i).trim());
  for (int i = 0; i < attributes.getLength(); i++) {
    if (LitePalParser.ATTR_VALUE.equalsIgnoreCase(attributes.getLocalName(i))) {
      litePalAttr.setStorage(attributes.getValue(i).trim());

代码示例来源:origin: groovy/groovy-core

public void startElement(String namespaceURI, String localName, String qName, Attributes list)
    throws SAXException {
  addTextToNode();
  Object nodeName = getElementName(namespaceURI, localName, qName);
  int size = list.getLength();
  Map<Object, String> attributes = new LinkedHashMap<Object, String>(size);
  for (int i = 0; i < size; i++) {
    Object attributeName = getElementName(list.getURI(i), list.getLocalName(i), list.getQName(i));
    String value = list.getValue(i);
    attributes.put(attributeName, value);
  }
  parent = createNode(parent, nodeName, attributes);
  stack.add(parent);
}

代码示例来源:origin: yasserg/crawler4j

private void addToOutgoingUrls(String href, String tag, Attributes attributes) {
  curUrl = new ExtractedUrlAnchorPair();
  curUrl.setHref(href);
  curUrl.setTag(tag);
  for (int x = 0; x < attributes.getLength(); x++) {
    String attrName = attributes.getLocalName(x);
    String attrVal = attributes.getValue(attrName);
    curUrl.setAttribute(attrName, attrVal);
  }
  outgoingUrls.add(curUrl);
}

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

final int nattrs = attrs.getLength();
for (int i = 0; i < nattrs; i++) {
  if (attrs.getLocalName(i) == null) {
  tmp.setAttribute(attrs.getQName(i), attrs.getValue(i));
  tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), 
    attrs.getValue(i));

代码示例来源:origin: 4thline/cling

@Override
public void startElement(String uri, String localName, String qName, final Attributes attributes) throws SAXException {
  super.startElement(uri, localName, qName, attributes);
  Map.Entry[] attributeMap = new Map.Entry[attributes.getLength()];
  for (int i = 0; i < attributeMap.length; i++) {
    attributeMap[i] =
        new AbstractMap.SimpleEntry<>(
            attributes.getLocalName(i),
            attributes.getValue(i)
        );
  }
  try {
    EventedValue esv = createValue(localName, attributeMap);
    if (esv != null)
      getInstance().getValues().add(esv);
  } catch (Exception ex) {
    // Don't exit, just log a warning
    log.warning("Error reading event XML, ignoring value: " + Exceptions.unwrap(ex));
  }
}

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

/**
 * Add the contents of the attribute list to this list.
 *
 * @param atts List of attributes to add to this list
 */
public void addAttributes(Attributes atts)
{
 int nAtts = atts.getLength();
 for (int i = 0; i < nAtts; i++)
 {
  String uri = atts.getURI(i);
  if (null == uri)
   uri = "";
  String localName = atts.getLocalName(i);
  String qname = atts.getQName(i);
  int index = this.getIndex(uri, localName);
  // System.out.println("MutableAttrListImpl#addAttributes: "+uri+":"+localName+", "+index+", "+atts.getQName(i)+", "+this);
  if (index >= 0)
   this.setAttribute(index, uri, localName, qname, atts.getType(i),
            atts.getValue(i));
  else
   addAttribute(uri, localName, qname, atts.getType(i),
          atts.getValue(i));
 }
}

代码示例来源:origin: apache/tika

private static String getVal(String localName, Attributes atts) {
  for (int i = 0; i < atts.getLength(); i++) {
    if (localName.equals(atts.getLocalName(i))) {
      return atts.getValue(i);
    }
  }
  return null;
}

代码示例来源:origin: plutext/docx4j

if (atts.getLength() == 1) {
 SAXRecorder.this.sequence.addEvent(this.efactory.makeAttribute(atts.getURI(0),
   atts.getLocalName(0),
   atts.getQName(0),
   atts.getValue(0)));
} else if (atts.getLength() > 1) {
 AttributeEvent[] attEvents = new AttributeEvent[atts.getLength()];
 for (int i = 0; i < atts.getLength(); i++) {
  attEvents[i] = this.efactory.makeAttribute(atts.getURI(i),
    atts.getLocalName(i),
    atts.getQName(i),
    atts.getValue(i));
  attEvents[i].setWeight(2);
  this.currentWeight += 2;

代码示例来源:origin: 4thline/cling

new DIDLObject.Class(
    getCharacters(),
    getAttributes().getValue("name")
getInstance().addProperty(
  new DIDLObject.Property.UPNP.ARTIST(
    new PersonWithRole(getCharacters(), getAttributes().getValue("role"))
getInstance().addProperty(
  new DIDLObject.Property.UPNP.ACTOR(
    new PersonWithRole(getCharacters(), getAttributes().getValue("role"))
for (int i = 0; i < albumArtURIAttributes.getLength(); i++) {
  if ("profileID".equals(albumArtURIAttributes.getLocalName(i))) {
    albumArtURI.addAttribute(
      new DIDLObject.Property.DLNA.PROFILE_ID(

代码示例来源:origin: groovy/groovy-core

public void startElement(final String namespaceURI, final String localName, final String qName, final Attributes atts) throws SAXException {
  addCdata();
  final Map<String, String> attributes = new NamespaceAwareHashMap();
  final Map<String, String> attributeNamespaces = new HashMap<String, String>();
  for (int i = atts.getLength() - 1; i != -1; i--) {
    if (atts.getURI(i).length() == 0) {
      attributes.put(atts.getQName(i), atts.getValue(i));
    } else {
      String key = new QName(atts.getURI(i), atts.getLocalName(i)).toString();
      attributes.put(key, atts.getValue(i));
      attributeNamespaces.put(key, atts.getURI(i));
    }
  }
  final Node newElement;
  if (namespaceURI.length() == 0) {
    newElement = new Node(currentNode, qName, attributes, attributeNamespaces, namespaceURI);
  } else {
    newElement = new Node(currentNode, localName, attributes, attributeNamespaces, namespaceURI);
  }
  if (currentNode != null) {
    currentNode.addChild(newElement);
  }
  stack.push(currentNode);
  currentNode = newElement;
}

代码示例来源:origin: apache/tika

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
  if ("cmAuthor".equals(localName)) {
    for (int i = 0; i < atts.getLength(); i++) {
      if ("id".equals(atts.getLocalName(i))) {
        id = atts.getValue(i);
      } else if ("name".equals(atts.getLocalName(i))) {
        name = atts.getValue(i);
      } else if ("initials".equals(atts.getLocalName(i))) {
        initials = atts.getValue(i);
      }
    }
    commentAuthors.add(id, name, initials);
    //clear out
    id = null; name = null; initials = null;
  }
}

代码示例来源:origin: commons-digester/commons-digester

top = doc.createElementNS(namespaceURI, localName);
for (int i = 0; i < atts.getLength(); i++) {
  Attr attr = null;
  if ((atts.getLocalName(i) == null) ||
    (atts.getLocalName(i).length() == 0)) {
    attr = doc.createAttribute(atts.getQName(i));
    attr.setNodeValue(atts.getValue(i));
    ((Element)top).setAttributeNode(attr);
  } else {
    attr = doc.createAttributeNS(atts.getURI(i),
                   atts.getLocalName(i));
    attr.setNodeValue(atts.getValue(i));
    ((Element)top).setAttributeNodeNS(attr);

相关文章