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

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

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

Attributes.getQName介绍

[英]Look up an attribute's XML qualified (prefixed) name by index.
[中]按索引查找属性的XML限定(前缀)名称。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
  Node parent = getParent();
  Element element = this.document.createElementNS(uri, qName);
  for (int i = 0; i < attributes.getLength(); i++) {
    String attrUri = attributes.getURI(i);
    String attrQname = attributes.getQName(i);
    String value = attributes.getValue(i);
    if (!attrQname.startsWith("xmlns")) {
      element.setAttributeNS(attrUri, attrQname, value);
    }
  }
  element = (Element) parent.appendChild(element);
  this.elements.add(element);
}

代码示例来源:origin: MovingBlocks/Terasology

public static String findAttribute(Attributes attributes, String name) {
  int size = attributes.getLength();
  for (int i = 0; i < size; i++) {
    if (attributes.getQName(i).equalsIgnoreCase(name)) {
      return attributes.getValue(i);
    }
  }
  return null;
}

代码示例来源:origin: igniterealtime/Openfire

protected void writeAttribute(Attributes attributes, int index) throws IOException {
  char quote = format.getAttributeQuoteCharacter();
  writer.write(" ");
  writer.write(attributes.getQName(index));
  writer.write("=");
  writer.write(quote);
  writeEscapeAttributeEntities(attributes.getValue(index));
  writer.write(quote);
}

代码示例来源: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: spring-projects/spring-framework

private List<Attribute> getAttributes(Attributes attributes) {
  int attrLength = attributes.getLength();
  List<Attribute> result = new ArrayList<>(attrLength);
  for (int i = 0; i < attrLength; i++) {
    QName attrName = toQName(attributes.getURI(i), attributes.getQName(i));
    if (!isNamespaceDeclaration(attrName)) {
      result.add(this.eventFactory.createAttribute(attrName, attributes.getValue(i)));
    }
  }
  return result;
}

代码示例来源:origin: aws/aws-sdk-java

private static String findAttributeValue(
      String qnameToFind,
      Attributes attrs) {

    for (int i = 0; i < attrs.getLength(); i++) {
      String qname = attrs.getQName(i);
      if (qname.trim().equalsIgnoreCase(qnameToFind.trim())) {
        return attrs.getValue(i);
      }
    }

    return null;
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void startElementInternal(QName name, Attributes attributes,
    Map<String, String> namespaceMapping) throws XMLStreamException {
  this.streamWriter.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI());
  for (Map.Entry<String, String> entry : namespaceMapping.entrySet()) {
    String prefix = entry.getKey();
    String namespaceUri = entry.getValue();
    this.streamWriter.writeNamespace(prefix, namespaceUri);
    if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
      this.streamWriter.setDefaultNamespace(namespaceUri);
    }
    else {
      this.streamWriter.setPrefix(prefix, namespaceUri);
    }
  }
  for (int i = 0; i < attributes.getLength(); i++) {
    QName attrName = toQName(attributes.getURI(i), attributes.getQName(i));
    if (!isNamespaceDeclaration(attrName)) {
      this.streamWriter.writeAttribute(attrName.getPrefix(), attrName.getNamespaceURI(),
          attrName.getLocalPart(), attributes.getValue(i));
    }
  }
}

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

private void mapJNDI(Attributes atts, Map gfSpecific) {
 int attsLen = atts.getLength();
 String key = "";
 String value = "";
 // put attributes into a Map
 for (int i = 0; i < attsLen; i++) {
  key = atts.getQName(i);
  value = atts.getValue(key);
  gfSpecific.put(key, value);
 }
}

代码示例来源:origin: org.springframework/spring-core

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
  Node parent = getParent();
  Element element = this.document.createElementNS(uri, qName);
  for (int i = 0; i < attributes.getLength(); i++) {
    String attrUri = attributes.getURI(i);
    String attrQname = attributes.getQName(i);
    String value = attributes.getValue(i);
    if (!attrQname.startsWith("xmlns")) {
      element.setAttributeNS(attrUri, attrQname, value);
    }
  }
  element = (Element) parent.appendChild(element);
  this.elements.add(element);
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {            
  if (namespaceURI != null) {
    print.addElementNS(namespaceURI);
  }
  if ("".equals(localName)) localName = null;  //#16484  //NOI18N
  print.addElementName(localName != null ? localName : qName);
  for (int i = 0; i<atts.getLength(); i++) {
    print.addElementAtt(atts.getQName(i), atts.getValue(i));
  }
  throw STOP;
}

