本文整理汇总了Java中javax.xml.xpath.XPathFactory.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java XPathFactory.newInstance方法的具体用法?Java XPathFactory.newInstance怎么用?Java XPathFactory.newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.xpath.XPathFactory
的用法示例。
在下文中一共展示了XPathFactory.newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: XPathMetadataExtracter
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
/**
* Default constructor
*/
public XPathMetadataExtracter()
{
super(new HashSet<String>(Arrays.asList(SUPPORTED_MIMETYPES)));
try
{
DocumentBuilderFactory normalFactory = DocumentBuilderFactory.newInstance();
documentBuilder = normalFactory.newDocumentBuilder();
DocumentBuilderFactory dtdIgnoringFactory = DocumentBuilderFactory.newInstance();
dtdIgnoringFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
dtdIgnoringFactory.setFeature("http://xml.org/sax/features/validation", false);
dtdIgnoringDocumentBuilder = dtdIgnoringFactory.newDocumentBuilder();
xpathFactory = XPathFactory.newInstance();
}
catch (Throwable e)
{
throw new AlfrescoRuntimeException("Failed to initialize XML metadata extractor", e);
}
}
示例2: countNodes
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
/**
* Count nodes which are given via xpath expression
*/
public static Double countNodes(Node node, String nodePath)
throws XPathExpressionException {
final XPathFactory factory = XPathFactory.newInstance();
final XPath xpath = factory.newXPath();
final XPathExpression expr = xpath.compile("count(" + nodePath + ')');
return (Double) expr.evaluate(node, XPathConstants.NUMBER);
}
示例3: EasyTravelScenarioService
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
public EasyTravelScenarioService(RestTemplate restTemplate, EasyTravelConfigurationProperties conf) {
this.restTemplate = restTemplate;
this.xPathFactory = XPathFactory.newInstance();
this.documentBuilderFactory = DocumentBuilderFactory.newInstance();
this.apiUrl = conf.getApiUrl();
this.availableScenarioConfigsMap = conf.getAvailableScenarios().stream().collect(Collectors.toMap(ScenarioConfigProperty::getId, sc -> sc));
this.availableScenarioNames = conf.getAvailableScenarioNames();
}
示例4: jaxpFactories
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
@DataProvider(name = "jaxpFactories")
public Object[][] jaxpFactories() throws Exception {
return new Object[][] {
{ DocumentBuilderFactory.newInstance(), (Produce)factory -> ((DocumentBuilderFactory)factory).newDocumentBuilder() },
{ SAXParserFactory.newInstance(), (Produce)factory -> ((SAXParserFactory)factory).newSAXParser() },
{ SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI), (Produce)factory -> ((SchemaFactory)factory).newSchema() },
{ TransformerFactory.newInstance(), (Produce)factory -> ((TransformerFactory)factory).newTransformer() },
{ XMLEventFactory.newInstance(), (Produce)factory -> ((XMLEventFactory)factory).createStartDocument() },
{ XMLInputFactory.newInstance(), (Produce)factory -> ((XMLInputFactory)factory).createXMLEventReader(new StringReader("")) },
{ XMLOutputFactory.newInstance(), (Produce)factory -> ((XMLOutputFactory)factory).createXMLEventWriter(new StringWriter()) },
{ XPathFactory.newInstance(), (Produce)factory -> ((XPathFactory)factory).newXPath() },
{ DatatypeFactory.newInstance(), (Produce)factory -> ((DatatypeFactory)factory).newXMLGregorianCalendar() }
};
}
示例5: createXPath
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
private XPath createXPath() throws XPathFactoryConfigurationException {
XPathFactory xpathFactory = XPathFactory.newInstance();
Assert.assertNotNull(xpathFactory);
XPath xpath = xpathFactory.newXPath();
Assert.assertNotNull(xpath);
return xpath;
}
示例6: testClassLoader
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
@Test
public void testClassLoader() {
MyClassLoader cl = runWithAllPerm(() -> new MyClassLoader());
runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(cl));
XPathFactory xPathFactory = XPathFactory.newInstance();
if (!cl.isCalled()) {
Assert.fail("Context class loader should be used.");
}
}
示例7: getXPathFactory
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
private static synchronized XPathFactory getXPathFactory()
{
if( xpathFactory == null )
{
xpathFactory = XPathFactory.newInstance();
}
return xpathFactory;
}
示例8: initializeXPath
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
private static XPath initializeXPath() {
final Map<String, String> mappings = new HashMap<>();
mappings.put(BRP_NAMESPACE_PREFIX.replace(":", ""), BRP_NAMESPACE_URI);
final SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext();
simpleNamespaceContext.setBindings(mappings);
final XPathFactory xPathFactory = XPathFactory.newInstance();
final XPath xpath = xPathFactory.newXPath();
xpath.setNamespaceContext(simpleNamespaceContext);
return xpath;
}
示例9: transform
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
private String transform(Document document) throws Exception {
XPathFactory xpf = XPathFactory.newInstance();
XPath xpath = xpf.newXPath();
XPathExpression testNameExpression = xpath.compile("//test-case/name");
NodeList testNameNodes = (NodeList) testNameExpression.evaluate(document, XPathConstants.NODESET);
for (int i = 0; i < testNameNodes.getLength(); i++) {
testNameNodes.item(i).getFirstChild().setNodeValue(testNameNodes.item(i).getTextContent().replace("'", ""));
}
String xmlAfterTransform = Util.getXMLFile(document);
return xmlAfterTransform;
}
示例10: AddNotificationSchemaXML
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
@SuppressWarnings("nls")
public AddNotificationSchemaXML()
{
XPathFactory factory = XPathFactory.newInstance();
xpath = factory.newXPath();
try
{
allNodes = xpath.compile("nodes/com.tle.common.workflow.node.WorkflowItem");
}
catch( XPathExpressionException e )
{
throw new RuntimeException(e);
}
}
示例11: getNode
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
public Node getNode(String xPathExpression, Object item) throws XPathExpressionException{
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
return (Node)xPath.evaluate(xPathExpression, item, XPathConstants.NODE);
}
示例12: init
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
public void init() {
factory = XPathFactory.newInstance();
xpath = factory.newXPath();
expCache = new Hashtable<String, XPathExpression>();
}
示例13: LoadFromXML
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
public boolean LoadFromXML(Document doc, boolean colando) {
HashMap<Element, FormaElementar> link = new HashMap<>();
try {
//<editor-fold defaultstate="collapsed" desc="Remover espaços - http://stackoverflow.com/questions/978810/how-to-strip-whitespace-only-text-nodes-from-a-dom-before-serialization">
XPathFactory xpathFactory = XPathFactory.newInstance();
// XPath to find empty text nodes.
XPathExpression xpathExp = xpathFactory.newXPath().compile(
"//text()[normalize-space(.) = '']");
NodeList emptyTextNodes = (NodeList) xpathExp.evaluate(doc, XPathConstants.NODESET);
// Remove each empty text node from document.
for (int i = 0; i < emptyTextNodes.getLength(); i++) {
Node emptyTextNode = emptyTextNodes.item(i);
emptyTextNode.getParentNode().removeChild(emptyTextNode);
}
//</editor-fold>
NodeList nodeLst = doc.getElementsByTagName(Diagrama.nodePrincipal);
Node mer = nodeLst.item(0);
nodeLst = mer.getChildNodes();
if (colando) {
ClearSelect(true);
((InfoDiagrama) infoDiagrama).setDiagramaOldUniversalUnicID(String.valueOf(((Element) mer).getAttribute("UniversalUnicID")));
}
this.isLoadCreate = true;
this.isCarregando = true;
int tl = 0;
int maxID = 0;
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElmnt = (Element) fstNode;
FormaElementar res = runCriadorFromXml(fstElmnt, colando);
if (res == null) {
util.BrLogger.Logger("ERROR_DIAGRAMA_LOAD", "Lixo ou objeto alienígena encontrado: " + fstElmnt.toString() + " - não é possível colar este objeto", "[]");
continue;
}
tl++;
if (!colando) {
maxID = Math.max(maxID, res.getID());
}
link.put(fstElmnt, res);
maxID = OnLoadingXMLitem(res, fstElmnt, colando, maxID, link);
}
}
if (!colando) {
TotalID = maxID;
}
this.isLoadCreate = false;
link.keySet().stream().forEach((el) -> {
FormaElementar proc = link.get(el);
proc.CommitXML(el, link);
});
this.isCarregando = false;
if (colando) {
if (((Element) mer).hasAttribute("FIRST_SEL")) {
ReestrutureSelecao(((Element) mer).getAttribute("FIRST_SEL"), link);
}
}
if (tl > 0 && colando) {
DoMuda(null);
}
PerformInspector();
} catch (Exception e) {
util.BrLogger.Logger("ERROR_DIAGRAMA_LOAD", e.getMessage());
this.isLoadCreate = false;
this.isCarregando = false;
return false;
}
repaint();
return true;
}
示例14: testNewInstance
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
/**
* Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
* points to correct implementation of javax.xml.xpath.XPathFactory , should
* return newInstance of XPathFactory
*
* @param uri
* @param factoryClassName
* @param classLoader
* @throws XPathFactoryConfigurationException
*/
@Test(dataProvider = "parameters")
public void testNewInstance(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException {
XPathFactory xpf = XPathFactory.newInstance(uri, factoryClassName, classLoader);
XPath xpath = xpf.newXPath();
assertNotNull(xpath);
}
示例15: getElementByXPath
import javax.xml.xpath.XPathFactory; //导入方法依赖的package包/类
public static Element getElementByXPath(Element e, String xPathExpression) throws XPathExpressionException {
XPathFactory factory=XPathFactory.newInstance();
XPath xPath=factory.newXPath();
return (Element)(xPath.evaluate(xPathExpression, e, XPathConstants.NODE));
}