当前位置: 首页>>代码示例>>Java>>正文


Java XMLStreamConstants.START_ELEMENT属性代码示例

本文整理汇总了Java中javax.xml.stream.XMLStreamConstants.START_ELEMENT属性的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamConstants.START_ELEMENT属性的具体用法?Java XMLStreamConstants.START_ELEMENT怎么用?Java XMLStreamConstants.START_ELEMENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.xml.stream.XMLStreamConstants的用法示例。


在下文中一共展示了XMLStreamConstants.START_ELEMENT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNamespaceContext

@Test
public void testNamespaceContext() {
    is = new java.io.ByteArrayInputStream(getXML().getBytes());
    try {
        XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    NamespaceContext context = sr.getNamespaceContext();
                    Assert.assertTrue(context.getPrefix(namespaceURIApple).equals(prefixApple));
                }
            }
        }
    } catch (Exception ex) {
        Assert.fail("Exception: " + ex.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Bug6481678.java

示例2: accept

@Override
public void accept(XMLStreamReader xr) {
	if(xr.getEventType() == XMLStreamConstants.START_ELEMENT
			&& xr.getLocalName().equals("offset")) {
		
		this.currId = xr.getAttributeValue(null, "idRef");
		
	} else if(xr.getEventType() == XMLStreamConstants.CHARACTERS
			&& this.currId != null){
		
		this.currOffset = Long.valueOf(xr.getText());
		
	} else if(xr.getEventType() == XMLStreamConstants.END_ELEMENT
			&& xr.getLocalName().equals("offset")){
		
		this.idToOffsets.put(this.currId, this.currOffset);
		this.offsets.add(this.currOffset);
		this.currId = null;
		this.currOffset = -1;
		
	}
}
 
开发者ID:digitalproteomics,项目名称:dp-mzml,代码行数:22,代码来源:SpectrumIndexer.java

示例3: readFeatureMap

/**
 * Processes a GateDocumentFeatures or Annotation element to build a
 * feature map. The element is expected to contain Feature children,
 * each with a Name and Value. The reader will be returned positioned
 * on the closing GateDocumentFeatures or Annotation tag.
 * 
 * @throws XMLStreamException
 */
public static FeatureMap readFeatureMap(XMLStreamReader xsr)
        throws XMLStreamException {
  FeatureMap fm = Factory.newFeatureMap();
  while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
    xsr.require(XMLStreamConstants.START_ELEMENT, null, "Feature");
    Object featureName = null;
    Object featureValue = null;
    while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
      if("Name".equals(xsr.getLocalName())) {
        featureName = readFeatureNameOrValue(xsr);
      }
      else if("Value".equals(xsr.getLocalName())) {
        featureValue = readFeatureNameOrValue(xsr);
      }
      else {
        throw new XMLStreamException("Feature element should contain "
                + "only Name and Value children", xsr.getLocation());
      }
    }
    fm.put(featureName, featureValue);
  }
  return fm;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:31,代码来源:DocumentStaxUtils.java

示例4: readXcesFeatureMap

/**
 * Processes a struct element to build a feature map. The element is
 * expected to contain feat children, each with name and value
 * attributes. The reader will be returned positioned on the closing
 * struct tag.
 * 
 * @throws XMLStreamException
 */
public static FeatureMap readXcesFeatureMap(XMLStreamReader xsr)
        throws XMLStreamException {
  FeatureMap fm = Factory.newFeatureMap();
  while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
    xsr.require(XMLStreamConstants.START_ELEMENT, XCES_NAMESPACE, "feat");
    String featureName = xsr.getAttributeValue(null, "name");
    Object featureValue = xsr.getAttributeValue(null, "value");

    fm.put(featureName, featureValue);
    // read the (possibly virtual) closing tag of the feat element
    xsr.nextTag();
    xsr.require(XMLStreamConstants.END_ELEMENT, XCES_NAMESPACE, "feat");
  }
  return fm;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:23,代码来源:DocumentStaxUtils.java

示例5: nextTag

/**
 * {@inheritDoc}
 */
@Override
public int nextTag() throws XMLStreamException {
    int tag = super.nextTag();
    if (tracing) {
        switch (tag) {
        case XMLStreamConstants.START_ELEMENT:
            System.err.println("[" + getLocalName());
            break;
        case XMLStreamConstants.END_ELEMENT:
            System.err.println(getLocalName() + "]");
            break;
        default:
            System.err.println((tagStrings.containsKey(tag))
                ? tagStrings.get(tag)
                : "Weird tag: " + tag);
            break;
        }
    }
    return tag;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:23,代码来源:FreeColXMLReader.java

示例6: moveToNextSpectrum

/**
 * Jumps to first spectrum xml, and parses referenceable param groups elements along the way
 * @return
 * @throws XMLStreamException
 */
public boolean moveToNextSpectrum() throws XMLStreamException {
	ReferenceableParamGroup currGroup = null;
	
	while(this.xr.hasNext()){
		this.xr.next();
		if(this.xr.getEventType() == XMLStreamConstants.START_ELEMENT){
			if(this.xr.getLocalName().equals("referenceableParamGroup")){
				currGroup = new ReferenceableParamGroup(this.xr);
			} else if(this.xr.getLocalName().equals("spectrum")){
				return true;
			} else if(currGroup != null){
				currGroup.accept(this.xr);
			}
		} else if(this.xr.getEventType() == XMLStreamConstants.END_ELEMENT 
				&& this.xr.getLocalName().equals("referenceableParamGroup")){
			MzMLStAXParser.this.refParams.put(currGroup.getId(), currGroup.build());
			currGroup = null;
		}
	}
	return false;
}
 
开发者ID:digitalproteomics,项目名称:dp-mzml,代码行数:26,代码来源:MzMLStAXParser.java

示例7: nextTag

/**
 * Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION) until
 * a START_ELEMENT or END_ELEMENT is reached. If other than space characters
 * are encountered, an exception is thrown. This method should be used when
 * processing element-only content because the parser is not able to
 * recognize ignorable whitespace if then DTD is missing or not interpreted.
 *
 * @return the event type of the element read
 * @throws XMLStreamException if the current event is not white space
 */
public int nextTag() throws XMLStreamException {

    int eventType = next();
    while ((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
            || (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
            // skip whitespace
            || eventType == XMLStreamConstants.SPACE
            || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
            || eventType == XMLStreamConstants.COMMENT) {
        eventType = next();
    }

    if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
        throw new XMLStreamException(
                "found: " + getEventTypeString(eventType)
                + ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT)
                + " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT),
                getLocation());
    }

    return eventType;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:XMLStreamReaderImpl.java

示例8: readXML

private void readXML(byte[] xmlData, String expectedContent)
        throws Exception {
    InputStream stream = new ByteArrayInputStream(xmlData);
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader xmlReader
            = factory.createXMLStreamReader(stream);
    boolean inTestElement = false;
    StringBuilder sb = new StringBuilder();
    while (xmlReader.hasNext()) {
        String ename;
        switch (xmlReader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT:
                ename = xmlReader.getLocalName();
                if (ename.equals("writeCharactersWithString")
                        || ename.equals("writeCharactersWithArray")) {
                    inTestElement = true;
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                ename = xmlReader.getLocalName();
                if (ename.equals("writeCharactersWithString")
                        || ename.equals("writeCharactersWithArray")) {
                    inTestElement = false;
                    String content = sb.toString();
                    System.out.println(ename + " text:'" + content + "' expected:'" + expectedContent+"'");
                    Assert.assertEquals(content, expectedContent);
                    sb.setLength(0);
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                if (inTestElement) {
                    sb.append(xmlReader.getText());
                }
                break;
        }
        xmlReader.next();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:SurrogatesTest.java

示例9: getPayloadAttributeValue

@Override
public String getPayloadAttributeValue(QName attName) {
    if (lazySource.isPayloadStreamReader()) {
        XMLStreamReader reader = lazySource.readPayload();
        if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
            return reader.getAttributeValue(attName.getNamespaceURI(), attName.getLocalPart());
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:StaxLazySourceBridge.java

示例10: parse

/**
 * Method for parsing orders XML.
 * @param is input stream for parsing.
 * @return SortedMap of OrderBook's mapping key name.
 * @throws FileNotFoundException if there is no such file.
 * @throws XMLStreamException The base exception for unexpected processing errors.  This Exception
 * class is used to report well-formedness errors as well as unexpected
 * processing conditions.
 */
public SortedMap<String, OrderBook> parse(InputStream is) throws FileNotFoundException, XMLStreamException {
    SortedMap<String, OrderBook> orders = new TreeMap<>(String::compareTo);
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader reader = factory.createXMLStreamReader(is);
    OrderBook orderBook;
    String book;
    reader.next();
    while (reader.hasNext()) {
        if (reader.next() == XMLStreamConstants.START_ELEMENT) {
            if (reader.isStartElement()) {
                book = reader.getAttributeValue(null, "book");
                if ("AddOrder".equals(reader.getLocalName())) {
                    if (!orders.containsKey(book)) {
                        orderBook = new OrderBook(book);
                        orders.put(book, orderBook);
                    } else {
                        orderBook = orders.get(book);
                    }
                    orderBook.addOrder(OrderBook.OPERATION.valueOf(reader.getAttributeValue(null, "operation")),
                            Integer.parseInt(reader.getAttributeValue(null, "orderId")),
                            Integer.parseInt(reader.getAttributeValue(null, "volume")),
                            Float.parseFloat(reader.getAttributeValue(null, "price")));
                } else {
                    orders.get(book).delOrder(Integer.parseInt(reader.getAttributeValue(null, "orderId")));
                }
            }
        }
    }
    return orders;
}
 
开发者ID:PavelZubaha,项目名称:pzubaha,代码行数:39,代码来源:StAXParser.java

示例11: handleStartElement

/**
 * Parses the current element parser element. This method must only be called when the given stream reader points to a START_ELEMENT
 *
 * @param r the stream reader
 * @return the deserialized element
 * @throws XMLStreamException
 */
private Object handleStartElement( XMLStreamReader r ) throws XMLStreamException {
    String currentObjectName = r.getLocalName().toLowerCase();

    Map<String, String> attributes = new HashMap<>();
    for( int i = 0; i < r.getAttributeCount(); i++ )
        attributes.put( r.getAttributeLocalName( i ).toLowerCase(), r.getAttributeValue( i ) );

    NessusObject nessusObject = nessusObjectByName.containsKey( currentObjectName ) ? nessusObjectByName.get( currentObjectName ) : defaultObject;
    Object element = nessusObject.create( currentObjectName, attributes );

    while( r.hasNext() ) {
        switch( r.next() ) {
            case XMLStreamConstants.START_ELEMENT:
                Object child = handleStartElement( r );
                nessusObject.gotChild( element, child );
                break;

            case XMLStreamConstants.CHARACTERS:
                nessusObject.gotTextValue( element, r.getText() );
                break;

            case XMLStreamConstants.END_ELEMENT:
                return element;
        }
    }

    // should never happen the only return should be from END_ELEMENT
    return null;
}
 
开发者ID:tenable,项目名称:Tenable.io-SDK-for-Java,代码行数:36,代码来源:NessusFileParser.java

示例12: getAttributes

/**
 * Get the attributes associated with the given START_ELEMENT or ATTRIBUTE
 * StAXevent.
 *
 * @return the StAX attributes converted to an org.xml.sax.Attributes
 */
private Attributes getAttributes() {
    AttributesImpl attrs = new AttributesImpl();

    int eventType = staxStreamReader.getEventType();
    if (eventType != XMLStreamConstants.ATTRIBUTE
        && eventType != XMLStreamConstants.START_ELEMENT) {
        throw new InternalError(
            "getAttributes() attempting to process: " + eventType);
    }

    // in SAX, namespace declarations are not part of attributes by default.
    // (there's a property to control that, but as far as we are concerned
    // we don't use it.) So don't add xmlns:* to attributes.

    // gather non-namespace attrs
    for (int i = 0; i < staxStreamReader.getAttributeCount(); i++) {
        String uri = staxStreamReader.getAttributeNamespace(i);
        if(uri==null)   uri="";
        String localName = staxStreamReader.getAttributeLocalName(i);
        String prefix = staxStreamReader.getAttributePrefix(i);
        String qName;
        if(prefix==null || prefix.length()==0)
            qName = localName;
        else
            qName = prefix + ':' + localName;
        String type = staxStreamReader.getAttributeType(i);
        String value = staxStreamReader.getAttributeValue(i);

        attrs.addAttribute(uri, localName, qName, type, value);
    }

    return attrs;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:XMLStreamReaderToContentHandler.java

示例13: getAttribute

@Nullable
public String getAttribute(@NotNull String nsUri, @NotNull String localName) {
    try {
        XMLStreamReader sr = epr.read("EndpointReference"/*doesn't matter*/);
        while(sr.getEventType()!= XMLStreamConstants.START_ELEMENT)
            sr.next();

        return sr.getAttributeValue(nsUri,localName);
    } catch (XMLStreamException e) {
        // since we are reading from buffer, this can't happen.
        throw new AssertionError(e);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:EPRHeader.java

示例14: unmarshal

private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException {
    XMLEvent event = null;
    while (reader.hasNext()) {
        try {
            event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.CHARACTERS:
                    processCharacters(event.asCharacters(), parentElement, map);
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.END_ELEMENT:
                    processEndTag(event.asEndElement(), parentElement);
                    reader.nextEvent();
                    return map;

                case XMLStreamConstants.START_ELEMENT:
                    final StartElement element = event.asStartElement();
                    processStartTag(element, parentElement, reader, map);
                    break;

                case XMLStreamConstants.END_DOCUMENT:
                    return map;

                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event)));
            }
        } catch (XMLStreamException e) {
            final Location location = event == null ? null : event.getLocation();
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e);
        }
    }
    return map;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:ExternalAttachmentsUnmarshaller.java

示例15: testStAX

@Test(dataProvider = "xml-data")
public void testStAX(String xml, int chunkSize, int expectedNumOfChunks, boolean withinLimit) throws Exception {
    XMLInputFactory xifactory = XMLInputFactory.newInstance();
    xifactory.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", true);
    if (chunkSize > 0) {
        xifactory.setProperty(CDATA_CHUNK_SIZE, chunkSize);
    }
    XMLStreamReader streamReader = xifactory.createXMLStreamReader(new StringReader(xml));

    StringBuilder cdata = new StringBuilder();
    int numOfChunks = 0;
    boolean isWithinLimit = true;
    while (streamReader.hasNext()) {
        int eventType = streamReader.next();
        switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                debugPrint("\nElement: " + streamReader.getLocalName());
                break;
            case XMLStreamConstants.CDATA:
                String text = streamReader.getText();
                numOfChunks++;
                if (text.length() > chunkSize) {
                    isWithinLimit = false;
                }
                debugPrint("\nCDATA: " + text.length());
                cdata.append(text);
                break;
            case XMLStreamConstants.CHARACTERS:
                debugPrint("\nCharacters: " + streamReader.getText().length());
                break;
        }
    }
    debugPrint("CData in single chunk:" + cdata.toString().length());
    Assert.assertEquals(numOfChunks, expectedNumOfChunks);
    Assert.assertEquals(isWithinLimit, withinLimit);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:CDataChunkSizeTest.java


注:本文中的javax.xml.stream.XMLStreamConstants.START_ELEMENT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。