當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLEvent.asStartElement方法代碼示例

本文整理匯總了Java中javax.xml.stream.events.XMLEvent.asStartElement方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLEvent.asStartElement方法的具體用法?Java XMLEvent.asStartElement怎麽用?Java XMLEvent.asStartElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.stream.events.XMLEvent的用法示例。


在下文中一共展示了XMLEvent.asStartElement方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addRdfIdValues

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private void addRdfIdValues(InputStream is, Set<String> rdfIdValues) throws XMLStreamException {
    // memoize RDF ID values of the document
    XMLEventReader eventReader = xmlStaxContext.inputFactory.createXMLEventReader(is);
    while (eventReader.hasNext()) {
        XMLEvent event = eventReader.nextEvent();
        if (event.isStartElement()) {
            StartElement startElement = event.asStartElement();
            Iterator it = startElement.getAttributes();
            while (it.hasNext()) {
                Attribute attribute = (Attribute) it.next();
                QName name = attribute.getName();
                if (RDF_ID.equals(name)) {
                    rdfIdValues.add(attribute.getValue());
                }
            }
        }
    }
    eventReader.close();
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:20,代碼來源:CimAnonymizer.java

示例2: readXMLByStAX

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
public static void readXMLByStAX() throws XMLStreamException, FileNotFoundException {
	XMLInputFactory factory = XMLInputFactory.newInstance();
	XMLEventReader reader = factory.createXMLEventReader(new FileInputStream("test.xml"));//StaxDemo.class.getResourceAsStream("test.xml")
	XMLEvent event;
	StringBuffer parsingResult = new StringBuffer();
	while (reader.hasNext()) {
		event = reader.nextEvent();
		if (event.isStartElement()) {
			StartElement se = event.asStartElement();
			parsingResult.append("<");
			parsingResult.append(se.getName());
			if (se.getName().getLocalPart().equals("catalog")) {
				parsingResult.append("id=");
				parsingResult.append(se.getAttributeByName(new QName("id")).getValue());
				parsingResult.append("");
			}
			parsingResult.append(">");
		} else if (event.isCharacters()) {
			parsingResult.append(event.asCharacters().getData());
		} else if (event.isEndElement()) {
			parsingResult.append("</");
			parsingResult.append(event.asEndElement().getName());
			parsingResult.append(">");
		}
	}
	System.out.println(parsingResult);
}
 
開發者ID:leon66666,項目名稱:JavaCommon,代碼行數:28,代碼來源:StaxDemo.java

示例3: add

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public void add(XMLEvent event) throws XMLStreamException {
    XMLEvent newEvent = null;

    if (event.isStartElement()) {
        StartElement startElement = event.asStartElement();
        newEvent = anonymizeStartElement(startElement);
    } else if (event.isCharacters()) {
        Characters characters = event.asCharacters();
        newEvent = anonymizeCharacters(characters);
    }

    super.add(newEvent != null ? newEvent : event);
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:15,代碼來源:CimAnonymizer.java

示例4: unmarshal

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
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,代碼行數:40,代碼來源:ExternalAttachmentsUnmarshaller.java

示例5: unmarshalNodeContent

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private String unmarshalNodeContent(final NamespaceVersion nsVersion, final ModelNode node, final QName nodeElementName, final XMLEventReader reader) throws PolicyException {
    StringBuilder valueBuffer = null;

    loop:
    while (reader.hasNext()) {
        try {
            final XMLEvent xmlParserEvent = reader.nextEvent();
            switch (xmlParserEvent.getEventType()) {
                case XMLStreamConstants.COMMENT:
                    break; // skipping the comments
                case XMLStreamConstants.CHARACTERS:
                    valueBuffer = processCharacters(node.getType(), xmlParserEvent.asCharacters(), valueBuffer);
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    checkEndTagName(nodeElementName, xmlParserEvent.asEndElement());
                    break loop; // data exctraction for currently processed policy node is done
                case XMLStreamConstants.START_ELEMENT:
                    final StartElement childElement = xmlParserEvent.asStartElement();

                    ModelNode childNode = addNewChildNode(nsVersion, node, childElement);
                    String value = unmarshalNodeContent(nsVersion, childNode, childElement.getName(), reader);

                    if (childNode.isDomainSpecific()) {
                        parseAssertionData(nsVersion, value, childNode, childElement);
                    }
                    break;
                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0011_UNABLE_TO_UNMARSHALL_POLICY_XML_ELEM_EXPECTED()));
            }
        } catch (XMLStreamException e) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e));
        }
    }

    return (valueBuffer == null) ? null : valueBuffer.toString().trim();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:37,代碼來源:XmlPolicyModelUnmarshaller.java

