本文整理汇总了Java中javax.xml.stream.XMLStreamConstants.ATTRIBUTE属性的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamConstants.ATTRIBUTE属性的具体用法?Java XMLStreamConstants.ATTRIBUTE怎么用?Java XMLStreamConstants.ATTRIBUTE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.xml.stream.XMLStreamConstants
的用法示例。
在下文中一共展示了XMLStreamConstants.ATTRIBUTE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEventName
/**
* Get the human readable event name for the numeric event id
*/
public static String getEventName(int eventId) {
switch (eventId) {
case XMLStreamConstants.START_ELEMENT:
return "StartElementEvent";
case XMLStreamConstants.END_ELEMENT:
return "EndElementEvent";
case XMLStreamConstants.PROCESSING_INSTRUCTION:
return "ProcessingInstructionEvent";
case XMLStreamConstants.CHARACTERS:
return "CharacterEvent";
case XMLStreamConstants.COMMENT:
return "CommentEvent";
case XMLStreamConstants.START_DOCUMENT:
return "StartDocumentEvent";
case XMLStreamConstants.END_DOCUMENT:
return "EndDocumentEvent";
case XMLStreamConstants.ENTITY_REFERENCE:
return "EntityReferenceEvent";
case XMLStreamConstants.ATTRIBUTE:
return "AttributeBase";
case XMLStreamConstants.DTD:
return "DTDEvent";
case XMLStreamConstants.CDATA:
return "CDATA";
}
return "UNKNOWN_EVENT_TYPE";
}
示例2: getAttributes
/**
* Get the attributes associated with the given START_ELEMENT or ATTRIBUTE
* StAXevent.
*
* @return the StAX attributes converted to an org.xml.sax.Attributes
*/
private Attributes getAttributes() {
AttributesImpl attrs = new AttributesImpl();
int eventType = staxStreamReader.getEventType();
if (eventType != XMLStreamConstants.ATTRIBUTE
&& eventType != XMLStreamConstants.START_ELEMENT) {
throw new InternalError(
"getAttributes() attempting to process: " + eventType);
}
// in SAX, namespace declarations are not part of attributes by default.
// (there's a property to control that, but as far as we are concerned
// we don't use it.) So don't add xmlns:* to attributes.
// gather non-namespace attrs
for (int i = 0; i < staxStreamReader.getAttributeCount(); i++) {
String uri = staxStreamReader.getAttributeNamespace(i);
if(uri==null) uri="";
String localName = staxStreamReader.getAttributeLocalName(i);
String prefix = staxStreamReader.getAttributePrefix(i);
String qName;
if(prefix==null || prefix.length()==0)
qName = localName;
else
qName = prefix + ':' + localName;
String type = staxStreamReader.getAttributeType(i);
String value = staxStreamReader.getAttributeValue(i);
attrs.addAttribute(uri, localName, qName, type, value);
}
return attrs;
}
示例3: getEventTypeString
public final static String getEventTypeString(int eventType) {
switch (eventType){
case XMLStreamConstants.START_ELEMENT:
return "START_ELEMENT";
case XMLStreamConstants.END_ELEMENT:
return "END_ELEMENT";
case XMLStreamConstants.PROCESSING_INSTRUCTION:
return "PROCESSING_INSTRUCTION";
case XMLStreamConstants.CHARACTERS:
return "CHARACTERS";
case XMLStreamConstants.COMMENT:
return "COMMENT";
case XMLStreamConstants.START_DOCUMENT:
return "START_DOCUMENT";
case XMLStreamConstants.END_DOCUMENT:
return "END_DOCUMENT";
case XMLStreamConstants.ENTITY_REFERENCE:
return "ENTITY_REFERENCE";
case XMLStreamConstants.ATTRIBUTE:
return "ATTRIBUTE";
case XMLStreamConstants.DTD:
return "DTD";
case XMLStreamConstants.CDATA:
return "CDATA";
}
return "UNKNOWN_EVENT_TYPE";
}
示例4: correctPrefix
/**
*
* @param uri
* @return
*/
private void correctPrefix(QName attr, int type) {
String tmpPrefix;
String prefix;
String uri;
prefix = attr.prefix;
uri = attr.uri;
boolean isSpecialCaseURI = false;
if (prefix == null || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
if (uri == null) {
return;
}
if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix) && uri.equals(XMLConstants.DEFAULT_NS_PREFIX))
return;
uri = fSymbolTable.addSymbol(uri);
QName decl;
for (int i = 0; i < fNamespaceDecls.size(); i++) {
decl = fNamespaceDecls.get(i);
if ((decl != null) && (decl.uri.equals(attr.uri))) {
attr.prefix = decl.prefix;
return;
}
}
tmpPrefix = fNamespaceContext.getPrefix(uri);
if (XMLConstants.DEFAULT_NS_PREFIX.equals(tmpPrefix)) {
if (type == XMLStreamConstants.START_ELEMENT) {
return;
}
else if (type == XMLStreamConstants.ATTRIBUTE) {
//the uri happens to be the same as that of the default namespace
tmpPrefix = getAttrPrefix(uri);
isSpecialCaseURI = true;
}
}
if (tmpPrefix == null) {
StringBuilder genPrefix = new StringBuilder("zdef");
for (int i = 0; i < 1; i++) {
genPrefix.append(fPrefixGen.nextInt());
}
prefix = genPrefix.toString();
prefix = fSymbolTable.addSymbol(prefix);
} else {
prefix = fSymbolTable.addSymbol(tmpPrefix);
}
if (tmpPrefix == null) {
if (isSpecialCaseURI) {
addAttrNamespace(prefix, uri);
} else {
QName qname = new QName();
qname.setValues(prefix, XMLConstants.XMLNS_ATTRIBUTE, null, uri);
fNamespaceDecls.add(qname);
fInternalNamespaceContext.declarePrefix(fSymbolTable.addSymbol(
prefix), uri);
}
}
}
attr.prefix = prefix;
}