本文整理匯總了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);
}
示例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();
}