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

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

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

Attributes.getURI介绍

[英]Look up an attribute's Namespace URI by index.
[中]按索引查找属性的命名空间URI。

代码示例

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

@Override
public boolean equals(Object obj) {
  Attributes other = ((PartialAttributes) obj).attributes;
  if (this.attributes.getLength() != other.getLength()) {
    return false;
  }
  for (int i = 0; i < other.getLength(); i++) {
    boolean found = false;
    for (int j = 0; j < attributes.getLength(); j++) {
      if (other.getURI(i).equals(attributes.getURI(j))
          && other.getQName(i).equals(attributes.getQName(j))
          && other.getType(i).equals(attributes.getType(j))
          && other.getValue(i).equals(attributes.getValue(j))) {
        found = true;
        break;
      }
    }
    if (!found) {
      return false;
    }
  }
  return true;
}

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

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
  super.startElement(uri, localName, qName, attributes);
  Element newEl = getInstance().getMetadata().createElementNS(uri, qName);
  for (int i = 0; i < attributes.getLength(); i++) {
    newEl.setAttributeNS(
      attributes.getURI(i),
      attributes.getQName(i),
      attributes.getValue(i)
    );
  }
  current.appendChild(newEl);
  current = newEl;
}

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

int nAtts = atts.getLength();
  if (atts.getType(i).equalsIgnoreCase("ID"))
   setIDAttribute(atts.getValue(i), elem);
  String attrNS = atts.getURI(i);
  String attrQName = atts.getQName(i);
  elem.setAttributeNS(attrNS,attrQName, atts.getValue(i));

代码示例来源: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);

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

int nAtts = atts.getLength();
  if (atts.getType(i).equalsIgnoreCase("ID"))
   setIDAttribute(atts.getValue(i), elem);
  String attrNS = atts.getURI(i);
  String attrQName = atts.getQName(i);
  elem.setAttributeNS(attrNS,attrQName, atts.getValue(i));

相关文章