代码示例来源:origin: org.springframework/spring-core

private List<Attribute> getAttributes(Attributes attributes) {
  int attrLength = attributes.getLength();
  List<Attribute> result = new ArrayList<>(attrLength);
  for (int i = 0; i < attrLength; i++) {
    QName attrName = toQName(attributes.getURI(i), attributes.getQName(i));
    if (!isNamespaceDeclaration(attrName)) {
      result.add(this.eventFactory.createAttribute(attrName, attributes.getValue(i)));
    }
  }
  return result;
}

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

/**
   Render a {@link org.xml.sax.Attributes}.
 */
 public
 String  doRender(Object o) {
  if(o instanceof Attributes) {
   StringBuffer sbuf = new StringBuffer();
   Attributes a = (Attributes) o;
   int len = a.getLength();
   boolean first = true;
   for(int i = 0; i < len; i++) {
  if(first) {
   first = false;
  } else {
   sbuf.append(", ");
  }
  sbuf.append(a.getQName(i));
  sbuf.append('=');
  sbuf.append(a.getValue(i));
   }
   return sbuf.toString();
  } else {
   try {
    return o.toString();
   } catch(Exception ex) {
     return ex.toString();
   }
  }
 }
}

代码示例来源: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: plutext/docx4j

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
  if(qName.equals(INLINE_PARENT)){
    String aQName;
    for(int i=0; i < attributes.getLength(); i++){
      aQName = attributes.getQName(i);
      if(aQName.equals(INTERNAL_LINK)){
        parseValue(attributes.getValue(i));
      }
    }
  }
}

代码示例来源: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: xalan/xalan

/**
 * Attributes clone constructor
 */
public AttributeList(org.xml.sax.Attributes attributes) {
this();
if (attributes != null) {
  final int count = attributes.getLength();
  for (int i = 0; i < count; i++) {
  add(attributes.getQName(i),attributes.getValue(i));
  }
}
}

代码示例来源: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: stanfordnlp/CoreNLP

private void outputTextAndTag(String qName, Attributes attributes, boolean close) {
 // If we're not already in an element to be transformed, first
 // echo the previous text...
 outWriter.print(XMLUtils.escapeXML(textToBeTransformed.toString()));
 textToBeTransformed = new StringBuffer();
 
 // ... then echo the new tag to outStream 
 outWriter.print('<');
 if (close) {
  outWriter.print('/');
 }
 outWriter.print(qName);
 if (attributes != null) {
  for (int i = 0; i < attributes.getLength(); i++) {
   outWriter.print(' ');
   outWriter.print(attributes.getQName(i));
   outWriter.print("=\"");
   outWriter.print(XMLUtils.escapeXML(attributes.getValue(i)));
   outWriter.print('"');
  }
 }
 outWriter.print(">\n");
}

代码示例来源:origin: org.springframework/spring-core

@Override
protected void startElementInternal(QName name, Attributes attributes,
    Map<String, String> namespaceMapping) throws XMLStreamException {
  this.streamWriter.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI());
  for (Map.Entry<String, String> entry : namespaceMapping.entrySet()) {
    String prefix = entry.getKey();
    String namespaceUri = entry.getValue();
    this.streamWriter.writeNamespace(prefix, namespaceUri);
    if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
      this.streamWriter.setDefaultNamespace(namespaceUri);
    }
    else {
      this.streamWriter.setPrefix(prefix, namespaceUri);
    }
  }
  for (int i = 0; i < attributes.getLength(); i++) {
    QName attrName = toQName(attributes.getURI(i), attributes.getQName(i));
    if (!isNamespaceDeclaration(attrName)) {
      this.streamWriter.writeAttribute(attrName.getPrefix(), attrName.getNamespaceURI(),
          attrName.getLocalPart(), attributes.getValue(i));
    }
  }
}

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

@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes atts) throws SAXException {
  // Increment the current depth because start a new XML element.
  int newDepth = depth.incrementAndGet();
  // Output the element and its attributes if it is
  // not the root element.
  if (newDepth > splitDepth.get()) {
    sb.append("<");
    sb.append(qName);
    int attCount = atts.getLength();
    for (int i = 0; i < attCount; i++) {
      String attName = atts.getQName(i);
      String attValue = atts.getValue(i);
      sb.append(" ").append(attName).append("=").append("\"").append(attValue).append("\"");
    }
    sb.append(">");
  }
}

相关文章