本文整理汇总了Java中org.w3c.dom.traversal.NodeIterator.nextNode方法的典型用法代码示例。如果您正苦于以下问题:Java NodeIterator.nextNode方法的具体用法?Java NodeIterator.nextNode怎么用?Java NodeIterator.nextNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.traversal.NodeIterator
的用法示例。
在下文中一共展示了NodeIterator.nextNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addNodes
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
/**
* Copy NodeList members into this nodelist, adding in
* document order. Null references are not added.
*
* @param iterator NodeIterator which yields the nodes to be added.
* @throws RuntimeException thrown if this NodeSet is not of
* a mutable type.
*/
public void addNodes(NodeIterator iterator)
{
if (!m_mutable)
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
if (null != iterator) // defensive to fix a bug that Sanjiva reported.
{
Node obj;
while (null != (obj = iterator.nextNode()))
{
addElement(obj);
}
}
// checkDups();
}
示例2: evaluate
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
private boolean evaluate(byte[] data) {
try {
InputSource inputSource = new InputSource(new ByteArrayInputStream(data));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder dbuilder = factory.newDocumentBuilder();
Document doc = dbuilder.parse(inputSource);
CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
XObject result = cachedXPathAPI.eval(doc, xpath);
if (result.bool())
return true;
else {
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
return (iterator.nextNode() != null);
}
} catch (Throwable e) {
return false;
}
}
示例3: filterPunctuation
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
protected void filterPunctuation(MaryData d) {
Document doc = d.getDocument();
NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter(
MaryXML.PARAGRAPH), false);
Element p = null;
while ((p = (Element) ni.nextNode()) != null) {
Node textNode = p.getFirstChild();
String s = textNode.getNodeValue();
System.err.println("FilterPunctuation");
System.err.println(s);
s = s.replaceAll("،", ",");
//s = s.replaceAll("XX", "YY");
System.err.println(s);
textNode.setNodeValue(s);
}
}
示例4: evaluate
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
protected boolean evaluate(InputSource inputSource) {
try {
DocumentBuilder dbuilder = createDocumentBuilder();
Document doc = dbuilder.parse(inputSource);
//An XPath expression could return a true or false value instead of a node.
//eval() is a better way to determine the boolean value of the exp.
//For compliance with legacy behavior where selecting an empty node returns true,
//selectNodeIterator is attempted in case of a failure.
CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
XObject result = cachedXPathAPI.eval(doc, xpath);
if (result.bool())
return true;
else {
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
return (iterator.nextNode() != null);
}
} catch (Throwable e) {
return false;
}
}
示例5: evaluate
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
private boolean evaluate(byte[] data) {
try {
InputSource inputSource = new InputSource(new ByteArrayInputStream(data));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder dbuilder = factory.newDocumentBuilder();
Document doc = dbuilder.parse(inputSource);
CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc,xpath);
return iterator.nextNode()!=null;
} catch (Throwable e) {
return false;
}
}
示例6: getPlainTextBelow
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
/**
* Return the concatenation of the values of all text nodes below the given node. One space character is inserted between
* adjacent text nodes.
*
* @param n
* n
* @return null if n is null
*/
public static String getPlainTextBelow(Node n) {
if (n == null)
return null;
Document doc = null;
if (n.getNodeType() == Node.DOCUMENT_NODE) {
doc = (Document) n;
} else {
doc = n.getOwnerDocument();
}
StringBuilder buf = new StringBuilder();
NodeIterator it = ((DocumentTraversal) doc).createNodeIterator(n, NodeFilter.SHOW_TEXT, null, true);
Text text = null;
while ((text = (Text) it.nextNode()) != null) {
buf.append(text.getData().trim());
buf.append(" ");
}
return buf.toString();
}
示例7: parseParameters
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的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;
}
示例8: outputDebug
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
/**
* Outputs information on the matches for debug purposes.
*
* @param matchSet The set of matching Nodes.
* @param doc The first document being differenced
*/
private static void outputDebug(final NodePairs matchSet,
final Document doc) {
if (DiffFactory.isDebug()) {
NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(
doc.getDocumentElement(), NodeFilter.SHOW_ALL, null, false);
Node n;
while ((n = ni.nextNode()) != null) {
System.err.print(DOMOps.getNodeAsString(n));
if (matchSet.isMatched(n)) {
System.err.println(" matches "
+ DOMOps.getNodeAsString(matchSet.getPartner(n)));
} else {
System.err.println(" unmatched");
}
}
ni.detach();
System.err.println();
}
}
示例9: initialiseAndOrderNodes
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
/**
* Returns a list of Nodes sorted according to their depths.
*
* Does *NOT* include root or documentElement
*
* TreeSet is sorted in reverse order of depth according to
* NodeInfoComparator.
*
* @param doc The document to be initialised and ordered.
* @return A depth-ordered list of the nodes in the doc.
*/
private static List<NodeDepth> initialiseAndOrderNodes(
final Document doc) {
NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(
doc, NodeFilter.SHOW_ALL, null, false);
List<NodeDepth> depthSorted = new ArrayList<NodeDepth>();
Node n;
while ((n = ni.nextNode()) != null) {
if (!(NodeOps.checkIfSameNode(doc, n)
|| NodeOps.checkIfSameNode(doc.getDocumentElement(), n)
|| n.getNodeType() == Node.DOCUMENT_TYPE_NODE)) {
depthSorted.add(new NodeDepth(n));
}
}
ni.detach();
Collections.sort(depthSorted, new NodeDepthComparator());
return depthSorted;
}
示例10: getElementsByTagNameCaseInsensitive
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
public static List<Element> getElementsByTagNameCaseInsensitive(Document doc,
final Set<String> lowerCaseNames) {
final List<Element> result = Lists.newArrayList();
NodeIterator nodeIterator = ((DocumentTraversal) doc)
.createNodeIterator(doc, NodeFilter.SHOW_ELEMENT,
new NodeFilter() {
public short acceptNode(Node n) {
if (lowerCaseNames.contains(n.getNodeName().toLowerCase())) {
return NodeFilter.FILTER_ACCEPT;
}
return NodeFilter.FILTER_REJECT;
}
}, false);
for (Node n = nodeIterator.nextNode(); n != null ; n = nodeIterator.nextNode()) {
result.add((Element)n);
}
return result;
}
示例11: getSetSpecs
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的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");
}
示例12: evaluate
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
protected boolean evaluate(InputSource inputSource) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder dbuilder = factory.newDocumentBuilder();
Document doc = dbuilder.parse(inputSource);
//An XPath expression could return a true or false value instead of a node.
//eval() is a better way to determine the boolean value of the exp.
//For compliance with legacy behavior where selecting an empty node returns true,
//selectNodeIterator is attempted in case of a failure.
CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
XObject result = cachedXPathAPI.eval(doc, xpath);
if (result.bool())
return true;
else {
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
return (iterator.nextNode() != null);
}
} catch (Throwable e) {
return false;
}
}
示例13: selectSingleNode
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
/**
* Use an XPath string to select a single node.
* XPath namespace prefixes are resolved from the namespaceNode.
*
* @param contextNode The node to start searching from.
* @param str A valid XPath string.
* @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
* @return The first node found that matches the XPath, or null.
*
* @throws TransformerException
*/
public static Node selectSingleNode(
Node contextNode, String str, Node namespaceNode)
throws TransformerException
{
// Have the XObject return its result as a NodeSetDTM.
NodeIterator nl = selectNodeIterator(contextNode, str, namespaceNode);
// Return the first node, or null
return nl.nextNode();
}
示例14: NodeSetDTM
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
/**
* Create a NodeSetDTM, and copy the members of the
* given DTMIterator into it.
*
* @param iterator Iterator which yields Nodes to be made members of the new set.
*/
public NodeSetDTM(NodeIterator iterator, XPathContext xctxt)
{
super();
Node node;
m_manager = xctxt.getDTMManager();
while (null != (node = iterator.nextNode()))
{
int handle = xctxt.getDTMHandleFromNode(node);
addNodeInDocOrder(handle, xctxt);
}
}
示例15: addNodesInDocOrder
import org.w3c.dom.traversal.NodeIterator; //导入方法依赖的package包/类
/**
* Copy NodeList members into this nodelist, adding in
* document order. If a node is null, don't add it.
*
* @param iterator NodeIterator which yields the nodes to be added.
* @param support The XPath runtime context.
* @throws RuntimeException thrown if this NodeSet is not of
* a mutable type.
*/
public void addNodesInDocOrder(NodeIterator iterator, XPathContext support)
{
if (!m_mutable)
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");
Node node;
while (null != (node = iterator.nextNode()))
{
addNodeInDocOrder(node, support);
}
}