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


Java XMLEvent.asCharacters方法代碼示例

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


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

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

示例2: getElementText

import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public final String getElementText() throws XMLStreamException {
	XMLEvent event = this.previousEvent;
	if (event == null) {
		throw new XMLStreamException("Must be on START_ELEMENT to read next text, element was null");
	}
	if (!event.isStartElement()) {
		throw new XMLStreamException("Must be on START_ELEMENT to read next text", event.getLocation());
	}

	final StringBuilder text = new StringBuilder();
	while (!event.isEndDocument()) {
		switch (event.getEventType()) {
			case XMLStreamConstants.CHARACTERS:
			case XMLStreamConstants.SPACE:
			case XMLStreamConstants.CDATA: {
				final Characters characters = event.asCharacters();
				text.append(characters.getData());
				break;
			}
			case XMLStreamConstants.ENTITY_REFERENCE: {
				final EntityReference entityReference = (EntityReference)event;
				final EntityDeclaration declaration = entityReference.getDeclaration();
				text.append(declaration.getReplacementText());
				break;
			}
			case XMLStreamConstants.COMMENT:
			case XMLStreamConstants.PROCESSING_INSTRUCTION: {
				//Ignore
				break;
			}
			default: {
				throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
			}
		}

		event = this.nextEvent();
	}

	return text.toString();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:42,代碼來源:BaseXMLEventReader.java


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