本文整理汇总了Java中org.dom4j.Document.selectSingleNode方法的典型用法代码示例。如果您正苦于以下问题:Java Document.selectSingleNode方法的具体用法?Java Document.selectSingleNode怎么用?Java Document.selectSingleNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dom4j.Document
的用法示例。
在下文中一共展示了Document.selectSingleNode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseMap2Xml
import org.dom4j.Document; //导入方法依赖的package包/类
/**
* 将Dto转换为符合XML标准规范格式的字符串(基于属性值形式)
*
* @param map 传入的Dto对象
* @param pRootNodeName 根节点名
* @param pFirstNodeName 一级节点名
* @return string 返回XML格式字符串
*/
public static final String parseMap2Xml(Map map, String pRootNodeName, String pFirstNodeName) {
Document document = DocumentHelper.createDocument();
// 增加一个根元素节点
document.addElement(pRootNodeName);
Element root = document.getRootElement();
root.addElement(pFirstNodeName);
Element firstEl = (Element)document.selectSingleNode("/" + pRootNodeName + "/" + pFirstNodeName);
Iterator keyIterator = map.keySet().iterator();
while (keyIterator.hasNext()) {
String key = (String)keyIterator.next();
String value = (String)map.get(key);
firstEl.addAttribute(key, value);
}
// 将XML的头声明信息丢去
String outXml = document.asXML().substring(39);
return outXml;
}
示例2: MqResToDto
import org.dom4j.Document; //导入方法依赖的package包/类
/**
* 将mq查询结果包装成list--dto的形式,dto内容为item中的内容
*
* @param recv
* @return
*/
public static Map MqResToDto(String recv) {
// System.out.println("####recv"+recv);
List res = new ArrayList();
Map map = new HashMap();
try {
Document doc = DocumentHelper.parseText(recv);
List list = doc.selectNodes("//item");
Iterator<DefaultElement> it = list.iterator();
while (it.hasNext()) {
Map elementdto = XmlUtil.Dom2Map(it.next());
res.add(elementdto);
}
map.put("resultList", res);// 放入结果集
/* 如果存在REC_MNT,说明是分页查询类,需要将总记录数返回 */
Node de = doc.selectSingleNode("//REC_MNT");
if (DataUtil.isNotEmpty(de)) {
map.put("countInteger", de.getText());
}
} catch (Exception e) {
logger.error("", e);
}
return map;
}
示例3: parseMap2Xml
import org.dom4j.Document; //导入方法依赖的package包/类
/**
* 将Dto转换为符合XML标准规范格式的字符串(基于属性值形式)
*
* @param map 传入的Dto对象
* @param pRootNodeName 根节点名
* @param pFirstNodeName 一级节点名
* @return string 返回XML格式字符串
*/
public static final String parseMap2Xml(Map map, String pRootNodeName, String pFirstNodeName) {
Document document = DocumentHelper.createDocument();
// 增加一个根元素节点
document.addElement(pRootNodeName);
Element root = document.getRootElement();
root.addElement(pFirstNodeName);
Element firstEl = (Element) document.selectSingleNode("/" + pRootNodeName + "/" + pFirstNodeName);
Iterator keyIterator = map.keySet().iterator();
while (keyIterator.hasNext()) {
String key = (String) keyIterator.next();
String value = (String) map.get(key);
firstEl.addAttribute(key, value);
}
// 将XML的头声明信息丢去
String outXml = document.asXML().substring(39);
return outXml;
}
示例4: MqResToDto
import org.dom4j.Document; //导入方法依赖的package包/类
/**
* 将mq查询结果包装成list--dto的形式,dto内容为item中的内容
*
* @param recv
* @return
*/
public static Map MqResToDto(String recv) {
// System.out.println("####recv"+recv);
List res = new ArrayList();
Map map = new HashMap();
try {
Document doc = DocumentHelper.parseText(recv);
List list = doc.selectNodes("//item");
Iterator<DefaultElement> it = list.iterator();
while (it.hasNext()) {
Map elementdto = XmlUtil.Dom2Map(it.next());
res.add(elementdto);
}
map.put("resultList", res);// 放入结果集
/*
* 如果存在REC_MNT,说明是分页查询类,需要将总记录数返回
*/
Node de = doc.selectSingleNode("//REC_MNT");
if (DataUtil.isNotEmpty(de)) {
map.put("countInteger", de.getText());
}
} catch (Exception e) {
log.error(XmlUtil.class, e);
}
return map;
}
示例5: metsTesterOLD
import org.dom4j.Document; //导入方法依赖的package包/类
void metsTesterOLD () throws Exception {
String parentPath = "/this:mets/this:amdSec[1]";
// SchemaNode schemaNode = this.sh.getSchemaNode (parentPath);
// Sequence comp = (Sequence)schemaNode.getCompositor();
Compositor comp = this.sh.getCompositor(parentPath);
comp.printInstanceNames();
comp.printLeafMemberNames();
String docPath = "C:/Documents and Settings/ostwald/devel/dcs-instance-data/ndr/records/mets/1216839452217/METS-TEST-000-000-000-003.xml";
Document instanceDoc = Dom4jUtils.getXmlDocument(new File(docPath));
Element parent = (Element)instanceDoc.selectSingleNode (parentPath);
if (parent == null) {
throw new Exception ("parent not found");
}
else {
boolean accepts = comp.acceptsNewMember(parent, "this:techMD", 1);
}
}
示例6: getResponseError
import org.dom4j.Document; //导入方法依赖的package包/类
/**
* Gets the responseError attribute of the WebServiceClient class
*
*@param doc Description of the Parameter
*@return The responseError value
*/
public static String getResponseError(Document doc) {
try {
Node errorNode = doc.selectSingleNode("/DDSWebService/error");
if (errorNode != null) {
return errorNode.getText().trim();
}
} catch (Exception e) {
prtln("getResponseError() " + e);
}
return "";
}
示例7: nodeProbe
import org.dom4j.Document; //导入方法依赖的package包/类
void nodeProbe (String path) {
// Document doc = sh.getInstanceDocument();
Document doc = sh.getMinimalDocument();
Node n = doc.selectSingleNode (path);
if (n == null)
prtln("node NOT found at " + path);
else
prtln ("node FOUND at " + path);
}
示例8: findMessageNode
import org.dom4j.Document; //导入方法依赖的package包/类
private static Node findMessageNode(List<Document> messageCollectionList, String xpath,
String missingMsg) throws PluginException {
for (Iterator<Document> i = messageCollectionList.iterator(); i.hasNext();) {
Document document = i.next();
Node node = document.selectSingleNode(xpath);
if (node != null)
return node;
}
throw new PluginException(missingMsg);
}
示例9: Plugin
import org.dom4j.Document; //导入方法依赖的package包/类
public Plugin(String directory, boolean isDependent)
throws DocumentException, EclipseClasspathException, IOException {
this.directory = directory;
this.isDependent = isDependent;
this.requiredPluginIdList = new LinkedList<String>();
this.exportedLibraryList = new LinkedList<String>();
// Figure out whether this is an old-style (Eclipse 2.1.x)
// or new-style (3.0, OSGI-based) plugin.
boolean oldStyle = false;
Document document = null;
File pluginDescriptorFile = new File(directory + File.separator + "plugin.xml");
if (pluginDescriptorFile.isFile()) {
SAXReader reader = new SAXReader();
document = reader.read(new EclipseXMLReader(new FileReader(pluginDescriptorFile)));
Node plugin = document.selectSingleNode("/plugin");
if (plugin == null)
throw new EclipseClasspathException("No plugin node in plugin descriptor");
oldStyle = !plugin.valueOf("@id").equals("");
}
// Get the plugin id
if (oldStyle) {
parseOldPluginDescriptor(directory, document, isDependent);
} else {
parseNewPluginDescriptor(directory, isDependent);
}
}
示例10: getSetDefinitionsForm
import org.dom4j.Document; //导入方法依赖的package包/类
/**
* Reads the ListSets config XML to extract the set definition for a given set into a SetDefinitionsForm
* bean.
*
* @param listSetsXml The ListSets config XML to read
* @param setSpec The setSpec to read
* @return The setDefinitionsForm, or null if none configred for that setSpec
* @exception Exception If error parsing the XML
*/
public static SetDefinitionsForm getSetDefinitionsForm(String listSetsXml, String setSpec)
throws Exception {
Document document = Dom4jUtils.getXmlDocument(listSetsXml);
Element setElement = (Element) document.selectSingleNode("/ListSets/set[setSpec='" + setSpec + "']");
if (setElement == null)
return null;
SetDefinitionsForm setDefinitionsForm = new SetDefinitionsForm();
setDefinitionsForm.setSetName(setElement.valueOf("setName"));
setDefinitionsForm.setSetSpec(setElement.valueOf("setSpec"));
setDefinitionsForm.setSetDescription(setElement.valueOf("setDescription/description"));
setDefinitionsForm.setSetURL(setElement.valueOf("setDescription/identifier"));
setDefinitionsForm.setIncludedFormat(setElement.valueOf("virtualSearchField/virtualSearchTermDefinition/Query//booleanQuery/textQuery[@field='xmlFormat']"));
setDefinitionsForm.setIncludedQuery(setElement.valueOf("virtualSearchField/virtualSearchTermDefinition/Query/booleanQuery/luceneQuery[not(@excludeOrRequire='exclude')]"));
setDefinitionsForm.setExcludedQuery(setElement.valueOf("virtualSearchField/virtualSearchTermDefinition/Query/booleanQuery/luceneQuery[@excludeOrRequire='exclude']"));
// Handle include clauses
// Get included dirs
List includedDirs = setElement.selectNodes("virtualSearchField/virtualSearchTermDefinition/Query//booleanQuery/textQuery[@field='docdir' and not(@excludeOrRequire='exclude')]");
ArrayList dirsList = new ArrayList(includedDirs.size());
for (int i = 0; i < includedDirs.size(); i++)
dirsList.add( ((Node) includedDirs.get(i)).getText() );
setDefinitionsForm.setIncludedDirs((String[])dirsList.toArray(new String[]{}));
// Get included terms/phrases
List terms = setElement.selectNodes("virtualSearchField/virtualSearchTermDefinition/Query//booleanQuery/textQuery[@field='default' and not(@excludeOrRequire='exclude')]");
String text = "";
prtln("terms size: " + terms.size());
for (int i = 0; i < terms.size(); i++) {
text += ((Node) terms.get(i)).getText();
if (i < terms.size() - 1)
text += ", ";
}
setDefinitionsForm.setIncludedTerms(text);
// Handle exclude clauses
// Get excluded dirs
List exdludedDirs = setElement.selectNodes("virtualSearchField/virtualSearchTermDefinition/Query/booleanQuery/textQuery[@field='docdir' and @excludeOrRequire='exclude']");
dirsList = new ArrayList(exdludedDirs.size());
for (int i = 0; i < exdludedDirs.size(); i++)
dirsList.add( ((Node) exdludedDirs.get(i)).getText() );
setDefinitionsForm.setExcludedDirs((String[])dirsList.toArray(new String[]{}));
/* dirStrings = setDefinitionsForm.getExcludedDirs();
for (int i = 0; i < exdludedDirs.size(); i++)
dirStrings[i] = ((Node) exdludedDirs.get(i)).getText();
setDefinitionsForm.setExcludedDirs(dirStrings); */
// Get excluded terms/phrases
terms = setElement.selectNodes("virtualSearchField/virtualSearchTermDefinition/Query/booleanQuery/textQuery[@field='default' and @excludeOrRequire='exclude']");
text = "";
for (int i = 0; i < terms.size(); i++) {
text += ((Node) terms.get(i)).getText();
if (i < terms.size() - 1)
text += ", ";
}
setDefinitionsForm.setExcludedTerms(text);
//prtln("setDefinitionsForm.getSetName(): " + setDefinitionsForm.getSetName());
return setDefinitionsForm;
}
示例11: id
import org.dom4j.Document; //导入方法依赖的package包/类
/**
* Assumes id is already placed in the xmlRecord. Note - the ID within the recordXml is ultimately
used by the indexer, NOT the provided id (see RepositoryManger.putRecord).
*
*@param recordXml xml record to be put
*@param xmlFormat metadata format of xml record (e.g., "adn")
*@param collection destination collection (e.g., "dcc")
*@param id xml record id
*@return ID of created record
*@exception WebServiceClientException Description of the Exception
*/
public String doPutRecord(String recordXml, String xmlFormat, String collection, String id, String status, String statusNote)
throws WebServiceClientException {
// prtln("doPutRecord()");
// prtln (recordXml);
String errorMsg;
try {
String encodedRecord = URLEncoder.encode(recordXml, "UTF-8");
// package up the request URL
String argString = "recordXml=" + encodedRecord.trim();
argString += "&xmlFormat=" + xmlFormat.trim();
argString += "&collection=" + collection.trim();
argString += "&id=" + id.trim();
if (status != null)
argString += "&dcsStatus=" + status;
if (statusNote != null)
argString += "&dcsStatusNote=" + URLEncoder.encode(statusNote, "UTF-8");
// URL url = new URL(baseUrl + "?" + argString);
// Document response = Dom4jUtils.getXmlDocument(url);
String logMsg = "doPutRecord() params:";
logMsg += "\n\t" + "xmlFormat: " + xmlFormat;
logMsg += "\n\t" + "collection: " + collection;
logMsg += "\n\t" + "id: " + id;
logMsg += "\n\t" + "status: " + status;
logMsg += "\n\t" + "statusNote: " + statusNote;
prtln (logMsg);
setRequestUrl("PutRecord", argString);
Document doc = getResponseDoc();
// now we have to parse the doc looking for errors
prtln(Dom4jUtils.prettyPrint(doc));
Node errorNode = doc.selectSingleNode("/DCSWebService/error");
if (errorNode != null) {
throw new Exception(errorNode.getText());
}
} catch (UnsupportedEncodingException e) {
errorMsg = "xmlRecord encoding error: " + e.getMessage();
throw new WebServiceClientException(errorMsg);
} catch (Throwable t) {
errorMsg = t.getMessage();
throw new WebServiceClientException(errorMsg);
}
return id;
}
示例12: getAllRecords
import org.dom4j.Document; //导入方法依赖的package包/类
/**
* Connects to the DDS via webservices, and extracts the records into a Dom4J document.
*
* @exception CasException
* @exception MmdException
* @exception XMLException
*/
void getAllRecords()
throws CasException, MmdException, XMLException {
//System.out.println("entering getAllRecords:");
boolean firstrun = true;
int totalResults = -1;
int s = 0;
// offset
int n = 100;
// number of records returned by the webservice at each call
Rec[] records = null;
do {
String request = "http://www.dlese.org/dds/services/ddsws1-0?verb=Search&q=ky:0*&xmlFormat=adn-localized&s=" + s + "&n=" + n + "&client=ddsws-explorer";
try {
Document document = null;
URL url = new URL(request);
int timeOutPeriod = 180000;
InputStream istm = TimedURLConnection.getInputStream(url,timeOutPeriod);
// Process the InputStream as desired. The InputStream may be used to
// create an XML DOM or to convert the content to a String, for example.
// For example, lets create a dom4j DOM document using the InputStream:
try {
SAXReader reader = new SAXReader();
document = reader.read(istm);
} catch (DocumentException e) {
// Handle the Exception as desired...
prtlnErr("Error! : " + e);
}
// Get the total number of records, if this is the first set of records returned by DDS
if (firstrun == true) {
firstrun = false;
Node node = document.selectSingleNode("/DDSWebService/Search/resultInfo/totalNumResults");
totalResults = Integer.parseInt(node.getText());
}
// Extract info like email addresses, record IDs, etc from the XML records, and store in DB
extractRecordsInfo(document, records);
} catch (URLConnectionTimedOutException exc) {
// The URLConnection timed out...
prtlnErr("URLConnection timed out while attempting to connect to " + request);
} catch (IOException ioe) {
// The URLConnection threw an IOException while attempting to connect...
prtlnErr("URLConnection threw an IOException while attempting to connect to " + request);
}
prtln ("processed " + s + " through " + (s + n) + " of " + totalResults);
s = s + n;
} while (s < totalResults);
}