本文整理汇总了Java中org.dom4j.XPath.selectNodes方法的典型用法代码示例。如果您正苦于以下问题:Java XPath.selectNodes方法的具体用法?Java XPath.selectNodes怎么用?Java XPath.selectNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dom4j.XPath
的用法示例。
在下文中一共展示了XPath.selectNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRecordCount
import org.dom4j.XPath; //导入方法依赖的package包/类
public int getRecordCount ()
{
Map<String,String> uris = new HashMap<String,String>();
uris.put( "ddsws", "http://www.dlese.org/Metadata/ddsws" );
uris.put( "groups", "http://www.dlese.org/Metadata/groups/" );
uris.put( "adn", "http://adn.dlese.org" );
uris.put( "annotation", "http://www.dlese.org/Metadata/annotation" );
XPath xpath = DocumentHelper.createXPath( "//ddsws:results/ddsws:record" );
xpath.setNamespaceURIs( uris );
List recordNodes = xpath.selectNodes(this.document);
return recordNodes.size();
}
示例2: getXmlUser
import org.dom4j.XPath; //导入方法依赖的package包/类
public void getXmlUser(Document doc, Map<String, String> userColumn) {
// 根据xpath方式得到所要得到xml文档的具体对象,根据分析解析xml文档可知,xml文档中含有前缀名
Map<String, String> map = new HashMap<String, String>();
map.put("c", "collection");
// 根据xml文档,//c:Table 即为得到的文档对象
XPath path = doc.createXPath("//c:Users");
path.setNamespaceURIs(map);
List<Element> list = path.selectNodes(doc);
// 得到tables对象,该对象是该pdm文件中所有表的集合
for (Element element : list) {
for (Iterator<Element> iter = element.elementIterator("User"); iter
.hasNext();) {
Element userElement = iter.next();
Attribute attribute = userElement.attribute("Id");
userColumn.put(attribute.getText(),
userElement.elementText("Code"));
// setUserlist(userElement.elementText("Code"));
}
}
}
示例3: isMysql
import org.dom4j.XPath; //导入方法依赖的package包/类
public boolean isMysql(Document doc) {
// 根据xpath方式得到所要得到xml文档的具体对象,根据分析解析xml文档可知,xml文档中含有前缀名
Map<String, String> map = new HashMap<String, String>();
map.put("c", "collection");
// 根据xml文档,//c:Table 即为得到的文档对象
XPath path = doc.createXPath("//c:DBMS");
path.setNamespaceURIs(map);
List<Element> list = path.selectNodes(doc);
// 得到tables对象,该对象是该pdm文件中所有表的集合
for (Element element : list) {
for (Iterator<Element> iter = element.elementIterator("Shortcut"); iter
.hasNext();) {
Element userElement = iter.next();
String s = userElement.elementText("Code").toUpperCase();
if (s.substring(0, 5).equals("MYSQL")) {
logger.debug(s);
return true;
} else if (s.substring(0, 6).equals("ORACLE")) {
logger.debug(s);
return false;
}
}
}
return false;
}
示例4: convertTableSettings
import org.dom4j.XPath; //导入方法依赖的package包/类
private void convertTableSettings(final Document doc) {
XPath xpathSelector = DocumentHelper.createXPath("/settings/columns/column");
List<?> results = xpathSelector.selectNodes(doc);
List<String> tableColumnNames = new ArrayList<String>();
List<String> tableColumnVisible = new ArrayList<String>();
for (Iterator<?> iter = results.iterator(); iter.hasNext();) {
Element element = (Element) iter.next();
Attribute name = element.attribute("name");
Attribute visible = element.attribute("visible");
tableColumnNames.add(name.getText());
if (visible.getText().equals("true")) {
tableColumnVisible.add(name.getText());
}
}
String mode = convertFlag(doc);
writeTableSettings(doc, mode, tableColumnNames, tableColumnVisible);
}
示例5: convertFlag
import org.dom4j.XPath; //导入方法依赖的package包/类
private String convertFlag(final Document doc) {
XPath flagSelector = DocumentHelper.createXPath("/settings/flags/flag");
List<?> flagResults = flagSelector.selectNodes(doc);
boolean text = false;
boolean window = false;
for (Iterator<?> iter = flagResults.iterator(); iter.hasNext();) {
Element element = (Element) iter.next();
Attribute key = element.attribute("key");
Attribute visible = element.attribute("enabled");
if (key.getText().equals("FLAG_AUTO_RESIZE_COLUMNS_TEXT")) {
text = visible.getText().equals("true");
element.detach();
}
if (key.getText().equals("FLAG_AUTO_RESIZE_COLUMNS_WINDOW")) {
window = visible.getText().equals("true");
element.detach();
}
}
if (text) {
return "TEXT";
}
if (window) {
return "WINDOW";
}
return "NONE";
}
示例6: applyXPath
import org.dom4j.XPath; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private boolean applyXPath()
{
try{
XPath xpath = data.document.createXPath(data.PathValue);
if(meta.isNamespaceAware())
{
xpath = data.document.createXPath(addNSPrefix(data.PathValue, data.PathValue));
xpath.setNamespaceURIs(data.NAMESPACE);
}
// get nodes list
data.an = (List<AbstractNode>) xpath.selectNodes(data.document);
data.nodesize=data.an.size();
data.nodenr=0;
}catch (Exception e)
{
log.logError(toString(),Messages.getString("GetXMLData.Log.ErrorApplyXPath",e.getMessage()));
return false;
}
return true;
}
示例7: applyXPath
import org.dom4j.XPath; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private boolean applyXPath()
{
try{
XPath xpath = data.document.createXPath(data.PathValue);
if(meta.isNamespaceAware())
{
xpath = data.document.createXPath(addNSPrefix(data.PathValue, data.PathValue));
xpath.setNamespaceURIs(data.NAMESPACE);
}
// get nodes list
data.an = (List<AbstractNode>) xpath.selectNodes(data.document);
data.nodesize=data.an.size();
data.nodenr=0;
}catch (Exception e)
{
logError(BaseMessages.getString(PKG, "GetXMLData.Log.ErrorApplyXPath",e.getMessage()));
return false;
}
return true;
}
示例8: applyXPath
import org.dom4j.XPath; //导入方法依赖的package包/类
@SuppressWarnings( "unchecked" )
private boolean applyXPath() {
try {
XPath xpath = data.document.createXPath( data.PathValue );
if ( meta.isNamespaceAware() ) {
xpath = data.document.createXPath( addNSPrefix( data.PathValue, data.PathValue ) );
xpath.setNamespaceURIs( data.NAMESPACE );
}
// get nodes list
data.an = xpath.selectNodes( data.document );
data.nodesize = data.an.size();
data.nodenr = 0;
} catch ( Exception e ) {
logError( BaseMessages.getString( PKG, "GetXMLData.Log.ErrorApplyXPath", e.getMessage() ) );
return false;
}
return true;
}
示例9: getValues
import org.dom4j.XPath; //导入方法依赖的package包/类
private List getValues(String xpath) {
XPath xpathObj = DocumentHelper.createXPath(xpath);
xpathObj.setNamespaceURIs(getNSMap());
List nodes = xpathObj.selectNodes(doc);
List values = new ArrayList();
for (Iterator i = nodes.iterator(); i.hasNext(); ) {
values.add(((Node) i.next()).getText());
}
return values;
}
示例10: findFunctionCalls
import org.dom4j.XPath; //导入方法依赖的package包/类
static List<Element> findFunctionCalls(Element xslt,
final String functionCall) {
XPath xpath = buildXpath(xslt, functionCall);
@SuppressWarnings("unchecked")
// jaxen doesn't do generics
List<Element> nodes = xpath.selectNodes(xslt);
return nodes;
}
示例11: convertModes
import org.dom4j.XPath; //导入方法依赖的package包/类
private void convertModes(final Document doc) {
XPath xpathSelector = DocumentHelper.createXPath("/settings/filters/filter/row");
List<?> results = xpathSelector.selectNodes(doc);
for (Iterator<?> iter = results.iterator(); iter.hasNext();) {
Element elem = (Element) iter.next();
Attribute attr = elem.attribute("mode");
String currentValue = attr.getText();
attr.setText(convertMode(currentValue));
}
}
示例12: convertDefaultPriceModes
import org.dom4j.XPath; //导入方法依赖的package包/类
private void convertDefaultPriceModes(final Document doc) {
XPath xpathSelector = DocumentHelper.createXPath("/settings/marketstat");
List<?> results = xpathSelector.selectNodes(doc);
for (Iterator<?> iter = results.iterator(); iter.hasNext();) {
Element elem = (Element) iter.next();
Attribute attr = elem.attribute("defaultprice");
if (attr != null) { //May not exist (in early versions)
String currentValue = attr.getText();
attr.setText(convertDefaultPriceMode(currentValue));
}
}
}
示例13: setVersion
import org.dom4j.XPath; //导入方法依赖的package包/类
void setVersion(final File xml, final int newVersion) throws DocumentException {
SAXReader xmlReader = new SAXReader();
Document doc = xmlReader.read(xml);
XPath xpathSelector = DocumentHelper.createXPath("/settings");
List<?> results = xpathSelector.selectNodes(doc);
for (Iterator<?> iter = results.iterator(); iter.hasNext();) {
Element element = (Element) iter.next();
Attribute attr = element.attribute("version");
if (attr == null) {
element.add(new DefaultAttribute("version", String.valueOf(newVersion)));
} else {
attr.setText(String.valueOf(newVersion));
}
}
try {
FileOutputStream fos = new FileOutputStream(xml);
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setEncoding("UTF-16");
XMLWriter writer = new XMLWriter(fos, outformat);
writer.write(doc);
writer.flush();
} catch (IOException ioe) {
LOG.error("Failed to update the serttings.xml version number", ioe);
throw new RuntimeException(ioe);
}
}
示例14: slurpOutput
import org.dom4j.XPath; //导入方法依赖的package包/类
public boolean slurpOutput(PipedOutputStream stdout, PipedOutputStream stderr) throws IOException {
log.log(Level.FINE, "--> SlurpOutput");
ImmutableMap<String, PipedOutputStream> streams = ImmutableMap.of("stdout", stdout, "stderr", stderr);
Document request = factory.newGetOutputRequest(shellId, commandId).build();
Document response = sendRequest(request);
XPath xpath = DocumentHelper.createXPath("//" + Namespaces.NS_WIN_SHELL.getPrefix() + ":Stream");
namespaceContext = new SimpleNamespaceContext();
namespaceContext.addNamespace(Namespaces.NS_WIN_SHELL.getPrefix(), Namespaces.NS_WIN_SHELL.getURI());
xpath.setNamespaceContext(namespaceContext);
Base64 base64 = new Base64();
for (Element e : (List<Element>) xpath.selectNodes(response)) {
PipedOutputStream stream = streams.get(e.attribute("Name").getText().toLowerCase());
final byte[] decode = base64.decode(e.getText());
log.log(Level.FINE, "piping " + decode.length + " bytes from " + e.attribute("Name").getText().toLowerCase());
stream.write(decode);
}
XPath done = DocumentHelper
.createXPath("//*[@State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done']");
done.setNamespaceContext(namespaceContext);
if (Iterables.isEmpty(done.selectNodes(response))) {
log.log(Level.FINE, "keep going baby!");
return true;
} else {
exitCode = Integer.parseInt(first(response, "//" + Namespaces.NS_WIN_SHELL.getPrefix() + ":ExitCode"));
log.log(Level.FINE, "no more output - command is now done - exit code: " + exitCode);
}
return false;
}
示例15: getTree
import org.dom4j.XPath; //导入方法依赖的package包/类
/** Return a tree structure reflecting the XML and trimmed values.
* @param path Dotted path into the xml.
* @return A tree reflecting the xml at the given path.
* @throws UnknownID If the path does not exist in the tree or is ambiguous
*/
public StringTree<String> getTree(String path) {
ArgumentNotValid.checkNotNullOrEmpty(path, "String path");
XPath xpath = getXPath(path);
List<Node> nodes = xpath.selectNodes(xmlDoc);
if (nodes == null || nodes.size() == 0) {
throw new UnknownID("No path '" + path + "' in XML document '"
+ source + "'");
} else if (nodes.size() > 1) {
throw new UnknownID("More than one candidate for path '" + path
+ "' in XML document '" + source + "'");
}
return XmlTree.getStringTree(nodes.get(0));
}