本文整理了Java中javax.xml.stream.events.Namespace
类的一些代码示例,展示了Namespace
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Namespace
类的具体详情如下:
包路径:javax.xml.stream.events.Namespace
类名称:Namespace
[英]An interface that contains information about a namespace. Namespaces are accessed from a StartElement.
[中]包含有关命名空间的信息的接口。名称空间可以从StartElement访问。
代码示例来源:origin: spring-projects/spring-framework
private Attributes getAttributes(StartElement event) {
AttributesImpl attributes = new AttributesImpl();
for (Iterator i = event.getAttributes(); i.hasNext();) {
Attribute attribute = (Attribute) i.next();
QName qName = attribute.getName();
String namespace = qName.getNamespaceURI();
if (namespace == null || !hasNamespacesFeature()) {
namespace = "";
String type = attribute.getDTDType();
if (type == null) {
type = "CDATA";
attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue());
for (Iterator i = event.getNamespaces(); i.hasNext();) {
Namespace namespace = (Namespace) i.next();
String prefix = namespace.getPrefix();
String namespaceUri = namespace.getNamespaceURI();
String qName;
if (StringUtils.hasLength(prefix)) {
代码示例来源:origin: plutext/docx4j
/**
* Adds a namespace declaration attribute to the given element.
*/
public static void addNamespaceDeclaration(Element element, Namespace namespace) {
addNamespaceDeclaration(element, namespace.getPrefix(), namespace.getNamespaceURI());
}
代码示例来源:origin: pentaho/pentaho-kettle
@SuppressWarnings( "unchecked" )
private Object[] parseNamespaces( Object[] outputRowData, XMLEvent e ) throws KettleValueException,
KettleStepException {
Iterator<Namespace> iter = e.asStartElement().getNamespaces();
if ( iter.hasNext() ) {
Object[] outputRowDataNamespace = data.outputRowMeta.cloneRow( outputRowData );
putRowOut( outputRowDataNamespace ); // first put the element name info out
// change data_type to ATTRIBUTE
if ( data.pos_xml_data_type_numeric != -1 ) {
outputRowData[data.pos_xml_data_type_numeric] = new Long( XMLStreamConstants.NAMESPACE );
}
if ( data.pos_xml_data_type_description != -1 ) {
outputRowData[data.pos_xml_data_type_description] = eventDescription[XMLStreamConstants.NAMESPACE];
}
}
while ( iter.hasNext() ) {
Object[] outputRowDataNamespace = data.outputRowMeta.cloneRow( outputRowData );
Namespace n = iter.next();
outputRowDataNamespace[data.pos_xml_data_name] = n.getPrefix();
outputRowDataNamespace[data.pos_xml_data_value] = n.getNamespaceURI();
if ( iter.hasNext() ) {
// send out the Namespace row
putRowOut( outputRowDataNamespace );
} else {
// last row: this will be sent out by the outer loop
outputRowData = outputRowDataNamespace;
}
}
return outputRowData;
}
代码示例来源:origin: org.wso2.staxon/staxon
QName elementName = startElement.getName();
Element element;
if (namespaceAware) {
element = document.createElementNS(elementName.getNamespaceURI(), qName(elementName));
} else {
element = document.createElement(elementName.getLocalPart());
Iterator<?> namespaces = startElement.getNamespaces();
while (namespaces.hasNext()) {
Namespace ns = (Namespace) namespaces.next();
element.setAttributeNS(ns.getName().getNamespaceURI(), qName(ns.getName()), ns.getNamespaceURI());
Iterator<?> attributes = startElement.getAttributes();
while (attributes.hasNext()) {
Attribute at = (Attribute) attributes.next();
if (namespaceAware) {
element.setAttributeNS(at.getName().getNamespaceURI(), qName(at.getName()), at.getValue());
代码示例来源:origin: jamesagnew/hapi-fhir
switch (event.getEventType()) {
case XMLStreamConstants.ATTRIBUTE:
Attribute attr = (Attribute) event;
if (isBlank(attr.getName().getPrefix())) {
if (isBlank(attr.getName().getNamespaceURI())) {
theEventWriter.writeAttribute(attr.getName().getLocalPart(), attr.getValue());
case XMLStreamConstants.NAMESPACE:
Namespace ns = (Namespace) event;
theEventWriter.writeNamespace(ns.getPrefix(), ns.getNamespaceURI());
break;
case XMLStreamConstants.START_ELEMENT:
StartElement se = event.asStartElement();
if (firstElement) {
if (StringUtils.isBlank(se.getName().getPrefix())) {
String namespaceURI = se.getName().getNamespaceURI();
if (StringUtils.isBlank(namespaceURI)) {
namespaceURI = "http://www.w3.org/1999/xhtml";
theEventWriter.writeStartElement(se.getName().getLocalPart());
theEventWriter.writeDefaultNamespace(namespaceURI);
} else {
代码示例来源:origin: org.codehaus.jettison/jettison
Iterator namespaces = element.getNamespaces();
while (namespaces.hasNext()) {
Namespace ns = (Namespace) namespaces.next();
String prefix = ns.getPrefix();
String nsURI = ns.getNamespaceURI();
streamWriter.writeNamespace(prefix, nsURI);
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)
} else if (event.isCharacters()) {
Characters chars = event.asCharacters();
streamWriter.writeCharacters(chars.getData());
} else if (event.isEndElement()) {
streamWriter.writeEndElement();
代码示例来源:origin: org.codehaus.enunciate/enunciate-full
streamWriter.writeComment(((Comment)event).getText());
break;
case XMLStreamConstants.DTD:
break;
case XMLStreamConstants.NAMESPACE:
String nsURI = ((Namespace) event).getNamespaceURI();
String prefix = ((Namespace) event).getPrefix();
streamWriter.writeNamespace(prefix, nsURI);
break;
break;
case XMLStreamConstants.START_ELEMENT:
QName qName = event.asStartElement().getName();
streamWriter.writeStartElement(qName.getNamespaceURI(), qName.getLocalPart());
break;
代码示例来源:origin: hibernate/hibernate-orm
final List<Namespace> targetNamespaces = new ArrayList<Namespace>();
if ( "".equals( startElement.getName().getNamespaceURI() ) ) {
final Iterator<Namespace> originalNamespaces = startElement.getNamespaces();
while ( originalNamespaces.hasNext() ) {
Namespace namespace = originalNamespaces.next();
if ( NAMESPACE_URIS_TO_MAP.contains( namespace.getNamespaceURI() ) ) {
namespace = xmlEventFactory.createNamespace( namespace.getPrefix(), MappingXsdSupport.INSTANCE.hbmXsd().getNamespaceUri() );
xmlEventFactory.setLocation( startElement.getLocation() );
return xmlEventFactory.createStartElement(
new QName( MappingXsdSupport.INSTANCE.hbmXsd().getNamespaceUri(), startElement.getName().getLocalPart() ),
startElement.getAttributes(),
targetNamespaces.iterator()
代码示例来源:origin: org.picketlink/picketlink-common
@SuppressWarnings("unchecked")
private String containsBaseNamespace(StartElement startElement) {
String localPart, prefix, qual = null;
Iterator<Namespace> namespaces = startElement.getNamespaces();
while (namespaces != null && namespaces.hasNext()) {
Namespace namespace = namespaces.next();
QName name = namespace.getName();
localPart = name.getLocalPart();
prefix = name.getPrefix();
if (prefix != null && prefix != "")
qual = (localPart != null && localPart != "") ? prefix + ":" + localPart : prefix;
if (qual != null && qual.equals("xmlns"))
return namespace.getNamespaceURI();
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
private void handleEndElement(EndElement endElement) throws SAXException {
if (getContentHandler() != null) {
QName qName = endElement.getName();
if (hasNamespacesFeature()) {
getContentHandler().endElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName));
for (Iterator i = endElement.getNamespaces(); i.hasNext();) {
Namespace namespace = (Namespace) i.next();
endPrefixMapping(namespace.getPrefix());
}
}
else {
getContentHandler().endElement("", "", toQualifiedName(qName));
}
}
}
代码示例来源:origin: OfficeDev/ews-java-api
XMLEvent xmleve = (XMLEvent) xmlEventReader.next();
if (xmleve.getEventType() == XmlNodeType.END_ELEMENT) {
Node node = currentElement.getParentNode();
if (node instanceof Document) {
if (xmleve.getEventType() == XmlNodeType.START_ELEMENT) {
element = document.createElementNS(ele.getName()
.getNamespaceURI(), ele.getName().getLocalPart());
Iterator<Attribute> ite = ele.getAttributes();
element.setAttribute(attr.getName().getLocalPart(),
attr.getValue());
while (ite.hasNext()) {
Namespace ns = (Namespace) ite.next();
String name = ns.getPrefix();
if (!name.isEmpty()) {
element.setAttributeNS(xmlns, name,
ns.getNamespaceURI());
} else {
xmlns = ns.getNamespaceURI();
代码示例来源:origin: com.sun.xml.bind/jaxb-impl
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;
}
代码示例来源:origin: prowide/prowide-core
public void add(final XMLEvent event) throws XMLStreamException {
if (event != null) {
try {
final int type = event.getEventType();
switch (type) {
case XMLEvent.START_DOCUMENT:
closeStartTagIfNeeded();
indent.append(' ');
final StartElement se = event.asStartElement();
if (StringUtils.equals(se.getName().getLocalPart(), this.rootElement) && this.startElementCount==1) {
delayedStart = se;
log.finest("local part is Document, initializing delayed start, startElementCount="+this.startElementCount);
} else {
out.write("\n" + indent + "<" + prefix(se.getName()) + se.getName().getLocalPart());
StringBuilder sb = new StringBuilder();
if (delayedStart != null) {
sb.append("\n" + indent + "<" + prefix(ne.getName()) + delayedStart.getName().getLocalPart());
delayedStart = null;
final Characters ce = event.asCharacters();
final char[] arr = ce.getData().toCharArray();
out.write(escape(arr));
break;
out.write(" " + a.getName() + "=\"" + a.getValue() + "\" ");
break;
代码示例来源:origin: stax/stax
private static void printNamespace(Namespace a) {
System.out.println("PREFIX: " + a.getName().getPrefix());
System.out.println("NAMESP: " + a.getName().getNamespaceURI());
System.out.println("NAME: " + a.getName().getLocalPart());
System.out.println("VALUE: " + a.getValue());
System.out.println("TYPE: " + a.getDTDType());
}
}
代码示例来源:origin: dsukhoroslov/bagri
@SuppressWarnings("unchecked")
private void startElement(XmlParserContext ctx, StartElement element) throws BagriException {
ctx.appendCharacters();
ctx.addData(element.getName().toString()); // getLocalPart());
ctx.addElement();
for (Iterator<Namespace> itr = element.getNamespaces(); itr.hasNext();) {
Namespace ns = itr.next();
// TODO: process default namespace properly
String namespace = ns.getValue();
if (namespace != null) {
String prefix = ns.getName().getLocalPart();
ctx.addNamespace(prefix, namespace);
}
}
for (Iterator<Attribute> itr = element.getAttributes(); itr.hasNext();) {
Attribute a = itr.next();
//if (!a.getName().getPrefix().isEmpty()) {
// String prefix = model.translateNamespace(a.getName().getNamespaceURI(), a.getName().getPrefix());
// ctx.addNamespace(prefix, a.getName().getNamespaceURI());
//}
ctx.addAttribute(a.getName(), a.getValue());
}
}
代码示例来源:origin: org.dom4j/dom4j
/**
* Constructs a new DOM4J Element from the provided StartElement event. All
* attributes and namespaces will be added to the returned element.
*
* @param startEvent
* The StartElement event from which to construct the new DOM4J
* Element.
*
* @return The Element constructed from the provided StartElement event.
*/
public Element createElement(StartElement startEvent) {
QName qname = startEvent.getName();
org.dom4j.QName elemName = createQName(qname);
Element elem = factory.createElement(elemName);
// create attributes
for (Iterator<Attribute> i = startEvent.getAttributes(); i.hasNext();) {
Attribute attr = i.next();
elem.addAttribute(createQName(attr.getName()), attr.getValue());
}
// create namespaces
for (Iterator<Namespace> i = startEvent.getNamespaces(); i.hasNext();) {
Namespace ns = i.next();
elem.addNamespace(ns.getPrefix(), ns.getNamespaceURI());
}
return elem;
}
代码示例来源:origin: org.opensextant/giscore
while (ev != null && !ev.isStartElement()) {
ev = stream.nextEvent();
StartElement el = ev.asStartElement();
if (!IAtomConstants.ATOM_URI_NS.equals(el.getName()
.getNamespaceURI())) {
Iterator<Namespace> niter = el.getNamespaces();
while (niter.hasNext()) {
Namespace n = niter.next();
if (StringUtils.isBlank(n.getPrefix()))
defaultNamespace = el.getName().getNamespaceURI();
else
namespaceMap.put(n.getPrefix(),
el.getNamespaceURI(n.getPrefix()));
代码示例来源:origin: apache/cxf
private static void applyEvents(List<XMLEvent> events, SOAPElement el) throws SOAPException {
if (events != null) {
for (XMLEvent ev : events) {
if (ev.isNamespace()) {
el.addNamespaceDeclaration(((Namespace)ev).getPrefix(), ((Namespace)ev).getNamespaceURI());
} else if (ev.isAttribute()) {
el.addAttribute(((Attribute)ev).getName(), ((Attribute)ev).getValue());
}
}
}
}
代码示例来源:origin: org.codehaus.woodstox/woodstox-core-asl
/**
* Method called by the matching start element class to
* output all namespace declarations active in current namespace
* scope, if any.
*/
public void outputNamespaceDeclarations(XMLStreamWriter w) throws XMLStreamException
{
for (int i = 0, len = mNamespaces.size(); i < len; ++i) {
Namespace ns = (Namespace) mNamespaces.get(i);
if (ns.isDefaultNamespaceDeclaration()) {
w.writeDefaultNamespace(ns.getNamespaceURI());
} else {
w.writeNamespace(ns.getPrefix(), ns.getNamespaceURI());
}
}
}
代码示例来源:origin: org.apache.knox/gateway-provider-rewrite
private void bufferNamespaces( StartElement event, Element element ) {
Iterator namespaces = event.getNamespaces();
while( namespaces.hasNext() ) {
Namespace namespace = (Namespace)namespaces.next();
if( namespace.isDefaultNamespaceDeclaration() ) {
element.setAttribute( "xmlns", namespace.getNamespaceURI() );
} else {
element.setAttribute( "xmlns:" + namespace.getPrefix(), namespace.getNamespaceURI() );
}
}
}
内容来源于网络,如有侵权,请联系作者删除!