Java XPath Get getBaseLocation(byte[] metadata)

Here you can find the source of getBaseLocation(byte[] metadata)

Description

get Base Location

License

Apache License

Declaration

public static String getBaseLocation(byte[] metadata) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;

public class Main {
    private static final XPath xPath = XPathFactory.newInstance().newXPath();
    private static final String BASE_LOCATION = "/artifact/baselocation/text()";

    public static String getBaseLocation(byte[] metadata) {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder;/* w  w w. j a  va  2 s  .  co m*/
        try {
            builder = builderFactory.newDocumentBuilder();
            Document document = builder.parse(new ByteArrayInputStream(metadata));
            return (String) xPath.compile(BASE_LOCATION).evaluate(document, XPathConstants.STRING);

        } catch (XPathExpressionException | ParserConfigurationException | SAXException | IOException e) {
            return null;
        }
    }
}

Related

  1. get(String path, Node e)
  2. getAttribute(String fileName, String xPathExpression, String attributeName)
  3. getBool(Node node, boolean def, XPathExpression expr)
  4. getCache()
  5. getCertificateFromKeyInfo(Node keyInfoNode)
  6. getCruxPagesXPath()