本文整理汇总了Java中javax.xml.stream.events.Namespace.getNamespaceURI方法的典型用法代码示例。如果您正苦于以下问题:Java Namespace.getNamespaceURI方法的具体用法?Java Namespace.getNamespaceURI怎么用?Java Namespace.getNamespaceURI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.events.Namespace
的用法示例。
在下文中一共展示了Namespace.getNamespaceURI方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildByNsURIMap
import javax.xml.stream.events.Namespace; //导入方法依赖的package包/类
private Map<String,Namespace> buildByNsURIMap()
{
int len = mNamespaces.size();
if (len == 0) {
return Collections.emptyMap();
}
LinkedHashMap<String,Namespace> m = new LinkedHashMap<String,Namespace>(1 + len + (len>>1));
for (int i = 0; i < len; ++i) {
Namespace ns = mNamespaces.get(i);
String uri = ns.getNamespaceURI();
if (uri == null) { // shouldn't happen but...
uri = "";
}
m.put(uri, ns);
}
return m;
}
示例2: doGetNamespaceURI
import javax.xml.stream.events.Namespace; //导入方法依赖的package包/类
@Override
public String doGetNamespaceURI(String prefix)
{
// Note: base class checks for 'known' problems and prefixes:
if (mNsByPrefix == null) {
mNsByPrefix = buildByPrefixMap();
}
Namespace ns = mNsByPrefix.get(prefix);
if (ns == null && mParentCtxt != null) {
return mParentCtxt.getNamespaceURI(prefix);
}
return (ns == null) ? null : ns.getNamespaceURI();
}
示例3: doGetPrefixes
import javax.xml.stream.events.Namespace; //导入方法依赖的package包/类
@Override
public Iterator<String> doGetPrefixes(String nsURI)
{
// Note: base class checks for 'known' problems and prefixes:
ArrayList<String> l = null;
for (int i = 0, len = mNamespaces.size(); i < len; ++i) {
Namespace ns = mNamespaces.get(i);
String uri = ns.getNamespaceURI();
if (uri == null) {
uri = "";
}
if (uri.equals(nsURI)) {
if (l == null) {
l = new ArrayList<String>();
}
String prefix = ns.getPrefix();
l.add((prefix == null) ? "" : prefix);
}
}
if (mParentCtxt != null) {
@SuppressWarnings("unchecked")
Iterator<String> it = /*(Iterator<String>)*/mParentCtxt.getPrefixes(nsURI);
if (l == null) {
return it;
}
while (it.hasNext()) {
l.add(it.next());
}
}
if (l == null) {
return DataUtil.emptyIterator();
}
return l.iterator();
}
示例4: qname
import javax.xml.stream.events.Namespace; //导入方法依赖的package包/类
/**
* Combines a Namespace and local name into a QName.
*/
public static QName qname(Namespace ns, String name) {
return new QName(ns.getNamespaceURI(), name, ns.getPrefix());
}
示例5: add
import javax.xml.stream.events.Namespace; //导入方法依赖的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;
}
}
示例6: add
import javax.xml.stream.events.Namespace; //导入方法依赖的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);
}
}
示例7: retriveDocument
import javax.xml.stream.events.Namespace; //导入方法依赖的package包/类
/**
* @return document
* @throws javax.xml.parsers.ParserConfigurationException
*/
public Document retriveDocument(XMLEventReader xmlEventReader)
throws ParserConfigurationException {
DocumentBuilderFactory dbfInstance = DocumentBuilderFactory
.newInstance();
DocumentBuilder documentBuilder = dbfInstance.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element currentElement = document.getDocumentElement();
while (xmlEventReader.hasNext()) {
XMLEvent xmleve = (XMLEvent) xmlEventReader.next();
if (xmleve.getEventType() == XmlNodeType.END_ELEMENT) {
Node node = currentElement.getParentNode();
if (node instanceof Document) {
currentElement = ((Document) node).getDocumentElement();
} else {
currentElement = (Element) currentElement.getParentNode();
}
}
if (xmleve.getEventType() == XmlNodeType.START_ELEMENT) {
// startElement((StartElement) xmleve,doc);
StartElement ele = (StartElement) xmleve;
Element element = null;
element = document.createElementNS(ele.getName()
.getNamespaceURI(), ele.getName().getLocalPart());
Iterator<Attribute> ite = ele.getAttributes();
while (ite.hasNext()) {
Attribute attr = ite.next();
element.setAttribute(attr.getName().getLocalPart(),
attr.getValue());
}
String xmlns = EwsUtilities.WSTrustFebruary2005Namespace;//"http://schemas.xmlsoap.org/wsdl/";
ite = ele.getNamespaces();
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();
}
}
if (currentElement == null) {
document.appendChild(element);
} else {
currentElement.appendChild(element);
}
currentElement = element;
element.setUserData("location", ele.getLocation(), null);
}
}
return document;
}
示例8: retriveDocument
import javax.xml.stream.events.Namespace; //导入方法依赖的package包/类
/**
*
* @param xmlEventReader
* @return document
* @throws ParserConfigurationException
*/
public Document retriveDocument(XMLEventReader xmlEventReader)
throws ParserConfigurationException {
DocumentBuilderFactory dbfInstance = DocumentBuilderFactory
.newInstance();
DocumentBuilder documentBuilder = dbfInstance.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element currentElement = document.getDocumentElement();
while (xmlEventReader.hasNext()) {
XMLEvent xmleve = (XMLEvent) xmlEventReader.next();
if (xmleve.getEventType() == XMLNodeType.END_ELEMENT) {
Node node = currentElement.getParentNode();
if (node instanceof Document) {
currentElement = ((Document) node).getDocumentElement();
} else {
currentElement = (Element) currentElement.getParentNode();
}
}
if (xmleve.getEventType() == XMLNodeType.START_ELEMENT) {
// startElement((StartElement) xmleve,doc);
StartElement ele = (StartElement) xmleve;
Element element = null;
element = document.createElementNS(ele.getName()
.getNamespaceURI(), ele.getName().getLocalPart());
Iterator ite = ele.getAttributes();
while (ite.hasNext()) {
Attribute attr = (Attribute) ite.next();
element.setAttribute(attr.getName().getLocalPart(),
attr.getValue());
}
String xmlns = EwsUtilities.WSTrustFebruary2005Namespace;//"http://schemas.xmlsoap.org/wsdl/";
ite = ele.getNamespaces();
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();
}
}
if (currentElement == null) {
document.appendChild(element);
} else {
currentElement.appendChild(element);
}
currentElement = element;
element.setUserData("location", ele.getLocation(), null);
}
}
return document;
}