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


Java XMLEvent.isStartElement方法代碼示例

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


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

示例1: nextTag

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public final XMLEvent nextTag() throws XMLStreamException {
	XMLEvent event = this.nextEvent();
	while ((event.isCharacters() && event.asCharacters().isWhiteSpace())
			|| event.isProcessingInstruction()
			|| event.getEventType() == XMLStreamConstants.COMMENT) {

		event = this.nextEvent();
	}

	if (!event.isStartElement()  && event.isEndElement()) {
		throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
	}

	return event;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:BaseXMLEventReader.java

示例2: getElementText

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
public String getElementText() throws XMLStreamException
{
    StringBuffer buffer = new StringBuffer();
    XMLEvent e = nextEvent();
    if (!e.isStartElement())
        throw new XMLStreamException(
        CommonResourceBundle.getInstance().getString("message.mustBeOnSTART_ELEMENT"));

    while(hasNext()) {
        e = nextEvent();
        if(e.isStartElement())
            throw new XMLStreamException(
            CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly"));
        if(e.isCharacters())
            buffer.append(((Characters) e).getData());
        if(e.isEndElement())
            return buffer.toString();
    }
    throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.END_ELEMENTnotFound"));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:StAXFilteredEvent.java

示例3: 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

示例4: 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

示例5: unmarshal0

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private Object unmarshal0(XMLEventReader reader,JaxBeanInfo expectedType) throws JAXBException {
    if (reader == null) {
        throw new IllegalArgumentException(
                Messages.format(Messages.NULL_READER));
    }

    try {
        XMLEvent event = reader.peek();

        if (!event.isStartElement() && !event.isStartDocument()) {
            // TODO: convert event into event name
            throw new IllegalStateException(
                Messages.format(
                    Messages.ILLEGAL_READER_STATE,event.getEventType()));
        }

        // Quick hack until SJSXP fixes 6270116
        boolean isZephyr = reader.getClass().getName().equals("com.sun.xml.internal.stream.XMLReaderImpl");
        XmlVisitor h = createUnmarshallerHandler(null,false,expectedType);
        if(!isZephyr) {
            h = new InterningXmlVisitor(h);
        }
        new StAXEventConnector(reader,h).bridge();
        return h.getContext().getResult();
    } catch (XMLStreamException e) {
        throw handleStreamException(e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:UnmarshallerImpl.java

示例6: handleMissingField

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private void handleMissingField(String fieldName, XMLEventReader parser,
        XMLEvent event, ExtensionRegistry extensionRegistry, 
        UnknownFieldSet.Builder builder) throws XMLStreamException {
	
    // skip over the unknown fields, since we can't map them by id, then this message must not know about them.
    // We 'could' map them into the UnknownFieldSet, however none of the other formatters support this..
    // but in the future it would probably be useful for the case: Message A (v2) -> Message B (v1) -> Xml -> Message A (v2) 
    // this would require extra meta data in the xml to know the type of the unknown-field.
    
    
    if (event.isStartElement()) {
        /**
         * This loop will eat up everything inside "6"
         * So when this method is called, fieldName = 6, and event is set at index="11"
         * <unknown-field index="6">
         *      <unknown-field index="11">566667</unknown-field>
         *      <unknown-field index="15">
         *          <unknown-field index="16">566667</unknown-field>
         *      </unknown-field>
         * </unknown-field>
         */
        int depth = 1; // we start 1 level down, the value of "6"
        while (parser.hasNext()) {
            XMLEvent nextEvent = parser.nextEvent();
            if (nextEvent.isEndElement()) {
                depth--;
                if (depth <= 0 && parser.peek().isEndElement()) {
                    break;
                }
            } else if (nextEvent.isStartElement()) {
                depth++;
            }
        }
    } else if (event.isCharacters()) {
        // done, let it slide.
    }
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:38,代碼來源:XmlJavaxFormat.java

示例7: handleObject

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private Object handleObject(XMLEventReader parser,
        XMLEvent startEvent,
        ExtensionRegistry extensionRegistry, 
        Message.Builder builder,
        FieldDescriptor field, 
        ExtensionRegistry.ExtensionInfo extension) throws XMLStreamException {

    Message.Builder subBuilder = createSubBuilder(builder, field, extension);

    XMLEvent event = startEvent;
    int depth = 0; // initialize to 0
    do {
        if (event.isStartElement()) {
            depth++; // we're inside the element
            mergeField(parser, event, 
                    extensionRegistry, subBuilder);
            XMLEvent nextEvent = parser.nextTag();
            
            if (nextEvent.isEndElement()) {
                depth--;
                // if we're back under the top level obj, and there is another close, we're done.
                if (depth <= 0 && parser.peek().isEndElement()) {
                    break;
                }
            } else if (nextEvent.isStartElement()) {
                depth++;
            }
        } else {
            // something is potentially wrong..
            break;
        }
    } while (parser.hasNext() && (event = parser.nextTag()) != null);
    
    return subBuilder.build();
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:36,代碼來源:XmlJavaxFormat.java

示例8: nextEvent

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public XMLEvent nextEvent() throws XMLStreamException {
	XMLEvent event = super.nextEvent();
	if ( event.isStartElement() ) {
		return withNamespace( event.asStartElement() );
	}
	return event;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:JaxbProcessor.java

示例9: peek

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public XMLEvent peek() throws XMLStreamException {
	XMLEvent event = super.peek();
	if ( event.isStartElement() ) {
		return withNamespace( event.asStartElement() );
	}
	else {
		return event;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:11,代碼來源:JaxbProcessor.java

示例10: read

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private XmlDocument read(XMLEventReader staxEventReader, Origin origin) {
	XMLEvent event;
	try {
		event = staxEventReader.peek();
		while ( event != null && !event.isStartElement() ) {
			staxEventReader.nextEvent();
			event = staxEventReader.peek();
		}
	}
	catch ( Exception e ) {
		throw new InvalidMappingException( "Error accessing stax stream", origin, e );
	}

	if ( event == null ) {
		throw new InvalidMappingException( "Could not locate root element", origin );
	}

	final String rootElementName = event.asStartElement().getName().getLocalPart();

	if ( "entity-mappings".equals( rootElementName ) ) {
		final Attribute attribute = event.asStartElement().getAttributeByName( ORM_VERSION_ATTRIBUTE_QNAME );
		final String explicitVersion = attribute == null ? null : attribute.getValue();
		validateMapping(
				SupportedOrmXsdVersion.parse( explicitVersion, origin ),
				staxEventReader,
				origin
		);
	}

	return new XmlDocumentImpl( toDom4jDocument( staxEventReader, origin ), origin );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:MappingReader.java

示例11: nextTag

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
public XMLEvent nextTag() throws XMLStreamException {
    while(hasNext()) {
        XMLEvent e = nextEvent();
        if (e.isStartElement() || e.isEndElement())
            return e;
    }
    throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.startOrEndNotFound"));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:StAXFilteredEvent.java

示例12: 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

示例13: unmarshall

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public S3KeyFilter unmarshall(StaxUnmarshallerContext context) throws Exception {
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) {
        targetDepth += 1;
    }

    S3KeyFilter filter = new S3KeyFilter();

    while (true) {
        XMLEvent xmlEvent = context.nextEvent();
        if (xmlEvent.isEndDocument()) {
            return filter;
        }

        if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
            if (context.testExpression("FilterRule", targetDepth)) {
                filter.addFilterRule(FilterRuleStaxUnmarshaller.getInstance().unmarshall(context));
            }
        } else if (xmlEvent.isEndElement()) {
            if (context.getCurrentDepth() < originalDepth) {
                return filter;
            }
        }
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:29,代碼來源:S3KeyFilterStaxUnmarshaller.java

示例14: unmarshall

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public Filter unmarshall(StaxUnmarshallerContext context) throws Exception {
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) {
        targetDepth += 1;
    }

    Filter filter = new Filter();

    while (true) {
        XMLEvent xmlEvent = context.nextEvent();
        if (xmlEvent.isEndDocument()) {
            return filter;
        }

        if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
            if (context.testExpression("S3Key", targetDepth)) {
                filter.withS3KeyFilter(S3KeyFilterStaxUnmarshaller.getInstance().unmarshall(context));
            }
        } else if (xmlEvent.isEndElement()) {
            if (context.getCurrentDepth() < originalDepth) {
                return filter;
            }
        }
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:29,代碼來源:FilterStaxUnmarshaller.java

示例15: unmarshall

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public FilterRule unmarshall(StaxUnmarshallerContext context) throws Exception {
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) {
        targetDepth += 1;
    }

    FilterRule filter = new FilterRule();

    while (true) {
        XMLEvent xmlEvent = context.nextEvent();
        if (xmlEvent.isEndDocument()) {
            return filter;
        }
        if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
            if (context.testExpression("Name", targetDepth)) {
                filter.setName(StringStaxUnmarshaller.getInstance().unmarshall(context));
            } else if (context.testExpression("Value", targetDepth)) {
                filter.setValue(StringStaxUnmarshaller.getInstance().unmarshall(context));
            }
        } else if (xmlEvent.isEndElement()) {
            if (context.getCurrentDepth() < originalDepth) {
                return filter;
            }
        }
    }

}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:31,代碼來源:FilterRuleStaxUnmarshaller.java


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