本文整理汇总了Java中javax.xml.stream.events.StartElement.getName方法的典型用法代码示例。如果您正苦于以下问题:Java StartElement.getName方法的具体用法?Java StartElement.getName怎么用?Java StartElement.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.events.StartElement
的用法示例。
在下文中一共展示了StartElement.getName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleStartElement
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private void handleStartElement(StartElement event) throws SAXException {
// start namespace bindings
for (Iterator i = event.getNamespaces(); i.hasNext();) {
Namespace ns = (Namespace)i.next();
visitor.startPrefixMapping(
fixNull(ns.getPrefix()),
fixNull(ns.getNamespaceURI()));
}
// fire startElement
QName qName = event.getName();
tagName.uri = fixNull(qName.getNamespaceURI());
String localName = qName.getLocalPart();
tagName.uri = fixNull(qName.getNamespaceURI());
tagName.local = localName;
tagName.atts = getAttributes(event);
visitor.startElement(tagName);
seenText = false;
}
示例2: 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));
}
}
}
示例3: writeStartElementEvent
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private static void writeStartElementEvent(XMLEvent event, XMLStreamWriter writer)
throws XMLStreamException {
StartElement start = event.asStartElement();
QName name = start.getName();
String nsURI = name.getNamespaceURI();
String localName = name.getLocalPart();
String prefix = name.getPrefix();
if (prefix != null) {
writer.writeStartElement(prefix, localName, nsURI);
} else if (nsURI != null) {
writer.writeStartElement(localName, nsURI);
} else {
writer.writeStartElement(localName);
}
Iterator<XMLEvent> it = CastUtils.cast(start.getNamespaces());
while (it != null && it.hasNext()) {
writeEvent(it.next(), writer);
}
it = CastUtils.cast(start.getAttributes());
while (it != null && it.hasNext()) {
writeAttributeEvent(it.next(), writer);
}
}
示例4: processStartTag
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private void processStartTag(final StartElement element, final StartElement parent,
final XMLEventReader reader, final Map<URI, Policy> map)
throws PolicyException {
try {
final QName name = element.getName();
if (parent == null) {
if (!name.equals(POLICIES)) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<Policies>", name, element.getLocation())));
}
} else {
final QName parentName = parent.getName();
if (parentName.equals(POLICIES)) {
if (!name.equals(POLICY_ATTACHMENT)) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<PolicyAttachment>", name, element.getLocation())));
}
} else if (parentName.equals(POLICY_ATTACHMENT)) {
if (name.equals(POLICY)) {
readPolicy(reader);
return;
} else if (!name.equals(APPLIES_TO)) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<AppliesTo> or <Policy>", name, element.getLocation())));
}
} else if (parentName.equals(APPLIES_TO)) {
if (!name.equals(URI)) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<URI>", name, element.getLocation())));
}
} else {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0090_UNEXPECTED_ELEMENT(name, element.getLocation())));
}
}
reader.nextEvent();
this.unmarshal(reader, element);
} catch (XMLStreamException e) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(element.getLocation()), e));
}
}
示例5: 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);
}
示例6: StartElementEvent
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
public StartElementEvent(StartElement startelement) {
this(startelement.getName());
addAttributes(startelement.getAttributes());
addNamespaces(startelement.getNamespaces());
}
示例7: StartElementEvent
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
public StartElementEvent(StartElement startelement) {
this(startelement.getName());
addAttributes(startelement.getAttributes());
addNamespaceAttributes(startelement.getNamespaces());
}
示例8: addNewChildNode
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private ModelNode addNewChildNode(final NamespaceVersion nsVersion, final ModelNode parentNode, final StartElement childElement) throws PolicyException {
ModelNode childNode;
final QName childElementName = childElement.getName();
if (parentNode.getType() == ModelNode.Type.ASSERTION_PARAMETER_NODE) {
childNode = parentNode.createChildAssertionParameterNode();
} else {
XmlToken token = NamespaceVersion.resolveAsToken(childElementName);
switch (token) {
case Policy:
childNode = parentNode.createChildPolicyNode();
break;
case All:
childNode = parentNode.createChildAllNode();
break;
case ExactlyOne:
childNode = parentNode.createChildExactlyOneNode();
break;
case PolicyReference:
final Attribute uri = getAttributeByName(childElement, nsVersion.asQName(XmlToken.Uri));
if (uri == null) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0040_POLICY_REFERENCE_URI_ATTR_NOT_FOUND()));
} else {
try {
final URI reference = new URI(uri.getValue());
final Attribute digest = getAttributeByName(childElement, nsVersion.asQName(XmlToken.Digest));
PolicyReferenceData refData;
if (digest == null) {
refData = new PolicyReferenceData(reference);
} else {
final Attribute digestAlgorithm = getAttributeByName(childElement, nsVersion.asQName(XmlToken.DigestAlgorithm));
URI algorithmRef = null;
if (digestAlgorithm != null) {
algorithmRef = new URI(digestAlgorithm.getValue());
}
refData = new PolicyReferenceData(reference, digest.getValue(), algorithmRef);
}
childNode = parentNode.createChildPolicyReferenceNode(refData);
} catch (URISyntaxException e) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0012_UNABLE_TO_UNMARSHALL_POLICY_MALFORMED_URI(), e));
}
}
break;
default:
if (parentNode.isDomainSpecific()) {
childNode = parentNode.createChildAssertionParameterNode();
} else {
childNode = parentNode.createChildAssertionNode();
}
}
}
return childNode;
}
示例9: add
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
public void add(XMLEvent event)
throws XMLStreamException
{
QName name;
String uri;
switch (event.getEventType())
{
case XMLStreamConstants.START_ELEMENT:
StartElement startElement = event.asStartElement();
name = startElement.getName();
uri = name.getNamespaceURI();
if (uri != null && !"".equals(uri))
writer.writeStartElement(name.getPrefix(), name.getLocalPart(), uri);
else
writer.writeStartElement(name.getLocalPart());
break;
case XMLStreamConstants.END_ELEMENT:
writer.writeEndElement();
break;
case XMLStreamConstants.ATTRIBUTE:
Attribute attribute = (Attribute) event;
name = attribute.getName();
uri = name.getNamespaceURI();
if (uri != null && !"".equals(uri))
writer.writeAttribute(name.getPrefix(), uri, name.getLocalPart(),
attribute.getValue());
else
writer.writeAttribute(name.getLocalPart(), attribute.getValue());
break;
case XMLStreamConstants.NAMESPACE:
Namespace namespace = (Namespace) event;
uri = namespace.getNamespaceURI();
writer.writeNamespace(namespace.getPrefix(), uri);
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
ProcessingInstruction pi = (ProcessingInstruction) event;
String data = pi.getData();
if (data == null)
writer.writeProcessingInstruction(pi.getTarget());
else
writer.writeProcessingInstruction(pi.getTarget(), data);
break;
case XMLStreamConstants.COMMENT:
Comment comment = (Comment) event;
writer.writeComment(comment.getText());
break;
case XMLStreamConstants.START_DOCUMENT:
StartDocument startDocument = (StartDocument) event;
writer.writeStartDocument(startDocument.getVersion());
break;
case XMLStreamConstants.END_DOCUMENT:
writer.writeEndDocument();
break;
case XMLStreamConstants.DTD:
DTD dtd = (DTD) event;
writer.writeDTD(dtd.getDocumentTypeDeclaration());
break;
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.SPACE:
Characters characters = event.asCharacters();
writer.writeCharacters(characters.getData());
break;
case XMLStreamConstants.CDATA:
Characters cdata = event.asCharacters();
writer.writeCData(cdata.getData());
break;
}
}
示例10: add
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
public void add(XMLEvent event) throws XMLStreamException {
if (event.isStartDocument()) {
streamWriter.writeStartDocument();
} else if (event.isStartElement()) {
StartElement element = event.asStartElement();
QName elQName = element.getName();
if (elQName.getPrefix().length() > 0
&& elQName.getNamespaceURI().length() > 0)
streamWriter.writeStartElement(elQName.getPrefix(), elQName
.getLocalPart(), elQName.getNamespaceURI());
else if (elQName.getNamespaceURI().length() > 0)
streamWriter.writeStartElement(elQName.getNamespaceURI(),
elQName.getLocalPart());
else
streamWriter.writeStartElement(elQName.getLocalPart());
// Add element namespaces
Iterator namespaces = element.getNamespaces();
while (namespaces.hasNext()) {
Namespace ns = (Namespace) namespaces.next();
String prefix = ns.getPrefix();
String nsURI = ns.getNamespaceURI();
streamWriter.writeNamespace(prefix, nsURI);
}
// Add element attributes
Iterator attris = element.getAttributes();
while (attris.hasNext()) {
Attribute attr = (Attribute) attris.next();
QName atQName = attr.getName();
String value = attr.getValue();
if (atQName.getPrefix().length() > 0
&& atQName.getNamespaceURI().length() > 0)
streamWriter.writeAttribute(atQName.getPrefix(), atQName
.getNamespaceURI(), atQName.getLocalPart(), value);
else if (atQName.getNamespaceURI().length() > 0)
streamWriter.writeAttribute(atQName.getNamespaceURI(),
atQName.getLocalPart(), value);
else
streamWriter.writeAttribute(atQName.getLocalPart(), value);
}
} else if (event.isCharacters()) {
Characters chars = event.asCharacters();
streamWriter.writeCharacters(chars.getData());
} else if (event.isEndElement()) {
streamWriter.writeEndElement();
} else if (event.isEndDocument()) {
streamWriter.writeEndDocument();
} else {
throw new XMLStreamException("Unsupported event type: " + event);
}
}
示例11: readXml
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
XmlElement readXml() {
XmlElement root = null;
try {
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(reader);
while (xmlEventReader.hasNext()) {
XMLEvent xmlEvent = xmlEventReader.nextEvent();
/*if (xmlEvent.isStartDocument()){
StartDocument startDocument = (StartDocument) xmlEvent;
} else */
XmlElement parent = !elementStack.isEmpty() ? elementStack.peek() : null;
if (xmlEvent.isStartElement()){
StartElement startElement = (StartElement)xmlEvent;
// create the xml element
XmlElement xmlElement = new XmlElement();
if (parent==null) {
root = xmlElement;
} else {
// establish parent-child relation
parent.addElement(xmlElement);
xmlElement.parent = parent;
}
// initialize namespaces
Iterator namespaces = startElement.getNamespaces();
while (namespaces.hasNext()) {
Namespace namespace = (Namespace) namespaces.next();
xmlElement.addNamespace(namespace.getNamespaceURI(), namespace.getPrefix());
}
// set the name (depends on the namespaces being initialized)
QName qname = startElement.getName();
xmlElement.setName(qname.getNamespaceURI(), qname.getLocalPart());
// set the attributes (depends on the namespaces being initialized)
Iterator attributes = startElement.getAttributes();
while (attributes.hasNext()) {
Attribute attribute = (Attribute) attributes.next();
QName attributeQname = attribute.getName();
xmlElement.addAttribute(attributeQname.getNamespaceURI(), attributeQname.getLocalPart(), attribute.getValue());
}
elementStack.push(xmlElement);
} else if (xmlEvent.isEndElement()){
elementStack.pop();
} else if (xmlEvent.isCharacters()){
parent.addText(xmlEvent.asCharacters().getData());
}
}
} catch (XMLStreamException e) {
throw new XmlParsingError(e);
}
return root;
}