javax.xml.stream.XMLStreamReader.getAttributeCount()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(18.3k)|赞(0)|评价(0)|浏览(197)

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

XMLStreamReader.getAttributeCount介绍

[英]Returns the count of attributes on this START_ELEMENT, this method is only valid on a START_ELEMENT or ATTRIBUTE. This count excludes namespace definitions when isNamespaceAware is true; when isNamespaceAware is false, the attribute count includes xmlns and xmlns.* attributes. Attribute indices are zero-based.
[中]返回此START_元素上的属性计数,此方法仅对START_元素或属性有效。当isNamespaceAware为真时,此计数不包括命名空间定义;当isNamespaceAware为false时,属性计数包括xmlnsxmlns.*属性。属性索引是从零开始的。

代码示例

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

private Attributes getAttributes() {
  AttributesImpl attributes = new AttributesImpl();
  for (int i = 0; i < this.reader.getAttributeCount(); i++) {
    String namespace = this.reader.getAttributeNamespace(i);
    if (namespace == null || !hasNamespacesFeature()) {
      namespace = "";
    }
    String type = this.reader.getAttributeType(i);
    if (type == null) {
      type = "CDATA";
    }
    attributes.addAttribute(namespace, this.reader.getAttributeLocalName(i),
        toQualifiedName(this.reader.getAttributeName(i)), type, this.reader.getAttributeValue(i));
  }
  if (hasNamespacePrefixesFeature()) {
    for (int i = 0; i < this.reader.getNamespaceCount(); i++) {
      String prefix = this.reader.getNamespacePrefix(i);
      String namespaceUri = this.reader.getNamespaceURI(i);
      String qName;
      if (StringUtils.hasLength(prefix)) {
        qName = "xmlns:" + prefix;
      }
      else {
        qName = "xmlns";
      }
      attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
    }
  }
  return attributes;
}

代码示例来源:origin: pentaho/pentaho-kettle

public StartElementBuffer( XMLStreamReader rd ) {
 prefix = rd.getPrefix();
 namespace = rd.getNamespaceURI();
 localName = rd.getLocalName();
 for ( int i = 0; i < rd.getAttributeCount(); i++ ) {
  attrBuffer.add( new AttrBuffer( rd, i ) );
 }
}

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

private Attributes parseAttributes(final XMLStreamReader streamReader) throws RealmUnavailableException, XMLStreamException {
  final int attributeCount = streamReader.getAttributeCount();
  if (attributeCount > 0) {
    throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name);
  }
  int tag = streamReader.nextTag();
  if (tag == END_ELEMENT) {
    return Attributes.EMPTY;
  }
  Attributes attributes = new MapAttributes();
  do {
    if (! validNamespace(streamReader.getNamespaceURI())) {
      throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name);
    }
    if ("attribute".equals(streamReader.getLocalName())) {
      parseAttribute(streamReader, attributes);
    } else {
      throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name);
    }
  } while (streamReader.nextTag() == START_ELEMENT);
  return attributes;
}

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

