本文整理汇总了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;
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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();
}
示例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 "";
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}