本文整理汇总了Java中org.apache.xpath.XPathAPI.selectNodeIterator方法的典型用法代码示例。如果您正苦于以下问题:Java XPathAPI.selectNodeIterator方法的具体用法?Java XPathAPI.selectNodeIterator怎么用?Java XPathAPI.selectNodeIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xpath.XPathAPI
的用法示例。
在下文中一共展示了XPathAPI.selectNodeIterator方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Document doc = XmlUtils.loadDoc("/testcode/xpath/data.xml");
String input = args.length != 0 ? args[1] : "guess' or '1'='1";
String query = "//groups/group[@id='" + input + "']/writeAccess/text()";
//selectNodeIterator
NodeIterator iterator = XPathAPI.selectNodeIterator(doc, query);
XmlUtils.printNodeIterator(iterator);
//selectNodeList
NodeList nodeList = XPathAPI.selectNodeList(doc, query);
XmlUtils.printNodeList(nodeList);
//selectSingleNode
Node node = XPathAPI.selectSingleNode(doc, query);
XmlUtils.printNode(node);
//Static string (safe)
Node node2 = XPathAPI.selectSingleNode(doc, "//groups/group[@id='guess']/writeAccess/text()".toLowerCase());
XmlUtils.printNode(node2);
}
示例2: parseParameters
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
public Map<String, Parameter> parseParameters(String response) throws KettleException{
Map<String, Parameter> parameters = new HashMap<String, Parameter>();
try{
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setNamespaceAware(false);
Document doc = dfactory.newDocumentBuilder().parse(new InputSource(new StringReader(response)));
Node n;
NodeIterator nodeIt = XPathAPI.selectNodeIterator(doc, root_expr);
while ((n = nodeIt.nextNode())!= null){
parameters.put(XPathAPI.eval(n, NAME_EXPR).str(), parseParameter(n));
}
} catch (Exception e) {
throw new KettleException("Error retrieving parameters from WPS response...", e);
}
return parameters;
}
示例3: buildBoundingBoxFormat
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
private AbstractFormat buildBoundingBoxFormat(Node n) throws JDOMException, KettleException, DOMException, TransformerException{
List<String> crss = new ArrayList<String>();
String default_crs = XPathAPI.eval(n, DEFAULT_CRS_EXPR).str();
if(default_crs == null)
default_crs = EMPTY;
Node crs_node;
NodeIterator nodeIt = XPathAPI.selectNodeIterator(n, SUPPORTED_CRSS_EXPR);
while ((crs_node = nodeIt.nextNode())!= null){
crss.add(crs_node.getNodeValue());
}
boolean alreadyExists = false;
for(String crs: crss){
if(crs.equals(default_crs)){
alreadyExists = true;
break;
}
}
if(!alreadyExists && !default_crs.equals(EMPTY))
crss.add(default_crs);
return new BoundingBoxFormat(crss, default_crs);
}
示例4: getComplexFormats
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
private void getComplexFormats(Parameter param, Node n) throws JDOMException, KettleException, DOMException, TransformerException{
Node complex_default = XPathAPI.selectSingleNode(n, DEFAULT_FORMAT_EXPR);
AbstractFormat defaultFormat = null;
if(complex_default!= null){
defaultFormat = buildComplexFormat(complex_default);
param.setDefaultFormat(defaultFormat);
}
Node complex_supported;
NodeIterator nodeIt = XPathAPI.selectNodeIterator(n, SUPPORTED_FORMATS_EXPR);
while ((complex_supported = nodeIt.nextNode())!= null){
param.addSupportedFormat(buildComplexFormat(complex_supported));
}
if(param.getSupportedFormats().isEmpty() && defaultFormat != null)
param.addSupportedFormat(defaultFormat);
}
示例5: getSetSpecs
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
/**
* get the setspec from the item
*
* @param nativeItem a native item presumably containing a setspec somewhere
* @return a String containing the setspec for the item
* @exception IllegalArgumentException Something is wrong with the argument.
*/
public Iterator getSetSpecs(Object nativeItem)
throws IllegalArgumentException {
ArrayList list = new ArrayList();
Document doc = (Document) nativeItem;
try {
NodeIterator iter = XPathAPI.selectNodeIterator(doc, "/record/header/setSpec");
Node node = null;
while ((node = iter.nextNode()) != null) {
list.add(XPathAPI.eval(node, ".").str());
}
} catch (TransformerException e) {
e.printStackTrace();
return null;
}
return list.iterator();
// return (Iterator)((HashMap)nativeItem).get("setSpecs");
}
示例6: canonize
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
/**
* Canonizes an input with inclusive c14n without comments algorithm.
*
* <p>EBICS Specification 2.4.2 - 5.5.1.1.1 EBICS messages in transaction initialization:
*
* <p>The identification and authentication signature includes all XML elements of the
* EBICS request whose attribute value for @authenticate is equal to “true”. The
* definition of the XML schema “ebics_request.xsd“ guarantees that the value of the
* attribute @authenticate is equal to “true” for precisely those elements that also
* need to be signed.
*
* <p>Thus, All the Elements with the attribute authenticate = true and their
* sub elements are considered for the canonization process. This is performed
* via the {@link XPathAPI#selectNodeIterator(Node, String) selectNodeIterator(Node, String)}.
*
* @param input the byte array XML input.
* @return the canonized form of the given XML
* @throws EbicsException
*/
public static byte[] canonize(byte[] input) throws EbicsException {
DocumentBuilderFactory factory;
DocumentBuilder builder;
Document document;
NodeIterator iter;
ByteArrayOutputStream output;
Node node;
try {
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
builder = factory.newDocumentBuilder();
builder.setErrorHandler(new IgnoreAllErrorHandler());
document = builder.parse(new ByteArrayInputStream(input));
iter = XPathAPI.selectNodeIterator(document, "//*[@authenticate='true']");
output = new ByteArrayOutputStream();
while ((node = iter.nextNode()) != null) {
Canonicalizer canonicalizer;
canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
output.write(canonicalizer.canonicalizeSubtree(node));
}
return output.toByteArray();
} catch (Exception e) {
throw new EbicsException(e.getMessage());
}
}
示例7: buildLiteralFormat
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
private AbstractFormat buildLiteralFormat(Node n) throws TransformerException, JDOMException, KettleException{
String datatype = XPathAPI.eval(n, DATATYPE_EXPR).str();
if(datatype == null)
datatype = EMPTY;
List<String> uoms = new ArrayList<String>();
String default_uom = XPathAPI.eval(n, DEFAULT_UOM_EXPR).str();
if(default_uom == null)
default_uom = EMPTY;
Node uom_node;
NodeIterator nodeIt = XPathAPI.selectNodeIterator(n, SUPPORTED_UOMS_EXPR);
while ((uom_node = nodeIt.nextNode())!= null){
if(uom_node.getTextContent() != null)
uoms.add(uom_node.getTextContent());
}
boolean alreadyExists = false;
for(String uom: uoms){
if(uom.equals(default_uom)){
alreadyExists = true;
break;
}
}
if(!alreadyExists && !default_uom.equals(EMPTY))
uoms.add(default_uom);
return new LiteralFormat(datatype, uoms, default_uom, XPathAPI.eval(n, DEFAULT_VALUE_EXPR).str());
}
示例8: parseProcesses
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
public Map<String, String> parseProcesses(String response) throws KettleException{
Map<String, String> processes = new HashMap<String, String>();
try {
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setNamespaceAware(false);
Document doc = dfactory.newDocumentBuilder().parse(new InputSource(new StringReader(response)));
Node n;
NodeIterator nodeIt = XPathAPI.selectNodeIterator(doc, PROCESSES_EXPR);
while ((n = nodeIt.nextNode())!= null){
processes.put(XPathAPI.eval(n, PROCESS_NAME_EXPR).str(), XPathAPI.eval(n, PROCESS_ID_EXPR).str());
}
String describeProcessPOSTURL = XPathAPI.eval(doc, DESCRIBEPROCESS_POST_URL).str();
String describeProcessGETURL = XPathAPI.eval(doc, DESCRIBEPROCESS_GET_URL).str();
String executePOSTURL = XPathAPI.eval(doc, EXECUTE_POST_URL).str();
String executeGETURL = XPathAPI.eval(doc, EXECUTE_GET_URL).str();
if(!Const.isEmpty(describeProcessPOSTURL))
urls.put("describeProcessPOSTURL", describeProcessPOSTURL);
if(!Const.isEmpty(describeProcessGETURL))
urls.put("describeProcessGETURL", describeProcessGETURL);
if(!Const.isEmpty(executePOSTURL))
urls.put("executePOSTURL", executePOSTURL);
if(!Const.isEmpty(executeGETURL))
urls.put("executeGETURL", executeGETURL);
} catch (Exception e) {
throw new KettleException("Error retrieving processes from WPS response...", e);
}
return processes;
}
示例9: canonize
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
/**
* Canonizes an input with inclusive c14n without comments algorithm.
*
* <p>EBICS Specification 2.4.2 - 5.5.1.1.1 EBICS messages in transaction initialization:
*
* <p>The identification and authentication signature includes all XML elements of the
* EBICS request whose attribute value for @authenticate is equal to “true”. The
* definition of the XML schema “ebics_request.xsd“ guarantees that the value of the
* attribute @authenticate is equal to “true” for precisely those elements that also
* need to be signed.
*
* <p>Thus, All the Elements with the attribute authenticate = true and their
* sub elements are considered for the canonization process. This is performed
* via the {@link XPathAPI#selectNodeIterator(Node, String) selectNodeIterator(Node, String)}.
*
* @param input the byte array XML input.
* @return the canonized form of the given XML
* @throws EbicsException
*/
public static byte[] canonize(byte[] input) throws AxelorException {
DocumentBuilderFactory factory;
DocumentBuilder builder;
Document document;
NodeIterator iter;
ByteArrayOutputStream output;
Node node;
try {
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
builder = factory.newDocumentBuilder();
builder.setErrorHandler(new IgnoreAllErrorHandler());
document = builder.parse(new ByteArrayInputStream(input));
iter = XPathAPI.selectNodeIterator(document, "//*[@authenticate='true']");
output = new ByteArrayOutputStream();
while ((node = iter.nextNode()) != null) {
Canonicalizer canonicalizer;
canonicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
output.write(canonicalizer.canonicalizeSubtree(node));
}
return output.toByteArray();
} catch (Exception e) {
throw new AxelorException(e.getMessage(), IException.CONFIGURATION_ERROR );
}
}
示例10: applyXPaths
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
public Map<String, List<Node>> applyXPaths(Document document, Node node) throws TransformerException {
final Map<String, List<Node>> allFound = new HashMap<>();
// Use the simple XPath API to select a nodeIterator.
// System.out.println("Querying DOM using "+pathExpression);
for (String xpath : this.pathExpressions) {
final List<Node> found = new ArrayList<>();
NodeIterator nl = XPathAPI.selectNodeIterator(node, xpath);
// Serialize the found nodes to System.out.
// System.out.println("<output>");
Node n;
while ((n = nl.nextNode())!= null) {
if (isTextNode(n)) {
// DOM may have more than one node corresponding to a
// single XPath text node. Coalesce all contiguous text nodes
// at this level
StringBuilder sb = new StringBuilder(n.getNodeValue());
for (
Node nn = n.getNextSibling();
isTextNode(nn);
nn = nn.getNextSibling()
) {
sb.append(nn.getNodeValue());
}
Text textNode = document.createTextNode(sb.toString());
found.add(textNode);
} else {
found.add(n);
// serializer.transform(new DOMSource(n), new StreamResult(new OutputStreamWriter(System.out)));
}
// System.out.println();
}
// System.out.println("</output>");
allFound.put(xpath, found);
}
return allFound;
}
示例11: service
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
protected void service(HttpServletRequest req, HttpServletResponse res ) {
try {
//get message from html
req.setCharacterEncoding("UTF-8");
String pokemon_Id = (String) req.getParameter("id");
//load xml file
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
// get path of xml file under tomcat
ServletContext context = getServletContext();
String xml_path_file = context.getRealPath("pokemon.xml");
Document doc = builder.parse(new File(xml_path_file));
Element root = doc.getDocumentElement() ;
String xpath_query = "//pokemon/id[.='"+ pokemon_Id+"']/.." ;
NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath_query);
String result = ""; //to html
Node node;
if ((node = nl.nextNode())!= null) {
root.removeChild (node);
System.out.println("OK!");
result = "<result>OK</result>" ;
}
else {
System.out.println("");
result = "<result>failed</result>" ;
}
TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer aTransformer = tranFactory.newTransformer();
Source src = new DOMSource(doc);
Result dest = new StreamResult(new FileOutputStream(xml_path_file));
aTransformer.transform(src, dest);
System.out.println("ok");
res.setContentType("text/xml;charset=UTF-8");
res.setHeader("Cache-Control","no-cache") ;
res.getWriter().write(result) ;
}
catch (Exception e) {
System.out.println("Failed!");
e.printStackTrace();
}
}
示例12: service
import org.apache.xpath.XPathAPI; //导入方法依赖的package包/类
protected void service(HttpServletRequest req, HttpServletResponse res ) {
try {
//get message from html
req.setCharacterEncoding("UTF-8");
String pokemon_Id = (String) req.getParameter("id"); //search pokemon's name
//1.載入XML??�件
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
//load xml file
ServletContext context = getServletContext();
String xml_path_file = context.getRealPath("pokemon.xml");
Document doc = builder.parse(new File (xml_path_file) );
//get path of xml file under tomcat
String xpath_query = "//pokemon/id[.='"+pokemon_Id+"']/..";
//2.4.start search
NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath_query);
System.out.println(nl);
String result = "<result>\n" ;
Node n;
while ((n = nl.nextNode())!= null) {
result = result + cvtNode2String(n);
}
result = result + "\n</result>";
res.setContentType("text/xml;charset=UTF-8");
res.setHeader("Cache-Control","no-cache") ;
res.getWriter().write(result) ;
}
catch (Exception e) {
System.out.println("Failed!");
e.printStackTrace();
}
}