本文整理汇总了Java中javax.xml.stream.events.StartElement.getAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java StartElement.getAttributes方法的具体用法?Java StartElement.getAttributes怎么用?Java StartElement.getAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.events.StartElement
的用法示例。
在下文中一共展示了StartElement.getAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: anonymizeStartElement
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private XMLEvent anonymizeStartElement(StartElement startElement) {
if (startElement.getName().getLocalPart().equals("IdentifiedObject.name")) {
identifiedObjectName = true;
} else if (startElement.getName().getLocalPart().equals("IdentifiedObject.description")) {
identifiedObjectDescription = true;
} else {
Iterator it = startElement.getAttributes();
if (it.hasNext()) {
List<Attribute> newAttributes = new ArrayList<>();
while (it.hasNext()) {
Attribute attribute = (Attribute) it.next();
Attribute newAttribute = anonymizeAttribute(attribute);
newAttributes.add(newAttribute != null ? newAttribute : attribute);
}
return xmlStaxContext.eventFactory.createStartElement(startElement.getName(),
newAttributes.iterator(),
startElement.getNamespaces());
}
}
return null;
}
示例2: addRdfIdValues
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private void addRdfIdValues(InputStream is, Set<String> rdfIdValues) throws XMLStreamException {
// memoize RDF ID values of the document
XMLEventReader eventReader = xmlStaxContext.inputFactory.createXMLEventReader(is);
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
if (event.isStartElement()) {
StartElement startElement = event.asStartElement();
Iterator it = startElement.getAttributes();
while (it.hasNext()) {
Attribute attribute = (Attribute) it.next();
QName name = attribute.getName();
if (RDF_ID.equals(name)) {
rdfIdValues.add(attribute.getValue());
}
}
}
}
eventReader.close();
}
示例3: getAttributeByName
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private Attribute getAttributeByName(final StartElement element,
final QName attributeName) {
// call standard API method to retrieve the attribute by name
Attribute attribute = element.getAttributeByName(attributeName);
// try to find the attribute without a prefix.
if (attribute == null) {
final String localAttributeName = attributeName.getLocalPart();
final Iterator iterator = element.getAttributes();
while (iterator.hasNext()) {
final Attribute nextAttribute = (Attribute) iterator.next();
final QName aName = nextAttribute.getName();
final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
if (attributeFoundByWorkaround) {
attribute = nextAttribute;
break;
}
}
}
return attribute;
}
示例4: parse
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
public TubelineFeature parse(XMLEventReader reader) throws WebServiceException {
try {
final StartElement element = reader.nextEvent().asStartElement();
boolean attributeEnabled = true;
final Iterator iterator = element.getAttributes();
while (iterator.hasNext()) {
final Attribute nextAttribute = (Attribute) iterator.next();
final QName attributeName = nextAttribute.getName();
if (ENABLED_ATTRIBUTE_NAME.equals(attributeName)) {
attributeEnabled = ParserUtil.parseBooleanValue(nextAttribute.getValue());
} else if (NAME_ATTRIBUTE_NAME.equals(attributeName)) {
// TODO use name attribute
} else {
// TODO logging message
throw LOGGER.logSevereException(new WebServiceException("Unexpected attribute"));
}
}
return parseFactories(attributeEnabled, element, reader);
} catch (XMLStreamException e) {
throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
}
}
示例5: handleStartElement
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private void handleStartElement(StartElement startElement) throws SAXException {
if (getContentHandler() != null) {
QName qName = startElement.getName();
if (hasNamespacesFeature()) {
for (Iterator i = startElement.getNamespaces(); i.hasNext();) {
Namespace namespace = (Namespace) i.next();
startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI());
}
for (Iterator i = startElement.getAttributes(); i.hasNext();){
Attribute attribute = (Attribute) i.next();
QName attributeName = attribute.getName();
startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI());
}
getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName),
getAttributes(startElement));
}
else {
getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement));
}
}
}
示例6: removeNonSvgAttributes
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
/**
* Modifies a {@link StartElement}, removing attributes that do not have a {@link QName#getNamespaceURI()} that
* equals {@link SvgDocument#NAMESPACE_URI}.
* @param element The {@link StartElement} to remove attributes from.
* @return The modified {@link StartElement}.
*/
@SuppressWarnings("unchecked")
private static XMLEvent removeNonSvgAttributes(StartElement element) {
Iterator<Attribute> original = element.getAttributes();
Collection<Attribute> modified = new ArrayList<>();
while (original.hasNext()) {
Attribute attribute = original.next();
QName qName = attribute.getName();
String namespaceUri = qName.getNamespaceURI();
if (namespaceUri.isEmpty() || namespaceUri.equals(SvgDocument.NAMESPACE_URI)) {
modified.add(attribute);
}
}
return events.createStartElement(element.getName(), modified.iterator(), element.getNamespaces());
}
示例7: processModuleTag
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
/**
* Parses single "module" tag.
*
* @param reader
* StAX parser interface.
* @param startElement
* start element of the tag.
* @param parent
* parent module instance.
* @throws XMLStreamException
* on internal StAX failure.
*/
private static void processModuleTag(XMLEventReader reader, StartElement startElement,
ConfigurationModule parent) throws XMLStreamException {
String childModuleName = null;
final Iterator<Attribute> attributes = startElement
.getAttributes();
while (attributes.hasNext()) {
final Attribute attribute = attributes.next();
if (attribute.getName().toString()
.equals(NAME_ATTR)) {
childModuleName = attribute.getValue();
}
}
final ConfigurationModule childModule =
new ConfigurationModule(childModuleName);
parseModule(reader, childModule);
parent.addChild(childModule);
}
示例8: processPropertyTag
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
/**
* Parses single "property" tag.
*
* @param startElement
* start element of the tag.
* @param parent
* parent module instance.
*/
private static void processPropertyTag(StartElement startElement,
ConfigurationModule parent) {
String propertyName = null;
String propertyValue = null;
final Iterator<Attribute> attributes = startElement
.getAttributes();
while (attributes.hasNext()) {
final Attribute attribute = attributes.next();
final String attributeName = attribute.getName().toString();
if (attributeName.equals(NAME_ATTR)) {
propertyName = attribute.getValue();
}
else if (attributeName.equals(VALUE_ATTR)) {
propertyValue = attribute.getValue();
}
}
parent.addProperty(propertyName, propertyValue);
}
示例9: processMessageTag
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
/**
* Parses single "message" tag.
*
* @param startElement
* start element of the tag.
* @param parent
* parent module instance.
*/
private static void processMessageTag(StartElement startElement,
ConfigurationModule parent) {
String propertyName = null;
String propertyValue = null;
final Iterator<Attribute> attributes = startElement
.getAttributes();
while (attributes.hasNext()) {
final Attribute attribute = attributes.next();
final String attributeName = attribute.getName().toString();
if (attributeName.equals(KEY_ATTR)) {
propertyName = attribute.getValue();
}
else if (attributeName.equals(VALUE_ATTR)) {
propertyValue = attribute.getValue();
}
}
parent.addProperty(propertyName, propertyValue);
}
示例10: checkStartElement
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
@Override
public boolean checkStartElement(StartElement startElement) {
if (wildcardElement || isQualifiedMatch(startElement.getName())) {
numElementsSeen++;
if (byIndex) {
return numElementsSeen == index;
} else if (byAttribute) {
final Iterator<?> attrIter = startElement.getAttributes();
while (attrIter.hasNext()) {
Attribute attrib = (Attribute) attrIter.next();
if (attrib.getName().getLocalPart().equals(attributeName) &&
(Constants.WILDCARD.equals(attributeValue)) || attrib.getValue().equals(attributeValue)) {
return true;
}
}
return false;
} else {
return true;
}
} else {
return false;
}
}
示例11: parseAssertionData
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private void parseAssertionData(NamespaceVersion nsVersion, String value, ModelNode childNode, final StartElement childElement) throws IllegalArgumentException, PolicyException {
// finish assertion node processing: create and set assertion data...
final Map<QName, String> attributeMap = new HashMap<QName, String>();
boolean optional = false;
boolean ignorable = false;
final Iterator iterator = childElement.getAttributes();
while (iterator.hasNext()) {
final Attribute nextAttribute = (Attribute) iterator.next();
final QName name = nextAttribute.getName();
if (attributeMap.containsKey(name)) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0059_MULTIPLE_ATTRS_WITH_SAME_NAME_DETECTED_FOR_ASSERTION(nextAttribute.getName(), childElement.getName())));
} else {
if (nsVersion.asQName(XmlToken.Optional).equals(name)) {
optional = parseBooleanValue(nextAttribute.getValue());
} else if (nsVersion.asQName(XmlToken.Ignorable).equals(name)) {
ignorable = parseBooleanValue(nextAttribute.getValue());
} else {
attributeMap.put(name, nextAttribute.getValue());
}
}
}
final AssertionData nodeData = new AssertionData(childElement.getName(), value, attributeMap, childNode.getType(), optional, ignorable);
// check visibility value syntax if present...
if (nodeData.containsAttribute(PolicyConstants.VISIBILITY_ATTRIBUTE)) {
final String visibilityValue = nodeData.getAttributeValue(PolicyConstants.VISIBILITY_ATTRIBUTE);
if (!PolicyConstants.VISIBILITY_VALUE_PRIVATE.equals(visibilityValue)) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0004_UNEXPECTED_VISIBILITY_ATTR_VALUE(visibilityValue)));
}
}
childNode.setOrReplaceNodeData(nodeData);
}
示例12: getAttributes
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
/**
* Get the attributes associated with the given START_ELEMENT StAXevent.
*
* @return the StAX attributes converted to an org.xml.sax.Attributes
*/
private Attributes getAttributes(StartElement event) {
attrs.clear();
// 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 (Iterator i = event.getAttributes(); i.hasNext();) {
Attribute staxAttr = (Attribute)i.next();
QName name = staxAttr.getName();
String uri = fixNull(name.getNamespaceURI());
String localName = name.getLocalPart();
String prefix = name.getPrefix();
String qName;
if (prefix == null || prefix.length() == 0)
qName = localName;
else
qName = prefix + ':' + localName;
String type = staxAttr.getDTDType();
String value = staxAttr.getValue();
attrs.addAttribute(uri, localName, qName, type, value);
}
return attrs;
}
示例13: getAttributes
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
/**
* Get the attributes associated with the given START_ELEMENT StAXevent.
*
* @return the StAX attributes converted to an org.xml.sax.Attributes
*/
private Attributes getAttributes(StartElement event) {
AttributesImpl attrs = new AttributesImpl();
if ( !event.isStartElement() ) {
throw new InternalError(
"getAttributes() attempting to process: " + event);
}
// 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 (Iterator i = event.getAttributes(); i.hasNext();) {
Attribute staxAttr = (javax.xml.stream.events.Attribute)i.next();
String uri = staxAttr.getName().getNamespaceURI();
if (uri == null) {
uri = "";
}
String localName = staxAttr.getName().getLocalPart();
String prefix = staxAttr.getName().getPrefix();
String qName;
if (prefix == null || prefix.length() == 0) {
qName = localName;
} else {
qName = prefix + ':' + localName;
}
String type = staxAttr.getDTDType();
String value = staxAttr.getValue();
attrs.addAttribute(uri, localName, qName, type, value);
}
return attrs;
}
示例14: fillXMLAttributes
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private void fillXMLAttributes(StartElement event) {
fAttributes.removeAllAttributes();
final Iterator attrs = event.getAttributes();
while (attrs.hasNext()) {
Attribute attr = (Attribute) attrs.next();
fillQName(fAttributeQName, attr.getName());
String type = attr.getDTDType();
int idx = fAttributes.getLength();
fAttributes.addAttributeNS(fAttributeQName,
(type != null) ? type : XMLSymbols.fCDATASymbol, attr.getValue());
fAttributes.setSpecified(idx, attr.isSpecified());
}
}
示例15: testEventReader
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
@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());
}
}