/**
* @param namespaceURI
* @param localName
* @return
*/
public String getAttributeValue(String namespaceURI, String localName) {
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
XMLAttributesImpl attributes = fScanner.getAttributeIterator();
if (namespaceURI == null) { //sjsxp issue 70
return attributes.getValue(attributes.getIndexByLocalName(localName)) ;
} else {
return fScanner.getAttributeIterator().getValue(
namespaceURI.length() == 0 ? null : namespaceURI, localName) ;
}
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeValue()") ;
}
}
java类javax.xml.stream.events.XMLEvent的实例源码
XMLStreamReaderImpl.java 文件源码
项目:OpenJSharp
阅读 21
收藏 0
点赞 0
评论 0
TsoFrequencySecurityIndex.java 文件源码
项目:powsybl-core
阅读 14
收藏 0
点赞 0
评论 0
public static TsoFrequencySecurityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
String text = null;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
switch (eventType) {
case XMLEvent.CHARACTERS:
text = xmlsr.getText();
break;
case XMLEvent.END_ELEMENT:
if ("freq-out-count".equals(xmlsr.getLocalName())) {
return new TsoFrequencySecurityIndex(contingencyId, Integer.parseInt(text));
}
break;
default:
break;
}
}
throw new AssertionError("freq-out-count element not found");
}
Bug6976938Test.java 文件源码
项目:openjdk-jdk10
阅读 28
收藏 0
点赞 0
评论 0
public void eventReaderTest(XMLInputFactory xif) {
XMLEventReader eventReader = null;
try {
eventReader = xif.createXMLEventReader(this.getClass().getResourceAsStream(INPUT_FILE));
XMLEventReader filteredEventReader = xif.createFilteredReader(eventReader, new EventFilter() {
public boolean accept(XMLEvent event) {
if (!event.isStartElement()) {
return false;
}
QName elementQName = event.asStartElement().getName();
if ((elementQName.getLocalPart().equals(ATTACHMENT_NAME.getLocalPart()) || elementQName.getLocalPart().equals("Attachment"))
&& elementQName.getNamespaceURI().equals(VF_GENERIC_TT_NAMESPACE)) {
return true;
}
return false;
}
});
if (filteredEventReader.hasNext()) {
System.out.println("containsAttachments() returns true");
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
} finally {
if (eventReader != null) {
try {
eventReader.close();
} catch (XMLStreamException xse) {
// Ignored by intention
}
}
}
}
BaseXMLEventReader.java 文件源码
项目:lams
阅读 20
收藏 0
点赞 0
评论 0
@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;
}
XMLDocumentScannerImpl.java 文件源码
项目:openjdk-jdk10
阅读 15
收藏 0
点赞 0
评论 0
public void reset(PropertyManager propertyManager) {
super.reset(propertyManager);
// other settings
fDoctypeName = null;
fDoctypePublicId = null;
fDoctypeSystemId = null;
fSeenDoctypeDecl = false;
fNamespaceContext.reset();
fSupportDTD = ((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue();
// xerces features
fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue();
setScannerState(XMLEvent.START_DOCUMENT);
setDriver(fXMLDeclDriver);
fSeenInternalSubset = false;
if(fDTDScanner != null){
((XMLDTDScannerImpl)fDTDScanner).reset(propertyManager);
}
fEndPos = 0;
fStartPos = 0;
if(fDTDDecl != null){
fDTDDecl.clear();
}
}
MappingReader.java 文件源码
项目:lams
阅读 20
收藏 0
点赞 0
评论 0
private Document toDom4jDocument(XMLEventReader staxEventReader, Origin origin) {
STAXEventReader dom4jStaxEventReader = new STAXEventReader();
try {
// the dom4j converter class is touchy about comments (aka, comments make it implode)
// so wrap the event stream in a filtering stream to filter out comment events
staxEventReader = new FilteringXMLEventReader( staxEventReader ) {
@Override
protected XMLEvent filterEvent(XMLEvent event, boolean peek) {
return event.getEventType() == XMLStreamConstants.COMMENT
? null
: event;
}
};
return dom4jStaxEventReader.readDocument( staxEventReader );
}
catch (XMLStreamException e) {
throw new InvalidMappingException( "Unable to read StAX source as dom4j Document for processing", origin, e );
}
}
StAXFilteredEvent.java 文件源码
项目:OpenJSharp
阅读 20
收藏 0
点赞 0
评论 0
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"));
}
StAXFilteredEvent.java 文件源码
项目:openjdk-jdk10
阅读 15
收藏 0
点赞 0
评论 0
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"));
}
StaxUnmarshallerContext.java 文件源码
项目:ibm-cos-sdk-java
阅读 20
收藏 0
点赞 0
评论 0
/**
* Returns the text contents of the current element being parsed.
*
* @return The text contents of the current element being parsed.
* @throws XMLStreamException
*/
public String readText() throws XMLStreamException {
if (isInsideResponseHeader()) {
return getHeader(currentHeader);
}
if (currentEvent.isAttribute()) {
Attribute attribute = (Attribute)currentEvent;
return attribute.getValue();
}
StringBuilder sb = new StringBuilder();
while (true) {
XMLEvent event = eventReader.peek();
if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
eventReader.nextEvent();
sb.append(event.asCharacters().getData());
} else if (event.getEventType() == XMLStreamConstants.END_ELEMENT) {
return sb.toString();
} else {
throw new RuntimeException("Encountered unexpected event: " + event.toString());
}
}
}
StAXEvent2SAX.java 文件源码
项目:OpenJSharp
阅读 25
收藏 0
点赞 0
评论 0
private void handleStartDocument(final XMLEvent event) throws SAXException {
_sax.setDocumentLocator(new Locator2() {
public int getColumnNumber() {
return event.getLocation().getColumnNumber();
}
public int getLineNumber() {
return event.getLocation().getLineNumber();
}
public String getPublicId() {
return event.getLocation().getPublicId();
}
public String getSystemId() {
return event.getLocation().getSystemId();
}
public String getXMLVersion(){
return version;
}
public String getEncoding(){
return encoding;
}
});
_sax.startDocument();
}
XMLDocumentScannerImpl.java 文件源码
项目:OpenJSharp
阅读 17
收藏 0
点赞 0
评论 0
public void reset(PropertyManager propertyManager) {
super.reset(propertyManager);
// other settings
fDoctypeName = null;
fDoctypePublicId = null;
fDoctypeSystemId = null;
fSeenDoctypeDecl = false;
fNamespaceContext.reset();
fSupportDTD = ((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue();
// xerces features
fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue();
setScannerState(XMLEvent.START_DOCUMENT);
setDriver(fXMLDeclDriver);
fSeenInternalSubset = false;
if(fDTDScanner != null){
((XMLDTDScannerImpl)fDTDScanner).reset(propertyManager);
}
fEndPos = 0;
fStartPos = 0;
if(fDTDDecl != null){
fDTDDecl.clear();
}
}
Issue58Test.java 文件源码
项目:openjdk-jdk10
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void testLocation() {
String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n"
+ "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n"
+ "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>\n" + "<root />";
try {
XMLEventReader er = getReader(XML);
XMLEvent evt = er.nextEvent(); // StartDocument
Location loc1 = evt.getLocation();
System.out.println("Location 1: " + loc1.getLineNumber() + "," + loc1.getColumnNumber());
evt = er.nextEvent(); // DTD
// loc1 should not change so its line number should still be 1
Assert.assertTrue(loc1.getLineNumber() == 1);
Location loc2 = evt.getLocation();
System.out.println("Location 2: " + loc2.getLineNumber() + "," + loc2.getColumnNumber());
evt = er.nextEvent(); // root
System.out.println("Location 1: " + loc1.getLineNumber() + "," + loc1.getColumnNumber());
Assert.assertTrue(loc1.getLineNumber() == 1);
Assert.assertTrue(loc2.getLineNumber() == 7);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
ReaderToWriterTest.java 文件源码
项目:openjdk-jdk10
阅读 31
收藏 0
点赞 0
评论 0
/**
* Test: 6419687 NPE in XMLEventWriterImpl.
*/
@Test
public void testCR6419687() {
try {
InputStream in = getClass().getResourceAsStream("ReaderToWriterTest.wsdl");
OutputStream out = new FileOutputStream(USER_DIR + "ReaderToWriterTest-out.xml");
XMLEventReader reader = XML_INPUT_FACTORY.createXMLEventReader(in);
XMLEventWriter writer = XML_OUTPUT_FACTORY.createXMLEventWriter(out, "UTF-8");
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
writer.add(event);
}
reader.close();
writer.close();
} catch (XMLStreamException xmlStreamException) {
xmlStreamException.printStackTrace();
Assert.fail(xmlStreamException.toString());
} catch (FileNotFoundException fileNotFoundException) {
fileNotFoundException.printStackTrace();
Assert.fail(fileNotFoundException.toString());
}
}
XMLStreamReaderImpl.java 文件源码
项目:openjdk-jdk10
阅读 18
收藏 0
点赞 0
评论 0
/**
* @param namespaceURI
* @param localName
* @return
*/
public String getAttributeValue(String namespaceURI, String localName) {
//State should be either START_ELEMENT or ATTRIBUTE
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
XMLAttributesImpl attributes = fScanner.getAttributeIterator();
if (namespaceURI == null) { //sjsxp issue 70
return attributes.getValue(attributes.getIndexByLocalName(localName));
} else {
return fScanner.getAttributeIterator().getValue(
namespaceURI.length() == 0 ? null : namespaceURI, localName);
}
} else {
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeValue()");
}
}
XMLStreamReaderImpl.java 文件源码
项目:OpenJSharp
阅读 23
收藏 0
点赞 0
评论 0
private void switchToXML11Scanner() throws IOException{
int oldEntityDepth = fScanner.fEntityDepth;
com.sun.org.apache.xerces.internal.xni.NamespaceContext oldNamespaceContext = fScanner.fNamespaceContext;
fScanner = new XML11NSDocumentScannerImpl();
//get the new scanner state to old scanner's previous state
fScanner.reset(fPropertyManager);
fScanner.setPropertyManager(fPropertyManager);
fEntityScanner = (XMLEntityScanner)fEntityManager.getEntityScanner() ;
fEntityManager.fCurrentEntity.mayReadChunks = true;
fScanner.setScannerState(XMLEvent.START_DOCUMENT);
fScanner.fEntityDepth = oldEntityDepth;
fScanner.fNamespaceContext = oldNamespaceContext;
fEventType = fScanner.next();
}
XMLStreamWriterTest.java 文件源码
项目:openjdk-jdk10
阅读 25
收藏 0
点赞 0
评论 0
/**
* @bug 8139584
* Verifies that the resulting XML contains the standalone setting.
*/
@Test
public void testCreateStartDocument_DOMWriter()
throws ParserConfigurationException, XMLStreamException {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
XMLEventWriter eventWriter = xof.createXMLEventWriter(new DOMResult(doc));
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true);
eventWriter.add(event);
eventWriter.flush();
Assert.assertEquals(doc.getXmlEncoding(), "iso-8859-15");
Assert.assertEquals(doc.getXmlVersion(), "1.0");
Assert.assertTrue(doc.getXmlStandalone());
}
AXMLParser.java 文件源码
项目:InComb
阅读 27
收藏 0
点赞 0
评论 0
/**
* Reads the data from the {@link XMLEvent} and returns it. CData
* will be handled special.
* @param event {@link XMLEvent}
* @param eventReader Reader for Reading {@link XMLEvent}
* @return Character data from element
* @throws XMLStreamException
*/
private String getCharacterData(XMLEvent event, final XMLEventReader eventReader) throws XMLStreamException {
String result = "";
event = eventReader.nextEvent();
if (event instanceof Characters) {
result = event.asCharacters().getData();
}
return result;
}
DefaultRssParser.java 文件源码
项目:InComb
阅读 17
收藏 0
点赞 0
评论 0
/**
* Creates a new Parser Object.
* @param contentSource - {@link ContentSource} to parse
* @param inputStream - Created {@link InputStream} providing the RSS feed to parse.
*/
public DefaultRssParser(final ContentSource contentSource, final InputStream inputStream) {
super(contentSource, inputStream);
availableSetters = new String [] {"setTitle", "setDescription", "setLink", "setImage", "setWidth", "setHeight", "setPubDate", "setEnclosure", "setLastBuildDate"};
try {
startElementMethods.put(RSS, ObjectUtil.assertNotNull(getDeclaredMethod("createParsingElement", String.class, XMLEvent.class, XMLEventReader.class), RSS));
startElementMethods.put(CHANNEL, ObjectUtil.assertNotNull(getDeclaredMethod("pushElementIntoMap", String.class, XMLEvent.class, XMLEventReader.class), CHANNEL));
startElementMethods.put(ITEM, ObjectUtil.assertNotNull(getDeclaredMethod("pushElementIntoMap", String.class, XMLEvent.class, XMLEventReader.class), ITEM));
// used for the channel
startElementMethods.put(LAST_BUILD_DATE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), LAST_BUILD_DATE));
// used only in item
startElementMethods.put(TITLE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), TITLE));
startElementMethods.put(LINK, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), LINK));
startElementMethods.put(DESCRIPTION, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), DESCRIPTION));
startElementMethods.put(LANGUAGE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), LANGUAGE));
startElementMethods.put(PUB_DATE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), PUB_DATE));
startElementMethods.put(IMAGE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), IMAGE));
startElementMethods.put(ENCLOSURE, ObjectUtil.assertNotNull(getDeclaredMethod("parseStandardElement", String.class, XMLEvent.class, XMLEventReader.class), ENCLOSURE));
endElementMehods.put(CHANNEL, ObjectUtil.assertNotNull(getDeclaredMethod("popElementFromStack"), CHANNEL));
endElementMehods.put(ITEM, ObjectUtil.assertNotNull(getDeclaredMethod("popElementFromStack"), ITEM));
specialMethods.put(ITEM, ObjectUtil.assertNotNull(getDeclaredMethod("createItemObject"), ITEM));
} catch (final SecurityException e) {
LOGGER.error("Failed creating {} because", getClass(), e );
}
}
XMLStreamReaderImpl.java 文件源码
项目:OpenJSharp
阅读 31
收藏 0
点赞 0
评论 0
/** Returns the value of the attribute at the
* index
* @param index the position of the attribute
* @return the attribute value
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
*/
public String getAttributeValue(int index) {
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getValue(index) ;
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeValue()") ;
}
}
XMLStreamReaderImpl.java 文件源码
项目:openjdk-jdk10
阅读 23
收藏 0
点赞 0
评论 0
/**
* @return
*/
public String getNamespaceURI() {
//doesn't take care of Attribute as separte event
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT) {
return fScanner.getElementQName().uri;
}
return null;
}
XMLStreamReaderImpl.java 文件源码
项目:openjdk-jdk10
阅读 21
收藏 0
点赞 0
评论 0
/**
* @return
*/
public char[] getTextCharacters() {
if (fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT
|| fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE) {
return fScanner.getCharacterData().ch;
} else {
throw new IllegalStateException("Current state = " + getEventTypeString(fEventType)
+ " is not among the states " + getEventTypeString(XMLEvent.CHARACTERS) + " , "
+ getEventTypeString(XMLEvent.COMMENT) + " , " + getEventTypeString(XMLEvent.CDATA)
+ " , " + getEventTypeString(XMLEvent.SPACE) + " valid for getTextCharacters() ");
}
}
EventFilterSupportTest.java 文件源码
项目:openjdk-jdk10
阅读 16
收藏 0
点赞 0
评论 0
private static void testNextEvent(int max)
throws IOException, XMLStreamException {
System.out.println("\nTest nextEvent (" + max + ")...");
XMLEventReader reader = createXmlReader(max);
XMLEvent event;
do {
event = reader.nextEvent();
System.out.println(event);
} while (event.getEventType() != XMLEvent.END_DOCUMENT);
System.out.println("nextEvent passed\n");
}
CimAnonymizer.java 文件源码
项目:powsybl-core
阅读 19
收藏 0
点赞 0
评论 0
@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);
}
AbstractParser.java 文件源码
项目:OperatieBRP
阅读 24
收藏 0
点赞 0
评论 0
private T verwerkChildElementenEnElementEinde(final String elementNaam, final ParserContext context) throws ParseException {
while (context.heeftVolgendeEvent()) {
final int event = context.volgendeEvent();
if (XMLEvent.START_ELEMENT == event) {
verwerkChildElement(context);
} else if (XMLEvent.END_ELEMENT == event) {
if (!elementNaam.equals(context.getEventNaam())) {
throw new ParseException(
String.format("Onverwacht element einde '%s'. Verwacht einde element is '%s'.", context.getEventNaam(), elementNaam));
}
return verwerkEindeElement(context);
}
}
throw new ParseException(String.format("Er is geen einde tag gevonden voor element '%s'", elementNaam));
}
DefaultAttributeTest.java 文件源码
项目:openjdk-jdk10
阅读 18
收藏 0
点赞 0
评论 0
@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());
}
}
XMLStreamReaderImpl.java 文件源码
项目:openjdk-jdk10
阅读 22
收藏 0
点赞 0
评论 0
/**
* Returns the value of the attribute at the index
*
* @param index the position of the attribute
* @return the attribute value
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
*/
public String getAttributeValue(int index) {
//State should be either START_ELEMENT or ATTRIBUTE
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getValue(index);
} else {
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeValue()");
}
}
Bug6481678.java 文件源码
项目:openjdk-jdk10
阅读 60
收藏 0
点赞 0
评论 0
public TypeFilter createFilter() {
TypeFilter f = new TypeFilter();
f.addType(XMLEvent.START_ELEMENT);
f.addType(XMLEvent.END_ELEMENT);
f.addType(XMLEvent.PROCESSING_INSTRUCTION);
f.addType(XMLEvent.CHARACTERS);
f.addType(XMLEvent.COMMENT);
f.addType(XMLEvent.SPACE);
f.addType(XMLEvent.START_DOCUMENT);
f.addType(XMLEvent.END_DOCUMENT);
return f;
}
TsoDisconnectedGenerator.java 文件源码
项目:powsybl-core
阅读 52
收藏 0
点赞 0
评论 0
public static TsoDisconnectedGenerator fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
String text = null;
Map<String, Float> disconnectedGenerators = new HashMap<>();
String id = null;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
switch (eventType) {
case XMLEvent.CHARACTERS:
text = xmlsr.getText();
break;
case XMLEvent.START_ELEMENT:
if ("generator".equals(xmlsr.getLocalName())) {
id = xmlsr.getAttributeValue(null, "id");
}
break;
case XMLEvent.END_ELEMENT:
switch (xmlsr.getLocalName()) {
case "generator":
if (id == null) {
throw new AssertionError();
}
float p = Float.parseFloat(text);
disconnectedGenerators.put(id, p);
id = null;
break;
case "index":
return new TsoDisconnectedGenerator(contingencyId, disconnectedGenerators);
default:
throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
}
break;
default:
break;
}
}
throw new AssertionError("Should not happen");
}
Bug6489890.java 文件源码
项目:openjdk-jdk10
阅读 19
收藏 0
点赞 0
评论 0
@Test
public void test1() {
try {
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(getClass().getResource("sgml.xml").toString(), getClass().getResourceAsStream("sgml.xml"));
XMLEventReader xer = xif.createXMLEventReader(xsr);
Assert.assertTrue(xer.nextEvent().getEventType() == XMLEvent.START_DOCUMENT);
xsr.close();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
XMLEventReaderImpl.java 文件源码
项目:OpenJSharp
阅读 29
收藏 0
点赞 0
评论 0
/** 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));
}