示例6: testEventReader

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Test
public void testEventReader() {
    try {
        XMLInputFactory ifac = XMLInputFactory.newInstance();
        XMLEventReader read = ifac.createXMLEventReader(this.getClass().getResource(INPUT_FILE).toExternalForm(),
                this.getClass().getResourceAsStream(INPUT_FILE));
        while (read.hasNext()) {
            XMLEvent event = read.nextEvent();
            if (event.isStartElement()) {
                StartElement startElement = event.asStartElement();
                if (startElement.getName().getLocalPart().equals("bookurn")) {
                    Iterator iterator = startElement.getNamespaces();
                    int count = 0;
                    while (iterator.hasNext()) {
                        iterator.next();
                        count++;
                    }
                    Assert.assertTrue(count == 2, "Two namespaces are expected for <bookurn> ");

                    Iterator attributes = startElement.getAttributes();
                    count = 0;
                    while (attributes.hasNext()) {
                        iterator.next();
                        count++;
                    }
                    Assert.assertTrue(count == 0, "Zero attributes are expected for <bookurn> ");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:DefaultAttributeTest.java

示例7: set

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
public void set ( final String expression, final int targetElement, final String value ) throws IOException, XMLStreamException
{
    int pos = 0;

    final Stack<String> ele = new Stack<> ();

    final Pattern pattern = Pattern.compile ( expression );

    final XMLEventReader reader;

    Modification mod = null;

    final XMLInputFactory xmlinf = XMLInputFactory.newInstance ();
    try (final FileInputStream is = new FileInputStream ( this.inputFile ))
    {
        reader = xmlinf.createXMLEventReader ( is );
        try
        {
            while ( reader.hasNext () )
            {
                final XMLEvent event = (XMLEvent)reader.next ();
                if ( event instanceof StartElement )
                {
                    final StartElement startEvent = event.asStartElement ();
                    ele.push ( startEvent.getName ().getLocalPart () );
                }
                else if ( event instanceof EndElement )
                {
                    final EndElement endEvent = event.asEndElement ();
                    final String en = ele.pop ();
                    if ( !endEvent.getName ().getLocalPart ().equals ( en ) )
                    {
                        throw new IllegalStateException ( "Element error: " + en + " / " + endEvent.getName () );
                    }
                }

                boolean inMatch = mod != null;
                final boolean match = isMatch ( ele, pattern );
                if ( inMatch && !match )
                {
                    // end
                    if ( pos == targetElement )
                    {
                        this.mods.add ( mod );
                    }
                    pos++;
                    mod = null;
                }
                else if ( !inMatch && match )
                {
                    // starting
                    mod = new Modification ();
                    mod.start = event.getLocation ().getCharacterOffset ();
                    mod.data = value;
                }
                else if ( inMatch && match )
                {
                    mod.end = event.getLocation ().getCharacterOffset () - 2;
                }
                inMatch = match;
            }
        }
        finally
        {
            reader.close ();
        }
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:69,代碼來源:XmlModifier.java

示例8: readTestResults

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private static Collection<TestResult> readTestResults(XMLEventReader eventReader) throws XMLStreamException {
    final Set<TestResult> testResults = new HashSet<>();
    TestResult currentTestResult = null;

    while (eventReader.hasNext()) {
        XMLEvent event = eventReader.nextEvent();

        if (event.isStartElement()) {
            final StartElement startElement = event.asStartElement();
            if ("testcase".equalsIgnoreCase(startElement.getName().getLocalPart())) {
                // Read attributes
                String name = null, classname = null;
                Status status = null;

                final Iterator<Attribute> attributes = startElement.getAttributes();

                while (attributes.hasNext()) {
                    final Attribute attribute = attributes.next();
                    if ("classname".equalsIgnoreCase(attribute.getName().toString())) {
                        classname = attribute.getValue();
                    }

                    if ("name".equalsIgnoreCase(attribute.getName().toString())) {
                        name = attribute.getValue();
                    }
                }

                currentTestResult = new TestResult(classname, name, Status.PASSED);
            }

            if ("failure".equalsIgnoreCase(startElement.getName().getLocalPart())) {
                currentTestResult.setStatus(Status.FAILURE);
            }

            if ("error".equalsIgnoreCase(startElement.getName().getLocalPart())) {
                currentTestResult.setStatus(Status.ERROR);
            }

            if ("skipped".equalsIgnoreCase(startElement.getName().getLocalPart())) {
                currentTestResult.setStatus(Status.SKIPPED);
            }

            if ("rerunFailure".equalsIgnoreCase(startElement.getName().getLocalPart())) {
                currentTestResult.setStatus(Status.RE_RUN_FAILURE);
            }
        }

        if (event.isEndElement()) {
            final EndElement endElementElement = event.asEndElement();
            if ("testcase".equalsIgnoreCase(endElementElement.getName().getLocalPart())) {
                testResults.add(currentTestResult);
            }
        }
    }
    return testResults;
}
 
開發者ID:arquillian,項目名稱:smart-testing,代碼行數:57,代碼來源:SurefireReportReader.java

示例9: parse

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
    XMLEvent currentEvent = input.peek();
    if (currentEvent != null) {
        int eventType = currentEvent.getEventType();
        if (eventType != XMLStreamConstants.START_DOCUMENT &&
            eventType != XMLStreamConstants.START_ELEMENT) {
            throw new XMLStreamException();
        }
        fLocationWrapper.setLocation(currentEvent.getLocation());
        fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
        loop: while (input.hasNext()) {
            currentEvent = input.nextEvent();
            eventType = currentEvent.getEventType();
            switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                ++fDepth;
                StartElement start = currentEvent.asStartElement();
                fillQName(fElementQName, start.getName());
                fLocationWrapper.setLocation(start.getLocation());
                fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
                fillXMLAttributes(start);
                fillDeclaredPrefixes(start);
                addNamespaceDeclarations();
                fNamespaceContext.pushContext();
                fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
                break;
            case XMLStreamConstants.END_ELEMENT:
                EndElement end = currentEvent.asEndElement();
                fillQName(fElementQName, end.getName());
                fillDeclaredPrefixes(end);
                fLocationWrapper.setLocation(end.getLocation());
                fSchemaDOMParser.endElement(fElementQName, null);
                fNamespaceContext.popContext();
                --fDepth;
                if (fDepth <= 0) {
                    break loop;
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                break;
            case XMLStreamConstants.SPACE:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
                break;
            case XMLStreamConstants.CDATA:
                fSchemaDOMParser.startCDATA(null);
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                fSchemaDOMParser.endCDATA(null);
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                ProcessingInstruction pi = (ProcessingInstruction)currentEvent;
                fillProcessingInstruction(pi.getData());
                fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
                break;
            case XMLStreamConstants.DTD:
                /* There shouldn't be a DTD in the schema */
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                /* Not needed for schemas */
                break;
            case XMLStreamConstants.COMMENT:
                /* No point in sending comments */
                break;
            case XMLStreamConstants.START_DOCUMENT:
                fDepth++;
                /* We automatically call startDocument before the loop */
                break;
            case XMLStreamConstants.END_DOCUMENT:
                /* We automatically call endDocument after the loop */
                break;
            }
        }
        fLocationWrapper.setLocation(null);
        fNamespaceContext.setNamespaceContext(null);
        fSchemaDOMParser.endDocument(null);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:78,代碼來源:StAXSchemaParser.java


注:本文中的javax.xml.stream.events.XMLEvent.asStartElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。