当前位置: 首页>>代码示例>>Java>>正文


Java XPath.selectSingleNode方法代码示例

本文整理汇总了Java中org.jdom.xpath.XPath.selectSingleNode方法的典型用法代码示例。如果您正苦于以下问题:Java XPath.selectSingleNode方法的具体用法?Java XPath.selectSingleNode怎么用?Java XPath.selectSingleNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jdom.xpath.XPath的用法示例。


在下文中一共展示了XPath.selectSingleNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: login

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private HttpClient login(PostMethod method) throws Exception {
  HttpClient client = getHttpClient();
  int status = client.executeMethod(method);
  if (status != 200) {
    throw new Exception("Error logging in: " + method.getStatusLine());
  }
  Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument();
  XPath path = XPath.newInstance("/response/token");
  Element result = (Element)path.selectSingleNode(document);
  if (result == null) {
    Element error = (Element)XPath.newInstance("/response/error").selectSingleNode(document);
    throw new Exception(error == null ? "Error logging in" : error.getText());
  }
  token = result.getTextTrim();
  return client;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:17,代码来源:FogBugzRepository.java

示例2: updateAlias

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private void updateAlias(String includeOrigin, String includeDestination, File ear) throws JDOMException, IOException, JDOMException {
	TFile xmlTIBCO = new TFile(ear.getAbsolutePath() + File.separator + "TIBCO.xml");
	String tempPath = ear.getParentFile().getAbsolutePath() + File.separator + "TIBCO.xml";
	TFile xmlTIBCOTemp = new TFile(tempPath);

	truezip.copyFile(xmlTIBCO, xmlTIBCOTemp);

	File xmlTIBCOFile = new File(tempPath);

	SAXBuilder sxb = new SAXBuilder();
	Document document = sxb.build(xmlTIBCOFile);

	XPath xpa = XPath.newInstance("//dd:NameValuePairs/dd:NameValuePair[starts-with(dd:name, 'tibco.alias') and dd:value='" + includeOrigin + "']/dd:value");
	xpa.addNamespace("dd", "http://www.tibco.com/xmlns/dd");

	Element singleNode = (Element) xpa.selectSingleNode(document);
	if (singleNode != null) {
		singleNode.setText(includeDestination);
		XMLOutputter xmlOutput = new XMLOutputter();
		xmlOutput.setFormat(Format.getPrettyFormat().setIndent("    "));
		xmlOutput.output(document, new FileWriter(xmlTIBCOFile));

		truezip.copyFile(xmlTIBCOTemp, xmlTIBCO);
	}

	updateAliasInPARs(includeOrigin, includeDestination, ear);
}
 
开发者ID:fastconnect,项目名称:tibco-bwmaven,代码行数:28,代码来源:IncludeDependenciesInEARMojo.java

示例3: updateAliasInPARs

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private void updateAliasInPARs(String includeOrigin, String includeDestination, File ear) throws IOException, JDOMException {
	TrueZipFileSet pars = new TrueZipFileSet();
	pars.setDirectory(ear.getAbsolutePath());
	pars.addInclude("*.par");
	List<TFile> parsXML = truezip.list(pars);
	for (TFile parXML : parsXML) {
		TFile xmlTIBCO = new TFile(parXML, "TIBCO.xml");

		String tempPath = ear.getParentFile().getAbsolutePath() + File.separator + "TIBCO.xml";
		TFile xmlTIBCOTemp = new TFile(tempPath);

		truezip.copyFile(xmlTIBCO, xmlTIBCOTemp);

		File xmlTIBCOFile = new File(tempPath);

		SAXBuilder sxb = new SAXBuilder();
		Document document = sxb.build(xmlTIBCOFile);

		XPath xpa = XPath.newInstance("//dd:NameValuePairs/dd:NameValuePair[dd:name='EXTERNAL_JAR_DEPENDENCY']/dd:value");
		xpa.addNamespace("dd", "http://www.tibco.com/xmlns/dd");

		Element singleNode = (Element) xpa.selectSingleNode(document);
		if (singleNode != null) {
			String value = singleNode.getText().replace(includeOrigin, includeDestination);
			singleNode.setText(value);
			XMLOutputter xmlOutput = new XMLOutputter();
			xmlOutput.setFormat(Format.getPrettyFormat().setIndent("    "));
			xmlOutput.output(document, new FileWriter(xmlTIBCOFile));

			truezip.copyFile(xmlTIBCOTemp, xmlTIBCO);
		}
	}
}
 
开发者ID:fastconnect,项目名称:tibco-bwmaven,代码行数:34,代码来源:IncludeDependenciesInEARMojo.java

示例4: testVersions

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
@Test
public void testVersions() throws Exception {

    XPath xpath = XPath.newInstance("/ns:project/ns:properties");
    xpath.addNamespace(Namespace.getNamespace("ns", "http://maven.apache.org/POM/4.0.0"));
    Element node = (Element) xpath.selectSingleNode(wfcRoot);
    for (Object child : node.getChildren()) {
        String wfcKey = ((Element) child).getName();
        String wfcVal = ((Element) child).getText();
        String targetVal = getTargetValue(wfcKey);
        if (targetVal != null) {
            if (!targetVal.equals(wfcVal) && !targetVal.startsWith(wfcVal + ".redhat")) {
                problems.add(wfcKey + ": " + wfcVal + " => " + targetVal);
            }
        }
    }
    for (String line : problems) {
        System.err.println(line);
    }
    Assert.assertEquals("Mapping problems", Collections.emptyList(), problems);
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:22,代码来源:VersionsValidatorTest.java

示例5: getTargetValue

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
public String getTargetValue(String wfcKey) throws JDOMException {

        Element rootNode;
        if (wfcKey.startsWith("version.camel.")) {
            rootNode = camelRoot;
        } else if (wfcKey.startsWith("version.wildfly.")) {
            rootNode = wfRoot;
        } else {
            return null;
        }

        String targetKey = mapping.get(wfcKey);
        if (targetKey == null) {
            problems.add("Cannot find mapping for: " + wfcKey);
            return null;
        }
        XPath xpath = XPath.newInstance("/ns:project/ns:properties/ns:" + targetKey);
        xpath.addNamespace(Namespace.getNamespace("ns", "http://maven.apache.org/POM/4.0.0"));
        Element propNode = (Element) xpath.selectSingleNode(rootNode);
        if (propNode == null) {
            problems.add("Cannot obtain target property: " + targetKey);
            return null;
        }
        return propNode.getText();
    }
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:26,代码来源:VersionsValidatorTest.java

示例6: init

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private void init() throws IOException {
	Document request = MyUtils.toDocument(wsdlDoc
			.generateRequest(parentOperation));
	setDocumentation();
	String expression = "//*[local-name()='" + name + "'][1]/text()";
	try {
		XPath xp = XPath.newInstance(expression);
		Text t = (Text) xp.selectSingleNode(request);
		String value = t.getText();
		if (value.equals("?")) {
			defaultValue = "";
		} else if (value.startsWith("cid:")) {
			binary = true;
			defaultValue = "";
		} else {
			defaultValue = value;
		}

	} catch (JDOMException e) {
		throw new IOException("Could not read the generated SOAP using "
				+ expression, e);
	}
}
 
开发者ID:impactcentre,项目名称:iif-generic-soap-client,代码行数:24,代码来源:SoapInput.java

示例7: setValue

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private void setValue() {

		try {
			SAXBuilder parser = new SAXBuilder();
			Document jdomDoc = parser.build(new ByteArrayInputStream(response
					.getBytes()));
			String expression = "//*[local-name()='" + name + "'][1]/text()";
			XPath xp = XPath.newInstance(expression);
			Text t = (Text) xp.selectSingleNode(jdomDoc);
			if (t != null)
				value = t.getText();

		} catch (JDOMException | IOException e) {
			logger.error("Could not set value for output " + name, e);
		}

    }
 
开发者ID:impactcentre,项目名称:iif-generic-soap-client,代码行数:18,代码来源:SoapOutput.java

示例8: getElementByXPath

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
/**
 * A utility class that returns an element based on the XPath to that element.
 * @param xpathValue the XPath string of the element to be found.
 * @return the element specified by the XPath.
 * @throws JDOMException
 */
public Element getElementByXPath(String xpathValue) throws JDOMException {
    // E.g. xpathValue="/lasdata/operations/operation[@ID='Plot']"
	String xpv = Encode.forJava(xpathValue);
    Object jdomO = this;
    XPath xpath = XPath.newInstance(xpv);
    return (Element) xpath.selectSingleNode(jdomO);   
}
 
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:14,代码来源:IOSPDocument.java

示例9: login

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
private void login(@NotNull PostMethod method) throws Exception {
  LOG.debug("Requesting new token");
  int status = getHttpClient().executeMethod(method);
  if (status != 200) {
    throw new Exception("Error logging in: " + method.getStatusLine());
  }
  Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument();
  XPath path = XPath.newInstance("/response/token");
  Element result = (Element)path.selectSingleNode(document);
  if (result == null) {
    Element error = (Element)XPath.newInstance("/response/error").selectSingleNode(document);
    throw new Exception(error == null ? "Error logging in" : error.getText());
  }
  myToken = result.getTextTrim();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:FogBugzRepository.java

示例10: GetElementAttr

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
/**
 * Get the text for the selected element
 * 
 * @param xPathExpression
 *            The xpath expression for the element
 * @return The text value of the element
 */
public String GetElementAttr(String xPathExpression) {
    try {
        org.jdom.Attribute node = (Attribute) XPath.selectSingleNode(this.xmlDocument, xPathExpression);
        return node.getValue();
    } catch (Exception ex) {
        LOG.error("Error in handler: " + ex.getMessage(), ex);
        return "";
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:17,代码来源:GenericXMLHandler.java

示例11: xPathExists

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
/**
 * Does an xPath expression exist
 * 
 * @param xpathExpr
 *            The xPath expression
 * @return TRUE if the xPath expression exists; false otherwise
 */
public boolean xPathExists(String xpathExpr)
{
    try {
        if (XPath.selectSingleNode(this.xmlDocument, xpathExpr) == null)
            return false;
        return true;
    } catch (Exception ex) {
        return false;
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:18,代码来源:GenericXMLHandler.java

示例12: xpathSelectElement

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
protected Object xpathSelectElement(Element element, String xpath) throws JDOMException {
	XPath x = XPath.newInstance(xpath);
	x.addNamespace(MANIFEST_NS);
	x.addNamespace(CONTAINER_NS);
	x.addNamespace(EXAMPLE_NS);

	return x.selectSingleNode(element);
}
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:9,代码来源:TestUCFPackage.java

示例13: xpathSelectElement

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
protected Object xpathSelectElement(Element element, String xpath) throws JDOMException {
	XPath x = XPath.newInstance(xpath);
	x.addNamespace(SCUFL2_NS);
	x.addNamespace(RDF_NS);
	x.addNamespace(RDSF_NS);
	x.addNamespace(BEANSHELL_NS);
	//x.addNamespace(XML_NS);

	return x.selectSingleNode(element);
}
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:11,代码来源:TestRDFXMLSerializer.java

示例14: getElementText

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
protected String getElementText(Element elem,String xpath) throws JDOMException {
	Text text = ((Text)XPath.selectSingleNode(elem, xpath+"/text()"));
	if(null == text) {
		return "";
	}
	return text.getText();
}
 
开发者ID:magenm,项目名称:bsming,代码行数:8,代码来源:WxRecvMsgBaseParser.java

示例15: findResource

import org.jdom.xpath.XPath; //导入方法依赖的package包/类
public Element
findResource(Ns ns, String the_identifier, Element the_resources) throws ParseException {
  Element result=null;
  try {
    String query=RESOURCE_QUERY.replaceFirst("xxx", the_identifier);
    XPath path=XPath.newInstance(query);
    path.addNamespace(ns.getNs());
    result= (Element)path.selectSingleNode(the_resources);
  } catch (JDOMException e) {
    throw new ParseException(e.getMessage(),e);
  }
  return result;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:14,代码来源:AbstractParser.java


注:本文中的org.jdom.xpath.XPath.selectSingleNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。