loc = r.getLocation();
} else {
  loc = mLastLocation;
    loc = mLastLocation = r.getLocation();
      int attrCount = r.getAttributeCount();
      if (attrCount < 1) {
        attrs = null;
        attrs = new LinkedHashMap();
        for (int i = 0; i < attrCount; ++i) {
          QName aname = r.getAttributeName(i);
          attrs.put(aname, new AttributeEventImpl(loc, aname, r.getAttributeValue(i), r.isAttributeSpecified(i)));
      if (ed == null) { // undefined?
        return new WEntityReference(loc, r.getLocalName());
    return new WEntityReference(loc, r.getLocalName());

代码示例来源:origin: org.wildfly.core/wildfly-server

private static void parseSubsystem(final XMLStreamReader reader, final Set<String> subsystems) throws XMLStreamException {
  String name = null;
  final Set<Attribute> required = EnumSet.of(Attribute.NAME);
  final int count = reader.getAttributeCount();
  for (int i = 0; i < count; i++) {
    final Attribute attribute = Attribute.of(reader.getAttributeName(i));
    required.remove(attribute);
    switch (attribute) {
      case NAME:
        name = reader.getAttributeValue(i);
        break;
      default:
        throw unexpectedContent(reader);
    }
  }
  if (!required.isEmpty()) {
    throw missingAttributes(reader.getLocation(), required);
  }
  subsystems.add(name);
  if (reader.hasNext()) {
    switch (reader.nextTag()) {
      case XMLStreamConstants.END_ELEMENT:
        return;
      default:
        throw unexpectedContent(reader);
    }
  }
}

代码示例来源:origin: org.daisy.pipeline/common-utils

public static Map<QName,String> getAttributes(XMLStreamReader reader) {
  Map<QName,String> map = new HashMap<QName,String>();
  for (int i = 0; i < reader.getAttributeCount(); i++)
    map.put(reader.getAttributeName(i), reader.getAttributeValue(i));
  return map;
}

代码示例来源:origin: stackoverflow.com

public class Main {

  public static void main(String args[]) {
    try{
      String raw = "<?xml version='1.0' encoding='iso-8859-1'?><ResDoc><resume canonversion='2' dateversion='2' present='735453' xml:space='preserve'>Jack - A Web ResumeHello,My name is Jack.<statements><personal>This website is all about my career, work experience and skill set. Unlike a traditional resume (available here in Word and PDF) my Web Resume is interactive. Feel free to run a query, a great way to see if I would be a good fit for you and your company, or click on any of the blue links for more details and work samples.Just like my career and capabilities, this site is always growing as I add more examples of my work, and even some blog entries or documentation/ tutorials. You will see this site grow as I do!</personal></statements>I want to thank you for stopping by!Resume<experience>Current employer\t2013\tCurrent\t<title>Systems Administrator</title>\t<description>Windows &amp; Altiris administration, SEP &amp; Credant Encryption Management and Policies,EMR Software Dev company\t2012\t2013\tHelpesk Technician II\tOffice 365,Data-Center migration, Corporate image creation\\ configuration, Domain administrationCommunications\t2011\t2012\tSr. Helpesk Technician\tPrimarily managed IT support issues, requests and tickets from local station &amp; east coast.</description><job id='1'><employer>University\t2008</employer>\t2011\t<title>Desktop Technician/ Analyst\tDesktop Support</title>, <description>managing tickets &amp; walk-ins. I.T. support for professors &amp; faculty..</description></job><job id='2'><employer>Emergence Enterprises LLC</employer>\t2006\t<description>2008\tManaging Member &amp; Technology Consultant\t1099 Contractor in City1 and City 2 areas. Computer consultation and support.Hightlights of IT Skills Don't be shy! Please, click the links for work samples!Technical Support\tSystems Deployment Configuration &amp; Upgrading\tScripting packaging and AutomationPowerShell\tVBScript\tBatchAutoIT\tSQL\tSymantec Management Platform AdministrationPatches &amp; Updates\tTraining &amp; Mentoring\tAV management and deploymentVPN\tProxy and Firewall\tDisk Encryption policy and deploymentLAN/WAN Administration\tInventory Solutions\tand More!</description></job></experience>ReferencesRef_1\tSystems Engineer II\tnationwide companyRef_2\tTechnology &amp; Systems Manager\tUniversityRef_3\tInfrastructure Project Manager\tLocal company</resume><skillrollup version='1'>  <canonskill experience='1' expidrefs='2' idrefs='2' name='automation'>    <variant>Automation</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='consulting'>    <variant>Consultant</variant>    <variant>consultation</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='cryptography'>    <variant>Encryption</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='firewalls'>    <variant>Firewall</variant>  </canonskill>  <canonskill experience='1' name='imaging'>    <variant>image</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='inventory management'>    <variant>Inventory</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='lan'>    <variant>LAN</variant>  </canonskill>  <canonskill experience='1' expidrefs='1,2' idrefs='1,2' name='management'>    <variant>Managing</variant>    <variant>managing</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='mentoring'>    <variant>Mentoring</variant>  </canonskill>  <canonskill experience='1' name='microsoft office'>    <variant>Office</variant>  </canonskill>  <canonskill experience='1' name='microsoft windows'>    <variant>Windows</variant>  </canonskill>  <canonskill experience='1' name='migration'>    <variant>migration</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='packaging'>    <variant>packaging</variant>  </canonskill>  <canonskill experience='1' name='policy analysis'>    <variant>Policies</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='proxy server'>    <variant>Proxy</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='shell scripting'>    <variant>Scripting</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='sql'>    <variant>SQL</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='symantec packages'>    <variant>Symantec</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='technical support'>    <variant>Technical Support</variant>  </canonskill>  <canonskill experience='1' name='technician'>    <variant>Technician</variant>    <variant>Technician II</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='upgrades'>    <variant>Upgrading</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='vbscript'>    <variant>VBScript</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='vpn'>    <variant>VPN</variant>  </canonskill>  <canonskill experience='1' expidrefs='2' idrefs='2' name='wan'>    <variant>WAN</variant>  </canonskill></skillrollup></ResDoc>";
      XMLInputFactory xif = XMLInputFactory.newFactory();
      XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(raw));

      while(xsr.hasNext()){
        xsr.nextTag();
        System.out.println(xsr.getName());
        System.out.println(xsr.getAttributeCount());
      }
    }
    catch(XMLStreamException e)
    {

    }
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

for ( int event = vReader.next(); vReader.hasNext(); event = vReader.next() ) {
 switch ( event ) {
  case XMLStreamConstants.START_ELEMENT:
    logRowlevel( "START_ELEMENT / " + vReader.getAttributeCount() + " / " + vReader.getNamespaceCount() );
    logRowlevel( "vReader.getLocalName = " + vReader.getLocalName() );
     WebServiceField field = meta.getFieldOutFromWsName( vReader.getLocalName(), ignoreNamespacePrefix );
     if ( field != null ) {
      outputRowData[ outputIndex++ ] = getValue( vReader.getElementText(), field );
      oneValueRowProcessing = false;
     } else {
      if ( meta.getOutFieldContainerName().equals( vReader.getLocalName() ) ) {

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

private String findFirstAttributeValue(XMLStreamReader reader, String name) {
  for (int i = 0; i < reader.getAttributeCount(); i++) {
    String n = reader.getAttributeLocalName(i);
    if (name.equals(n)) {
      return reader.getAttributeValue(i);
    }
  }
  return "";
}

代码示例来源:origin: org.jboss.as/patch-gen

protected static void processResource(final XMLStreamReader reader, final Set<String> resources) throws XMLStreamException {
  final int attributeCount = reader.getAttributeCount();
  if (attributeCount != 1) {
    throw new XMLStreamException();
  }
  final String path = reader.getAttributeValue(0);
  resources.add(path.trim());
  if (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
    throw new XMLStreamException("unexpected element");
  }
}

代码示例来源:origin: stackoverflow.com

FileInputStream xmlStream = new FileInputStream(new File("myxml.xml"));
 XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(xmlStream);
 while(reader.hasNext()){
   reader.next();
   for(int i=0; i < reader.getAttributeCount(); i++) {
     System.out.println(reader.getAttributeName(i) + "=" + reader.getAttributeValue(i));
   }
 }

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

private void parseCredential(final XMLStreamReader streamReader, CredentialParseFunction function) throws RealmUnavailableException, XMLStreamException {
  final int attributeCount = streamReader.getAttributeCount();
  String name = null;
  String algorithm = null;
  String format = null;
  for (int i = 0; i < attributeCount; i ++) {
    String namespace = streamReader.getAttributeNamespace(i);
    if (namespace != null && !namespace.equals("")) {
      throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name);
    }
    final String localName = streamReader.getAttributeLocalName(i);
    if ("name".equals(localName)) {
      name = streamReader.getAttributeValue(i);
    } else if ("algorithm".equals(localName)) {
      algorithm = streamReader.getAttributeValue(i);
    } else if ("format".equals(localName)) {
      format = streamReader.getAttributeValue(i);
    } else {
      throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name);
    }
  }
  final String text = streamReader.getElementText().trim();
  function.parseCredential(algorithm, format, text);
}

代码示例来源:origin: com.struqt/invar-core

private static void StAXStartElement(XMLStreamReader r, Stack<TokenNode> stack, String filePath) {
  String name = r.getLocalName();
  TokenNode n = new TokenNode(name);
  n.setFilePath(filePath);
  stack.push(n);
  int len = r.getAttributeCount();
  for (int i = 0; i < len; i++) {
    String k = r.getAttributeName(i).getLocalPart();
    String v = r.getAttributeValue(i);
    n.putAttr(k, v);
  }
}

代码示例来源:origin: org.wildfly.core/wildfly-server

private static void parseSubsystem(final XMLStreamReader reader, final Set<String> subsystems) throws XMLStreamException {
  String name = null;
  final Set<Attribute> required = EnumSet.of(Attribute.NAME);
  final int count = reader.getAttributeCount();
  for (int i = 0; i < count; i++) {
    final Attribute attribute = Attribute.of(reader.getAttributeName(i));
    required.remove(attribute);
    switch (attribute) {
      case NAME:
        name = reader.getAttributeValue(i);
        break;
      default:
        throw unexpectedContent(reader);
    }
  }
  if (!required.isEmpty()) {
    throw missingAttributes(reader.getLocation(), required);
  }
  subsystems.add(name);
  if (reader.hasNext()) {
    switch (reader.nextTag()) {
      case XMLStreamConstants.END_ELEMENT:
        return;
      default:
        throw unexpectedContent(reader);
    }
  }
}

代码示例来源:origin: org.glassfish.main.common/common-util

private Map<String, String> parseAttributes() {
  int num = parser.getAttributeCount();
  Map<String, String> map = new HashMap<String, String>();
  for (int i = 0; i < num; i++) {
    map.put(parser.getAttributeName(i).getLocalPart(), parser.getAttributeValue(i));
  }
  return map;
}

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

private List<Credential> parseCredentials(final XMLStreamReader streamReader) throws RealmUnavailableException, XMLStreamException {
  final int attributeCount = streamReader.getAttributeCount();
  if (attributeCount > 0) {
    throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name);
  }
  if (streamReader.nextTag() == END_ELEMENT) {
    return Collections.emptyList();
  }
  List<Credential> credentials = new ArrayList<>();
  do {
    if (! validNamespace(streamReader.getNamespaceURI())) {
      throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name);
    }
    if ("password".equals(streamReader.getLocalName())) {
      parsePassword(credentials, streamReader);
    } else if ("public-key".equals(streamReader.getLocalName())) {
      parsePublicKey(credentials, streamReader);
    } else if ("certificate".equals(streamReader.getLocalName())) {
      parseCertificate(credentials, streamReader);
    } else if ("otp".equals(streamReader.getLocalName())) {
      parseOtp(credentials, streamReader);
    } else {
      throw ElytronMessages.log.fileSystemRealmInvalidContent(path, streamReader.getLocation().getLineNumber(), name);
    }
  } while (streamReader.nextTag() != END_ELEMENT);
  return credentials;
}

代码示例来源:origin: org.jboss.metadata/jboss-metadata-appclient

public ApplicationClientMetaData parse(XMLStreamReader reader, PropertyReplacer propertyReplacer) throws XMLStreamException {
  reader.require(START_DOCUMENT, null, null);
  // Read until the first start element
  while (reader.hasNext() && reader.next() != START_ELEMENT) {}
  final ApplicationClientMetaData appClientMetadata = new ApplicationClientMetaData();
  // Handle attributes and set them in the EjbJarMetaData
  final int count = reader.getAttributeCount();
  for (int i = 0; i < count; i++) {
    if (attributeHasNamespace(reader, i)) {
      continue;
    }
    processAttribute(appClientMetadata, reader, i);
  }
  appClientMetadata.setDescriptionGroup(new DescriptionGroupMetaData());
  appClientMetadata.setEnvironmentRefsGroupMetaData(new AppClientEnvironmentRefsGroupMetaData());
  // parse and create metadata out of the elements
  while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
    processElement(appClientMetadata, reader, propertyReplacer);
  }
  return appClientMetadata;
}

代码示例来源:origin: javaee/glassfish

/*package*/ void fillAttributes(XMLStreamReader in) {
  for( int i=in.getAttributeCount()-1; i>=0; i-- ) {
    String n = in.getAttributeLocalName(i);
    if(model.attributes.containsKey(n)) {
      if(attributes==null)
        attributes = new HashMap<String, String>();
      attributes.put(n,in.getAttributeValue(i));
    }
  }
  if(attributes==null)
    attributes = Collections.emptyMap();
}

代码示例来源:origin: com.sun.xml.stream.buffer/streambuffer

private void storeElement(XMLStreamReader reader) {
  storeQualifiedName(T_ELEMENT_LN,
      reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());
  if (reader.getNamespaceCount() > 0) {
    storeNamespaceAttributes(reader);
  }
  if (reader.getAttributeCount() > 0) {
    storeAttributes(reader);
  }
}

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

private Attributes getAttributes() {
  AttributesImpl attributes = new AttributesImpl();
  for (int i = 0; i < this.reader.getAttributeCount(); i++) {
    String namespace = this.reader.getAttributeNamespace(i);
    if (namespace == null || !hasNamespacesFeature()) {
      namespace = "";
    }
    String type = this.reader.getAttributeType(i);
    if (type == null) {
      type = "CDATA";
    }
    attributes.addAttribute(namespace, this.reader.getAttributeLocalName(i),
        toQualifiedName(this.reader.getAttributeName(i)), type, this.reader.getAttributeValue(i));
  }
  if (hasNamespacePrefixesFeature()) {
    for (int i = 0; i < this.reader.getNamespaceCount(); i++) {
      String prefix = this.reader.getNamespacePrefix(i);
      String namespaceUri = this.reader.getNamespaceURI(i);
      String qName;
      if (StringUtils.hasLength(prefix)) {
        qName = "xmlns:" + prefix;
      }
      else {
        qName = "xmlns";
      }
      attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
    }
  }
  return attributes;
}

相关文章

微信公众号

最新文章

更多