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


Java XMLEvent.isCharacters方法代碼示例

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


在下文中一共展示了XMLEvent.isCharacters方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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:SunburstApps,項目名稱:OpenJSharp,代碼行數: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: 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

示例6: nextTag

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
/** Skips any insignificant space events until a START_ELEMENT or
 * END_ELEMENT is reached. If anything 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
 * the DTD is missing or not interpreted.
 * @throws XMLStreamException if anything other than space characters are encountered
 */
public XMLEvent nextTag() throws XMLStreamException {
    //its really a pain if there is peeked event before calling nextTag()
    if(fPeekedEvent != null){
        //check the peeked event first.
        XMLEvent event = fPeekedEvent;
        fPeekedEvent = null ;
        int eventType = event.getEventType();
        //if peeked event is whitespace move to the next event
        //if peeked event is PI or COMMENT move to the next event
        if( (event.isCharacters() && event.asCharacters().isWhiteSpace())
        || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
        || eventType == XMLStreamConstants.COMMENT
        || eventType == XMLStreamConstants.START_DOCUMENT){
            event = nextEvent();
            eventType = event.getEventType();
        }

        //we have to have the while loop because there can be many PI or comment event in sucession
        while((event.isCharacters() && event.asCharacters().isWhiteSpace())
        || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
        || eventType == XMLStreamConstants.COMMENT){

            event = nextEvent();
            eventType = event.getEventType();
        }

        if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
            throw new XMLStreamException("expected start or end tag", event.getLocation());
        }
        return event;
    }

    //if there is no peeked event -- delegate the work of getting next event to fXMLReader
    fXMLReader.nextTag();
    return (fLastEvent = fXMLEventAllocator.allocate(fXMLReader));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:45,代碼來源:XMLEventReaderImpl.java


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