Java Utililty Methods XML Namespace

List of utility methods to do XML Namespace

  1. HOME
  2. Java
  3. X
  4. XML Namespace

Description

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

Method

XPathExpression compile(String expression, NamespaceContext namespaceContext)
Compiles an XPath expression for later evaluation.
return createXPath(namespaceContext, null).compile(expression);
NamespaceContext createNamespaceContext(final String nsPrefix, final String nsUri)
create Namespace Context
return new NamespaceContext() {
 public String getNamespaceURI(String prefix) {
 if (prefix.equals(nsPrefix)) {
 return nsUri;
 } else {
 return XMLConstants.NULL_NS_URI;
 public String getPrefix(String namespace) {
 if (namespace.equals(nsUri)) {
 return nsPrefix;
 } else {
 return null;
 public Iterator<String> getPrefixes(String namespace) {
 return null;
};
XMLReader createXMLReader(boolean validating, boolean namespaceAware)
This method attempts to use JAXP to locate the SAX2 XMLReader implementation.
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(validating);
factory.setNamespaceAware(namespaceAware);
SAXParser parser = factory.newSAXParser();
return parser.getXMLReader();
XMLReader createXMLReader(boolean validating, boolean withNamespace)
Create an XMLReader instance.
try {
 synchronized (parserFactory) {
 parserFactory.setValidating(validating);
 parserFactory.setNamespaceAware(withNamespace);
 return parserFactory.newSAXParser().getXMLReader();
} catch (ParserConfigurationException e) {
 throw new SAXException(e);
...
String getBaseNamespace(InputStream owlStream)
get Base Namespace
String base = "";
try {
 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 factory.setNamespaceAware(true);
 DocumentBuilder builder = factory.newDocumentBuilder();
 Document doc = builder.parse(owlStream);
 Element root = doc.getDocumentElement();
 NamedNodeMap attributes = root.getAttributes();
...
DocumentBuilder getBuilder(boolean ignoreComments, boolean validating, boolean ignoreContentWhitespace, boolean isNamespaceAware)
get Builder
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setIgnoringComments(ignoreComments);
factory.setValidating(validating);
factory.setIgnoringElementContentWhitespace(ignoreContentWhitespace);
factory.setNamespaceAware(isNamespaceAware);
DocumentBuilder builder = null;
try {
 builder = factory.newDocumentBuilder();
...
NamespaceContext getCarbonNamespace()
get Carbon Namespace
NamespaceContext ctx = new NamespaceContext() {
 public String getNamespaceURI(String prefix) {
 return "http://wso2.org/projects/carbon/carbon.xml";
 public String getPrefix(String arg0) {
 return null;
 public Iterator getPrefixes(String namespaceURI) {
...
String getDefaultNamespaceURI(final XMLStreamWriter writer)
get Default Namespace URI
return writer.getNamespaceContext().getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX);
DocumentBuilderFactory getFactory(boolean validate, boolean namespaceAware)
get Factory
DocumentBuilderFactory factory = doms[validate ? 0 : 1][namespaceAware ? 0 : 1];
if (factory == null) {
 factory = DocumentBuilderFactory.newInstance();
 factory.setValidating(validate);
 factory.setNamespaceAware(namespaceAware);
 doms[validate ? 0 : 1][namespaceAware ? 0 : 1] = factory;
return factory;
...
String getNamespace(Class clazz, String namespace)
get Namespace
if (namespace == null || namespace.trim().length() == 0) {
 Package pkg = clazz.getPackage();
 if (pkg == null) {
 return null;
 } else {
 return getNamespace(pkg.getName());
} else {
...


AltStyle によって変換されたページ (->オリジナル) /