Java Utililty Methods XML Namespace

List of utility methods to do XML Namespace

Description

The list of methods to do XML Namespace are organized into topic(s).

Method

DocumentreadXML(InputStream input, boolean isNamespaceAware)
Parses the given input stream and returns the corresponding desirialized XML document.
return readXML(new InputStreamReader(input, "UTF-8"), isNamespaceAware);
DocumentstringToDoc(String s, boolean nameSpaceAware)
/* Parse an XML string into a DOM document
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(nameSpaceAware);
DocumentBuilder docBuilder = domFactory.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(s));
Document doc = docBuilder.parse(is);
return doc;
voidwriteNamespace(XMLStreamWriter out, String prefix, String namespaceURI)
Write the namespace if necessary.
NamespaceContext namespaceContext = out.getNamespaceContext();
boolean writeNamespace = (namespaceContext.getPrefix(namespaceURI) == null);
if (writeNamespace) {
    out.setPrefix(prefix, namespaceURI);
    out.writeNamespace(prefix, namespaceURI);
voidwriteNamespace(XMLStreamWriter writer, String prefix, String namespaceURI)
write Namespace
if (prefix == null || NO_PREFIX.equals(prefix)) {
    writer.writeDefaultNamespace(namespaceURI);
} else {
    writer.writeNamespace(prefix, namespaceURI);
voidwriteNamespaceDeclarations(final XMLStreamWriter writer, final Iterable> prefixes)
write Namespace Declarations
for (Entry<URI, String> e : prefixes) {
    final String ns = e.getKey().toString();
    final String p = e.getValue();
    writer.writeNamespace(p, ns);
voidwriteNamespaceIfNotBound(XMLStreamWriter xmlStream, String prefix, String nsUri)
write Namespace If Not Bound
if (!prefix.equals(xmlStream.getPrefix(nsUri))) {
    xmlStream.writeNamespace(prefix, nsUri);
voidwriteNamespaces(XMLStreamWriter writer, Iterator namespaces)
write Namespaces
while (namespaces.hasNext()) {
    Namespace ns = (Namespace) namespaces.next();
    writer.writeNamespace(ns.getPrefix(), ns.getNamespaceURI());