本文整理汇总了Java中javax.xml.stream.events.XMLEvent.START_ELEMENT属性的典型用法代码示例。如果您正苦于以下问题:Java XMLEvent.START_ELEMENT属性的具体用法?Java XMLEvent.START_ELEMENT怎么用?Java XMLEvent.START_ELEMENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.xml.stream.events.XMLEvent
的用法示例。
在下文中一共展示了XMLEvent.START_ELEMENT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isCim14
private static boolean isCim14(InputStream is) throws XMLStreamException {
// check the first root element is RDF and the second one belongs to CIM 14 namespace
XMLStreamReader xmlsr = XML_INPUT_FACTORY_SUPPLIER.get().createXMLStreamReader(is);
try {
int elemIndex = 0;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
if (eventType == XMLEvent.START_ELEMENT) {
String ns = xmlsr.getNamespaceURI();
if (elemIndex == 0) {
if (!RDF_NS.equals(ns)) {
return false;
}
} else if (elemIndex == 1) {
return CIM14_NS.equals(ns);
} else {
throw new AssertionError();
}
elemIndex++;
}
}
} finally {
xmlsr.close();
}
return false;
}
示例2: getAttributeValue
/**
* @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()") ;
}
}
示例3: isPtiCim14
private static boolean isPtiCim14(InputStream is) throws XMLStreamException {
// check the first root element is RDF and the second one belongs to CIM 14 namespace
XMLStreamReader xmlsr = XML_INPUT_FACTORY_SUPPLIER.get().createXMLStreamReader(is);
try {
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
if (eventType == XMLEvent.START_ELEMENT) {
return PTI_CIM14_NS.equals(xmlsr.getNamespaceURI("pti"));
}
}
} finally {
xmlsr.close();
}
return false;
}
示例4: getNamespaceURI
/** Returns the uri for the namespace declared at the
* index.
*
* @param index the position of the namespace declaration
* @return returns the namespace uri
* @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
*/
public String getNamespaceURI(int index) {
if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT || fEventType == XMLEvent.NAMESPACE){
//namespaceContext is dynamic object.
return fScanner.getNamespaceContext().getURI(fScanner.getNamespaceContext().getDeclaredPrefixAt(index));
}
else{
throw new IllegalStateException("Current state " + getEventTypeString(fEventType)
+ " is not among the states " + getEventTypeString(XMLEvent.START_ELEMENT)
+ ", " + getEventTypeString(XMLEvent.END_ELEMENT) + ", "
+ getEventTypeString(XMLEvent.NAMESPACE)
+ " valid for getNamespaceURI()." );
}
}
示例5: getEventTypeString
final static String getEventTypeString(int eventType) {
switch (eventType) {
case XMLEvent.START_ELEMENT:
return "START_ELEMENT";
case XMLEvent.END_ELEMENT:
return "END_ELEMENT";
case XMLEvent.PROCESSING_INSTRUCTION:
return "PROCESSING_INSTRUCTION";
case XMLEvent.CHARACTERS:
return "CHARACTERS";
case XMLEvent.COMMENT:
return "COMMENT";
case XMLEvent.START_DOCUMENT:
return "START_DOCUMENT";
case XMLEvent.END_DOCUMENT:
return "END_DOCUMENT";
case XMLEvent.ENTITY_REFERENCE:
return "ENTITY_REFERENCE";
case XMLEvent.ATTRIBUTE:
return "ATTRIBUTE";
case XMLEvent.DTD:
return "DTD";
case XMLEvent.CDATA:
return "CDATA";
case XMLEvent.SPACE:
return "SPACE";
}
return "UNKNOWN_EVENT_TYPE, " + String.valueOf(eventType);
}
示例6: getAttributeCount
/**
* Returns the count of attributes on this START_ELEMENT, this method is
* only valid on a START_ELEMENT or ATTRIBUTE. This count excludes namespace
* definitions. Attribute indices are zero-based.
*
* @return returns the number of attributes
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
*/
public int getAttributeCount() {
//xxx: recognize SAX properties namespace, namespace-prefix to get XML Namespace declarations
//does length includes namespace declarations ?
//State should be either START_ELEMENT or ATTRIBUTE
if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getLength();
} else {
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeCount()");
}
}
示例7: readNode
private void readNode(XMLStreamReader xmlReader) throws XMLStreamException {
int attrId = 0;
Vertex v = null;
for (int i = 0; i < xmlReader.getAttributeCount(); ++i) {
String attr = xmlReader.getAttributeLocalName(i);
if (attr.equalsIgnoreCase(NODE_ID)) {
attrId = Integer.parseInt(xmlReader.getAttributeValue(i));
}
}
v = new Vertex(attrId);
boolean elemEnd = false;
while (xmlReader.hasNext() && !elemEnd) {
int event = xmlReader.next();
if (event == XMLEvent.START_ELEMENT) {
if (xmlReader.getLocalName().equalsIgnoreCase(DATA)) {
readNodeData(xmlReader, v);
}
} else if (event == XMLEvent.END_ELEMENT) {
if (xmlReader.getLocalName().equalsIgnoreCase(NODE)) {
elemEnd = true;
}
}
}
network.addVertex(v);
}
示例8: seek
/**
* Seek to an identifier in this stream.
*
* @param id The identifier to find.
* @return This {@code FreeColXMLReader} positioned such that the
* required identifier is current, or null on error or if not found.
* @exception XMLStreamException if a problem was encountered
* during parsing.
*/
public FreeColXMLReader seek(String id) throws XMLStreamException {
nextTag();
for (int type = getEventType(); type != XMLEvent.END_DOCUMENT;
type = getEventType()) {
if (type == XMLEvent.START_ELEMENT
&& id.equals(readId())) return this;
nextTag();
}
return null;
}
示例9: getValue
/**
* @return
*/
public String getValue() {
if (fEventType == XMLEvent.PROCESSING_INSTRUCTION) {
return fScanner.getPIData().toString();
} else if (fEventType == XMLEvent.COMMENT) {
return fScanner.getComment();
} else if (fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT) {
return fScanner.getElementQName().localpart;
} else if (fEventType == XMLEvent.CHARACTERS) {
return fScanner.getCharacterData().toString();
}
return null;
}
示例10: getAttributePrefix
/** Returns the prefix of this attribute at the
* provided index
* @param index the position of the attribute
* @return the prefix of the attribute
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
*/
public String getAttributePrefix(int index) {
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getPrefix(index);
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributePrefix()") ;
}
}
示例11: nextTag
/**
*
* @throws XMLStreamException
* @return
*/
public int nextTag() throws XMLStreamException {
if (fStreamAdvancedByHasNext && fEventAccepted &&
(fCurrentEvent == XMLEvent.START_ELEMENT || fCurrentEvent == XMLEvent.START_ELEMENT)) {
fStreamAdvancedByHasNext = false;
return fCurrentEvent;
}
int event = findNextTag();
if (event != -1) {
return event;
}
throw new IllegalStateException("The stream reader has reached the end of the document, or there are no more "+
" items to return");
}
示例12: getAttributeCount
/** Returns the count of attributes on this START_ELEMENT,
* this method is only valid on a START_ELEMENT or ATTRIBUTE. This
* count excludes namespace definitions. Attribute indices are
* zero-based.
* @return returns the number of attributes
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
*/
public int getAttributeCount() {
//xxx: recognize SAX properties namespace, namespace-prefix to get XML Namespace declarations
//does length includes namespace declarations ?
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
return fScanner.getAttributeIterator().getLength() ;
} else{
throw new java.lang.IllegalStateException( "Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeCount()") ;
}
}
示例13: getPrefix
/**
* @return the prefix of the current event, or null if the event does
* not have a prefix. For START_ELEMENT and END_ELEMENT, return
* XMLConstants.DEFAULT_NS_PREFIX when no prefix is available.
*/
public String getPrefix() {
if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT){
String prefix = fScanner.getElementQName().prefix;
return prefix == null ? XMLConstants.DEFAULT_NS_PREFIX : prefix;
}
return null ;
}
示例14: getValue
/**
* @return
*/
public String getValue() {
if(fEventType == XMLEvent.PROCESSING_INSTRUCTION){
return fScanner.getPIData().toString();
} else if(fEventType == XMLEvent.COMMENT){
return fScanner.getComment();
} else if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT){
return fScanner.getElementQName().localpart ;
} else if(fEventType == XMLEvent.CHARACTERS){
return fScanner.getCharacterData().toString();
}
return null;
}
示例15: getAttributeQName
/** Returns the qname of the attribute at the provided index
*
* @param index the position of the attribute
* @return the QName of the attribute
* @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
*/
public javax.xml.namespace.QName getAttributeQName(int index) {
//State should be either START_ELEMENT or ATTRIBUTE
if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
// create new object at runtime..
String localName = fScanner.getAttributeIterator().getLocalName(index) ;
String uri = fScanner.getAttributeIterator().getURI(index) ;
return new javax.xml.namespace.QName(uri, localName) ;
} else{
throw new java.lang.IllegalStateException("Current state is not among the states "
+ getEventTypeString(XMLEvent.START_ELEMENT) + " , "
+ getEventTypeString(XMLEvent.ATTRIBUTE)
+ "valid for getAttributeQName()") ;
}
}