本文整理匯總了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);
}